]> git.ipfire.org Git - thirdparty/glibc.git/blob - elf/tst-dlmopen1.c
[BZ #77]
[thirdparty/glibc.git] / elf / tst-dlmopen1.c
1 #include <dlfcn.h>
2 #include <stdio.h>
3 #include <gnu/lib-names.h>
4
5
6 static int
7 do_test (void)
8 {
9 void *h = dlopen (LIBC_SO, RTLD_LAZY|RTLD_NOLOAD);
10 if (h == NULL)
11 {
12 printf ("cannot get handle for %s: %s\n", LIBC_SO, dlerror ());
13 return 1;
14 }
15
16 Lmid_t ns = -10;
17 if (dlinfo (h, RTLD_DI_LMID, &ns) != 0)
18 {
19 printf ("dlinfo for %s in %s failed: %s\n",
20 LIBC_SO, __func__, dlerror ());
21 return 1;
22 }
23
24 if (ns != LM_ID_BASE)
25 {
26 printf ("namespace for %s not LM_ID_BASE\n", LIBC_SO);
27 return 1;
28 }
29
30 if (dlclose (h) != 0)
31 {
32 printf ("dlclose for %s in %s failed: %s\n",
33 LIBC_SO, __func__, dlerror ());
34 return 1;
35 }
36
37 h = dlmopen (LM_ID_NEWLM, "$ORIGIN/tst-dlmopen1mod.so", RTLD_LAZY);
38 if (h == NULL)
39 {
40 printf ("cannot get handle for %s: %s\n",
41 "tst-dlmopen1mod.so", dlerror ());
42 return 1;
43 }
44
45 ns = -10;
46 if (dlinfo (h, RTLD_DI_LMID, &ns) != 0)
47 {
48 printf ("dlinfo for %s in %s failed: %s\n",
49 "tst-dlmopen1mod.so", __func__, dlerror ());
50 return 1;
51 }
52
53 if (ns == LM_ID_BASE)
54 {
55 printf ("namespace for %s is LM_ID_BASE\n", LIBC_SO);
56 return 1;
57 }
58
59 int (*fct) (Lmid_t) = dlsym (h, "foo");
60 if (fct == NULL)
61 {
62 printf ("could not find %s: %s\n", "foo", dlerror ());
63 return 1;
64 }
65
66 if (fct (ns) != 0)
67 return 1;
68
69 if (dlclose (h) != 0)
70 {
71 printf ("dlclose for %s in %s failed: %s\n",
72 LIBC_SO, __func__, dlerror ());
73 return 1;
74 }
75
76 return 0;
77 }
78
79 #define TEST_FUNCTION do_test ()
80 #include "../test-skeleton.c"