| lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | #include <dlfcn.h> | 
|  | 2 | #include <stdio.h> | 
|  | 3 |  | 
|  | 4 | static int | 
|  | 5 | do_test (void) | 
|  | 6 | { | 
|  | 7 | void *h = dlopen ("tst-tlsmod16a.so", RTLD_LAZY | RTLD_GLOBAL); | 
|  | 8 | if (h == NULL) | 
|  | 9 | { | 
|  | 10 | puts ("unexpectedly failed to open tst-tlsmod16a.so"); | 
|  | 11 | exit (1); | 
|  | 12 | } | 
|  | 13 |  | 
|  | 14 | void *p = dlsym (h, "tlsvar"); | 
|  | 15 |  | 
|  | 16 | /* This dlopen should indeed fail, because tlsvar was assigned to | 
|  | 17 | dynamic TLS, and the new module requests it to be in static TLS. | 
|  | 18 | However, there's a possibility that dlopen succeeds if the | 
|  | 19 | variable is, for whatever reason, assigned to static TLS, or if | 
|  | 20 | the module fails to require static TLS, or even if TLS is not | 
|  | 21 | supported.  */ | 
|  | 22 | h = dlopen ("tst-tlsmod16b.so", RTLD_NOW | RTLD_GLOBAL); | 
|  | 23 | if (h == NULL) | 
|  | 24 | { | 
|  | 25 | return 0; | 
|  | 26 | } | 
|  | 27 |  | 
|  | 28 | puts ("unexpectedly succeeded to open tst-tlsmod16b.so"); | 
|  | 29 |  | 
|  | 30 |  | 
|  | 31 | void *(*fp) (void) = (void *(*) (void)) dlsym (h, "in_dso"); | 
|  | 32 | if (fp == NULL) | 
|  | 33 | { | 
|  | 34 | puts ("cannot find in_dso"); | 
|  | 35 | exit (1); | 
|  | 36 | } | 
|  | 37 |  | 
|  | 38 | /* If the dlopen passes, at least make sure the address returned by | 
|  | 39 | dlsym is the same as that returned by the initial-exec access. | 
|  | 40 | If the variable was assigned to dynamic TLS during dlsym, this | 
|  | 41 | portion will fail.  */ | 
|  | 42 | if (fp () != p) | 
|  | 43 | { | 
|  | 44 | puts ("returned values do not match"); | 
|  | 45 | exit (1); | 
|  | 46 | } | 
|  | 47 |  | 
|  | 48 | return 0; | 
|  | 49 | } | 
|  | 50 |  | 
|  | 51 | #define TEST_FUNCTION do_test () | 
|  | 52 | #include "../test-skeleton.c" |