[BZ #5184]
[glibc.git] / elf / tst-dlmopen1mod.c
blob142488098a061ef50ad9a5fdf297175ef79b49d8
1 #include <dlfcn.h>
2 #include <stdio.h>
3 #include <gnu/lib-names.h>
6 static int cnt;
8 static void
9 __attribute ((constructor))
10 constr (void)
12 ++cnt;
16 int
17 foo (Lmid_t ns2)
19 void *h = dlopen (LIBC_SO, RTLD_LAZY|RTLD_NOLOAD);
20 if (h == NULL)
22 printf ("cannot get handle for %s: %s\n", LIBC_SO, dlerror ());
23 return 1;
26 Lmid_t ns = -10;
27 if (dlinfo (h, RTLD_DI_LMID, &ns) != 0)
29 printf ("dlinfo for %s in %s failed: %s\n",
30 LIBC_SO, __func__, dlerror ());
31 return 1;
34 if (ns != ns2)
36 printf ("namespace for %s not LM_ID_BASE\n", LIBC_SO);
37 return 1;
40 if (dlclose (h) != 0)
42 printf ("dlclose for %s in %s failed: %s\n",
43 LIBC_SO, __func__, dlerror ());
44 return 1;
47 if (cnt == 0)
49 puts ("constructor did not run");
50 return 1;
52 else if (cnt != 1)
54 puts ("constructor did not run exactly once");
55 return 1;
58 return 0;