Skip to content
Snippets Groups Projects
Commit dccd3ea1 authored by Ben Gamari's avatar Ben Gamari Committed by Marge Bot
Browse files

testsuite: Add test for lookupSymbolInNativeObj

parent 12931698
No related branches found
No related tags found
No related merge requests found
TOP=../../../..
include $(TOP)/mk/boilerplate.mk
include $(TOP)/mk/test.mk
lookupSymbolInNativeObj1:
'$(TEST_HC)' -shared -dynamic obj.c -o libobj.so
'$(TEST_HC)' -no-hs-main -dynamic lookupSymbolInNativeObj1.c -o main
./main
test('lookupSymbolInNativeObj1',
[unless(have_dynamic(), skip),
extra_files(['obj.c'])],
makefile_test, [])
#include "Rts.h"
#if defined(mingw32_HOST_OS)
#define PATH_STR(str) L##str
#else
#define PATH_STR(str) str
#endif
typedef void (*hello_t)();
int main(int argc, char *argv[])
{
RtsConfig conf = defaultRtsConfig;
conf.rts_opts_enabled = RtsOptsAll;
hs_init_ghc(&argc, &argv, conf);
initLinker_(0);
int ok;
char *errmsg;
void *obj = loadNativeObj("./libobj.so", &errmsg);
if (!obj) {
barf("loadNativeObj failed: %s", errmsg);
}
hello_t sym;
const char* lbl;
#if defined(darwin_HOST_OS)
// mach-o symbols are prefixed with _
lbl = "_hello";
#else
lbl = "hello";
#endif
sym = lookupSymbolInNativeObj(obj, lbl);
if (sym == NULL) {
barf("lookupSymbolInNativeObj failed unexpectedly");
}
sym();
#if defined(darwin_HOST_OS)
lbl = "_hello_world";
#else
lbl = "hello_world";
#endif
sym = lookupSymbolInNativeObj(obj, lbl);
if (sym != NULL) {
barf("lookupSymbolInNativeObj succeeded unexpectedly");
}
return 0;
}
hello world
#include <stdio.h>
void hello() {
printf("hello world\n");
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment