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 <tls.h> |
| 6 | |
| 7 | |
| 8 | #define TEST_FUNCTION do_test () |
| 9 | static int |
| 10 | do_test (void) |
| 11 | { |
| 12 | #ifdef USE_TLS |
| 13 | static const char modname[] = "tst-tlsmod2.so"; |
| 14 | int result = 0; |
| 15 | int *foop; |
| 16 | int *foop2; |
| 17 | int (*fp) (int, int *); |
| 18 | void *h; |
| 19 | |
| 20 | h = dlopen (modname, RTLD_LAZY); |
| 21 | if (h == NULL) |
| 22 | { |
| 23 | printf ("cannot open '%s': %s\n", modname, dlerror ()); |
| 24 | exit (1); |
| 25 | } |
| 26 | |
| 27 | foop = dlsym (h, "foo"); |
| 28 | if (foop == NULL) |
| 29 | { |
| 30 | printf ("cannot get symbol 'foo': %s\n", dlerror ()); |
| 31 | exit (1); |
| 32 | } |
| 33 | |
| 34 | *foop = 42; |
| 35 | |
| 36 | fp = dlsym (h, "in_dso"); |
| 37 | if (fp == NULL) |
| 38 | { |
| 39 | printf ("cannot get symbol 'in_dso': %s\n", dlerror ()); |
| 40 | exit (1); |
| 41 | } |
| 42 | |
| 43 | result |= fp (42, foop); |
| 44 | |
| 45 | foop2 = dlsym (h, "foo"); |
| 46 | if (foop2 == NULL) |
| 47 | { |
| 48 | printf ("cannot get symbol 'foo' the second time: %s\n", dlerror ()); |
| 49 | exit (1); |
| 50 | } |
| 51 | |
| 52 | if (foop != foop2) |
| 53 | { |
| 54 | puts ("address of 'foo' different the second time"); |
| 55 | result = 1; |
| 56 | } |
| 57 | else if (*foop != 16) |
| 58 | { |
| 59 | puts ("foo != 16"); |
| 60 | result = 1; |
| 61 | } |
| 62 | |
| 63 | dlclose (h); |
| 64 | |
| 65 | return result; |
| 66 | #else |
| 67 | return 0; |
| 68 | #endif |
| 69 | } |
| 70 | |
| 71 | |
| 72 | #include "../test-skeleton.c" |