| lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | #include <dlfcn.h> | 
|  | 2 | #include <stdio.h> | 
|  | 3 | #include <stdlib.h> | 
|  | 4 |  | 
|  | 5 | #include <link.h> | 
|  | 6 |  | 
|  | 7 |  | 
|  | 8 | #define TEST_FUNCTION do_test () | 
|  | 9 | static int | 
|  | 10 | do_test (void) | 
|  | 11 | { | 
|  | 12 | static const char modname[] = "tst-tlsmod3.so"; | 
|  | 13 | int result = 0; | 
|  | 14 | int (*fp) (void); | 
|  | 15 | void *h; | 
|  | 16 | int i; | 
|  | 17 | int modid = -1; | 
|  | 18 |  | 
|  | 19 | for (i = 0; i < 10; ++i) | 
|  | 20 | { | 
|  | 21 | h = dlopen (modname, RTLD_LAZY); | 
|  | 22 | if (h == NULL) | 
|  | 23 | { | 
|  | 24 | printf ("cannot open '%s': %s\n", modname, dlerror ()); | 
|  | 25 | exit (1); | 
|  | 26 | } | 
|  | 27 |  | 
|  | 28 | /* Dirty test code here: we peek into a private data structure. | 
|  | 29 | We make sure that the module gets assigned the same ID every | 
|  | 30 | time.  The value of the first round is used.  */ | 
|  | 31 | if (modid == -1) | 
|  | 32 | modid = ((struct link_map *) h)->l_tls_modid; | 
|  | 33 | else if (((struct link_map *) h)->l_tls_modid != (size_t) modid) | 
|  | 34 | { | 
|  | 35 | printf ("round %d: modid now %zu, initially %d\n", | 
|  | 36 | i, ((struct link_map *) h)->l_tls_modid, modid); | 
|  | 37 | result = 1; | 
|  | 38 | } | 
|  | 39 |  | 
|  | 40 | fp = dlsym (h, "in_dso2"); | 
|  | 41 | if (fp == NULL) | 
|  | 42 | { | 
|  | 43 | printf ("cannot get symbol 'in_dso2': %s\n", dlerror ()); | 
|  | 44 | exit (1); | 
|  | 45 | } | 
|  | 46 |  | 
|  | 47 | result |= fp (); | 
|  | 48 |  | 
|  | 49 | dlclose (h); | 
|  | 50 | } | 
|  | 51 |  | 
|  | 52 | return result; | 
|  | 53 | } | 
|  | 54 |  | 
|  | 55 |  | 
|  | 56 | #include "../test-skeleton.c" |