Commit | Line | Data |
---|---|---|
d8ed06af | 1 | /* _GNU_SOURCE is defined by config.h */ |
c70c42cc | 2 | #include <dlfcn.h> |
d8ed06af MD |
3 | #include <stdio.h> |
4 | #include <errno.h> | |
5 | #include <unistd.h> | |
6 | #include <stdlib.h> | |
c70c42cc | 7 | |
d8ed06af MD |
8 | /* |
9 | * libfoo has a direct dependency on libbar. | |
10 | * libbar has a direct dependency on libzzz. | |
11 | * This test is therefore a mix of dlopen/dlclose and dlmopen/dlclose of | |
12 | * libfoo, and of its direct dependencies. | |
13 | */ | |
14 | int main(int argc, char **argv) | |
c70c42cc | 15 | { |
bc1d8ca0 PP |
16 | void *h0, *h2, *h3, *h4; |
17 | ||
18 | #ifdef HAVE_DLMOPEN | |
19 | void *h1; | |
20 | #endif | |
21 | ||
d8ed06af MD |
22 | char *error; |
23 | int (*foo)(void); | |
c70c42cc | 24 | |
d8ed06af MD |
25 | h0 = dlopen("libbar.so", RTLD_LAZY); |
26 | if (!h0) { | |
27 | goto get_error; | |
28 | } | |
bc1d8ca0 PP |
29 | |
30 | #ifdef HAVE_DLMOPEN | |
d8ed06af MD |
31 | h1 = dlmopen(LM_ID_BASE, "libfoo.so", RTLD_LAZY); |
32 | if (!h1) { | |
33 | goto get_error; | |
34 | } | |
bc1d8ca0 PP |
35 | #endif |
36 | ||
d8ed06af MD |
37 | h2 = dlopen("libzzz.so", RTLD_LAZY); |
38 | if (!h2) { | |
39 | goto get_error; | |
40 | } | |
41 | h3 = dlopen("libfoo.so", RTLD_LAZY); | |
42 | if (!h3) { | |
43 | goto get_error; | |
44 | } | |
45 | h4 = dlopen("libfoo.so", RTLD_LAZY); | |
46 | if (!h4) { | |
47 | goto get_error; | |
48 | } | |
c70c42cc | 49 | |
bc1d8ca0 | 50 | foo = dlsym(h3, "foo"); |
d8ed06af MD |
51 | error = dlerror(); |
52 | if (error != NULL) { | |
53 | goto error; | |
54 | } | |
c70c42cc | 55 | |
d8ed06af | 56 | foo(); |
c70c42cc | 57 | |
d8ed06af MD |
58 | if (dlclose(h0)) { |
59 | goto get_error; | |
60 | } | |
bc1d8ca0 PP |
61 | |
62 | #ifdef HAVE_DLMOPEN | |
d8ed06af MD |
63 | if (dlclose(h1)) { |
64 | goto get_error; | |
65 | } | |
bc1d8ca0 PP |
66 | #endif |
67 | ||
d8ed06af MD |
68 | if (dlclose(h2)) { |
69 | goto get_error; | |
70 | } | |
71 | if (dlclose(h3)) { | |
72 | goto get_error; | |
73 | } | |
74 | if (dlclose(h4)) { | |
75 | goto get_error; | |
76 | } | |
77 | ||
78 | exit(EXIT_SUCCESS); | |
79 | ||
80 | get_error: | |
81 | error = dlerror(); | |
82 | error: | |
83 | fprintf(stderr, "%s\n", error); | |
84 | exit(EXIT_FAILURE); | |
c70c42cc | 85 | } |