verify-dynamic-library.c 887 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. int
  7. main (int argc, char **argv)
  8. {
  9. void *handle;
  10. void (*hello_world) (const char *name);
  11. char *error;
  12. handle = dlopen ("./output-of-test-compile-to-dynamic-library.c.so",
  13. RTLD_NOW | RTLD_LOCAL);
  14. if (!handle)
  15. {
  16. fprintf (stderr, "dlopen failed: %s\n", dlerror());
  17. exit (1);
  18. }
  19. /* Clear any existing error */
  20. dlerror ();
  21. /* This symbol is from the DSO built by
  22. test-compile-to-dynamic-library.c. */
  23. *(void **) (&hello_world) = dlsym (handle, "hello_world");
  24. if ((error = dlerror()) != NULL)
  25. {
  26. fprintf (stderr, "dlsym failed: %s\n", error);
  27. exit (2);
  28. }
  29. /* Call the function from the generated DSO. */
  30. hello_world (argv[0]);
  31. dlclose (handle);
  32. return 0;
  33. }