dltest.c 923 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include <fcntl.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <dlfcn.h>
  5. #include <stdint.h>
  6. int main(int argc, char **argv)
  7. {
  8. int ret = EXIT_SUCCESS;
  9. void *handle;
  10. void (*mydltest)(void *value1, void *value2);
  11. char *error;
  12. uint32_t *value1, *value2;
  13. handle = dlopen (LIBNAME, RTLD_LAZY);
  14. if (!handle) {
  15. fprintf(stderr, "Could not open ./%s: %s\n", LIBNAME, dlerror());
  16. exit(1);
  17. }
  18. mydltest = dlsym(handle, "dltest");
  19. if ((error = dlerror()) != NULL) {
  20. fprintf(stderr, "Could not locate symbol 'dltest': %s\n", error);
  21. exit(1);
  22. }
  23. mydltest(&value1, &value2);
  24. printf("dltest: pthread_once=%p\n", value1);
  25. printf("dltest: pthread_self=%p\n", value2);
  26. if (value1 == value2) {
  27. ret = EXIT_FAILURE;
  28. printf("dltest: values should NOT be equal Weak values resolved incorrectly!\n");
  29. } else {
  30. printf("dltest: weak symbols resoved correctly.\n");
  31. }
  32. dlclose(handle);
  33. return ret;
  34. }