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 | |
| 6 | #define TEST_FUNCTION do_test () |
| 7 | static int |
| 8 | do_test (void) |
| 9 | { |
| 10 | static const char modname[] = "tst-tlsmod2.so"; |
| 11 | int result = 0; |
| 12 | int *foop; |
| 13 | int (*fp) (int, int *); |
| 14 | void *h; |
| 15 | |
| 16 | h = dlopen (modname, RTLD_LAZY); |
| 17 | if (h == NULL) |
| 18 | { |
| 19 | printf ("cannot open '%s': %s\n", modname, dlerror ()); |
| 20 | exit (1); |
| 21 | } |
| 22 | |
| 23 | fp = dlsym (h, "in_dso"); |
| 24 | if (fp == NULL) |
| 25 | { |
| 26 | printf ("cannot get symbol 'in_dso': %s\n", dlerror ()); |
| 27 | exit (1); |
| 28 | } |
| 29 | |
| 30 | result |= fp (0, NULL); |
| 31 | |
| 32 | foop = dlsym (h, "foo"); |
| 33 | if (foop == NULL) |
| 34 | { |
| 35 | printf ("cannot get symbol 'foo' the second time: %s\n", dlerror ()); |
| 36 | exit (1); |
| 37 | } |
| 38 | if (*foop != 16) |
| 39 | { |
| 40 | puts ("foo != 16"); |
| 41 | result = 1; |
| 42 | } |
| 43 | |
| 44 | dlclose (h); |
| 45 | |
| 46 | return result; |
| 47 | } |
| 48 | |
| 49 | |
| 50 | #include "../test-skeleton.c" |