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

source code of glibc/elf/tst-dlmopen1.c