dltest.c 978 B

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