]>
Commit | Line | Data |
---|---|---|
bf8b3e74 UD |
1 | #include <dlfcn.h> |
2 | #include <stdio.h> | |
4bff6e01 | 3 | #include <mcheck.h> |
bf8b3e74 UD |
4 | |
5 | int | |
6 | main (void) | |
7 | { | |
8 | int result = 0; | |
4bff6e01 AS |
9 | void *p; |
10 | ||
11 | mtrace (); | |
bf8b3e74 UD |
12 | |
13 | /* First try to load an object which is a dependency. This should | |
14 | succeed. */ | |
4bff6e01 AS |
15 | p = dlopen ("testobj1.so", RTLD_LAZY | RTLD_NOLOAD); |
16 | if (p == NULL) | |
bf8b3e74 UD |
17 | { |
18 | printf ("cannot open \"testobj1.so\": %s\n", dlerror ()); | |
19 | result = 1; | |
20 | } | |
21 | else | |
4bff6e01 AS |
22 | { |
23 | puts ("loading \"testobj1.so\" succeeded, OK"); | |
24 | dlclose (p); | |
25 | } | |
bf8b3e74 UD |
26 | |
27 | /* Now try loading an object which is not already loaded. */ | |
28 | if (dlopen ("testobj5.so", RTLD_LAZY | RTLD_NOLOAD) != NULL) | |
29 | { | |
30 | puts ("succeeded in loading \"testobj5.so\""); | |
31 | result = 1; | |
32 | } | |
33 | else | |
34 | { | |
35 | /* Load the object and run the same test again. */ | |
bf8b3e74 UD |
36 | puts ("\"testobj5.so\" wasn't loaded and RTLD_NOLOAD prevented it, OK"); |
37 | ||
38 | p = dlopen ("testobj5.so", RTLD_LAZY); | |
39 | ||
40 | if (p == NULL) | |
41 | { | |
42 | printf ("cannot open \"testobj5.so\" without RTLD_NOLOAD: %s\n", | |
43 | dlerror ()); | |
44 | result = 1; | |
45 | } | |
46 | else | |
47 | { | |
48 | puts ("loading \"testobj5.so\" succeeded, OK"); | |
49 | ||
4bff6e01 AS |
50 | void *q = dlopen ("testobj5.so", RTLD_LAZY | RTLD_NOLOAD); |
51 | if (q == NULL) | |
bf8b3e74 UD |
52 | { |
53 | printf ("cannot open \"testobj5.so\": %s\n", dlerror ()); | |
54 | result = 1; | |
55 | } | |
56 | else | |
4bff6e01 AS |
57 | { |
58 | puts ("loading \"testobj5.so\" with RTLD_NOLOAD succeeded, OK"); | |
59 | dlclose (q); | |
60 | } | |
bf8b3e74 UD |
61 | |
62 | if (dlclose (p) != 0) | |
63 | { | |
64 | printf ("cannot close \"testobj5.so\": %s\n", dlerror ()); | |
65 | result = 1; | |
66 | } | |
67 | else | |
68 | puts ("closing \"testobj5.so\" succeeded, OK"); | |
69 | } | |
70 | } | |
71 | ||
72 | return result; | |
73 | } | |
74 | ||
75 | ||
a850e77f | 76 | extern int foo (int a); |
bf8b3e74 UD |
77 | int |
78 | foo (int a) | |
79 | { | |
80 | return 42 + a; | |
81 | } |