| 1 |
/* For use by jit-verify-dynamic-library, used by |
| 2 |
test-compile-to-dynamic-library.c. */ |
| 3 |
#include <dlfcn.h> |
| 4 |
#include <stdio.h> |
| 5 |
#include <stdlib.h> |
| 6 |
|
| 7 |
int |
| 8 |
main (int argc, char **argv) |
| 9 |
{ |
| 10 |
void *handle; |
| 11 |
void (*hello_world) (const char *name); |
| 12 |
char *error; |
| 13 |
|
| 14 |
handle = dlopen ("./output-of-test-compile-to-dynamic-library.c.so", |
| 15 |
RTLD_NOW | RTLD_LOCAL); |
| 16 |
if (!handle) |
| 17 |
{ |
| 18 |
fprintf (stderr, "dlopen failed: %s\n", dlerror()); |
| 19 |
exit (1); |
| 20 |
} |
| 21 |
|
| 22 |
/* Clear any existing error */ |
| 23 |
dlerror (); |
| 24 |
|
| 25 |
/* This symbol is from the DSO built by |
| 26 |
test-compile-to-dynamic-library.c. */ |
| 27 |
*(void **) (&hello_world) = dlsym (handle, "hello_world"); |
| 28 |
|
| 29 |
if ((error = dlerror()) != NULL) |
| 30 |
{ |
| 31 |
fprintf (stderr, "dlsym failed: %s\n", error); |
| 32 |
exit (2); |
| 33 |
} |
| 34 |
|
| 35 |
/* Call the function from the generated DSO. */ |
| 36 |
hello_world (argv[0]); |
| 37 |
|
| 38 |
dlclose (handle); |
| 39 |
|
| 40 |
return 0; |
| 41 |
} |