2.9
[glibc/nacl-glibc.git] / elf / noload.c
blob9281ec714c84b5e07dfce948280f5e2793064de5
1 #include <dlfcn.h>
2 #include <stdio.h>
4 int
5 main (void)
7 int result = 0;
9 /* First try to load an object which is a dependency. This should
10 succeed. */
11 if (dlopen ("testobj1.so", RTLD_LAZY | RTLD_NOLOAD) == NULL)
13 printf ("cannot open \"testobj1.so\": %s\n", dlerror ());
14 result = 1;
16 else
17 puts ("loading \"testobj1.so\" succeeded, OK");
19 /* Now try loading an object which is not already loaded. */
20 if (dlopen ("testobj5.so", RTLD_LAZY | RTLD_NOLOAD) != NULL)
22 puts ("succeeded in loading \"testobj5.so\"");
23 result = 1;
25 else
27 /* Load the object and run the same test again. */
28 void *p;
30 puts ("\"testobj5.so\" wasn't loaded and RTLD_NOLOAD prevented it, OK");
32 p = dlopen ("testobj5.so", RTLD_LAZY);
34 if (p == NULL)
36 printf ("cannot open \"testobj5.so\" without RTLD_NOLOAD: %s\n",
37 dlerror ());
38 result = 1;
40 else
42 puts ("loading \"testobj5.so\" succeeded, OK");
44 if (dlopen ("testobj5.so", RTLD_LAZY | RTLD_NOLOAD) == NULL)
46 printf ("cannot open \"testobj5.so\": %s\n", dlerror ());
47 result = 1;
49 else
50 puts ("loading \"testobj5.so\" with RTLD_NOLOAD succeeded, OK");
52 if (dlclose (p) != 0)
54 printf ("cannot close \"testobj5.so\": %s\n", dlerror ());
55 result = 1;
57 else
58 puts ("closing \"testobj5.so\" succeeded, OK");
62 return result;
66 extern int foo (int a);
67 int
68 foo (int a)
70 return 42 + a;