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