1 #include <dlfcn.h>
2 #include <stdio.h>
3 #include <mcheck.h>
4
5 int
main(void)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 ("testobj1.so", RTLD_LAZY | RTLD_NOLOAD);
16 if (p == NULL)
17 {
18 printf ("cannot open \"testobj1.so\": %s\n", dlerror ());
19 result = 1;
20 }
21 else
22 {
23 puts ("loading \"testobj1.so\" succeeded, OK");
24 dlclose (p);
25 }
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. */
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
50 void *q = dlopen ("testobj5.so", RTLD_LAZY | RTLD_NOLOAD);
51 if (q == NULL)
52 {
53 printf ("cannot open \"testobj5.so\": %s\n", dlerror ());
54 result = 1;
55 }
56 else
57 {
58 puts ("loading \"testobj5.so\" with RTLD_NOLOAD succeeded, OK");
59 dlclose (q);
60 }
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
76 extern int foo (int a);
77 int
foo(int a)78 foo (int a)
79 {
80 return 42 + a;
81 }
82