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