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