lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 1 | #include <fcntl.h> |
| 2 | #include <stdlib.h> |
| 3 | #include <stdio.h> |
| 4 | #include <dlfcn.h> |
| 5 | #include <stdint.h> |
| 6 | |
| 7 | int main(int argc, char **argv) |
| 8 | { |
| 9 | int ret = EXIT_SUCCESS; |
| 10 | void *handle; |
| 11 | void (*mydltest)(void *value1, void *value2); |
| 12 | char *error; |
| 13 | uint32_t *value1, *value2; |
| 14 | |
| 15 | handle = dlopen (LIBNAME, RTLD_LAZY); |
| 16 | if (!handle) { |
| 17 | fprintf(stderr, "Could not open ./%s: %s\n", LIBNAME, dlerror()); |
| 18 | exit(1); |
| 19 | } |
| 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 | |
| 27 | mydltest(&value1, &value2); |
| 28 | printf("dltest: pthread_once=%p\n", value1); |
| 29 | printf("dltest: pthread_self=%p\n", value2); |
| 30 | if (value1 == value2) { |
| 31 | ret = EXIT_FAILURE; |
| 32 | printf("dltest: values should NOT be equal Weak values resolved incorrectly!\n"); |
| 33 | } else { |
| 34 | printf("dltest: weak symbols resoved correctly.\n"); |
| 35 | } |
| 36 | |
| 37 | dlclose(handle); |
| 38 | |
| 39 | return ret; |
| 40 | } |
| 41 | |