Parameterize OP_T_THRES from memcopy.h
[glibc.git] / dlfcn / tststatic2.c
blob5d8a7831b23cdeb6a1c46876d8ac43584c7e5595
1 #include <dlfcn.h>
2 #include <link.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6 #include <gnu/lib-names.h>
7 #include <first-versions.h>
9 static int
10 do_test (void)
12 void *handle = dlopen ("modstatic2-nonexistent.so", RTLD_LAZY);
13 if (handle == NULL)
14 printf ("nonexistent: %s\n", dlerror ());
15 else
16 exit (1);
18 handle = dlopen ("modstatic2.so", RTLD_LAZY);
19 if (handle == NULL)
21 printf ("%s\n", dlerror ());
22 exit (1);
25 int (*test) (FILE *, int);
26 test = dlsym (handle, "test");
27 if (test == NULL)
29 printf ("%s\n", dlerror ());
30 exit (1);
33 Dl_info info;
34 int res = dladdr (test, &info);
35 if (res == 0)
37 puts ("dladdr returned 0");
38 exit (1);
40 else
42 if (strstr (info.dli_fname, "modstatic2.so") == NULL
43 || strcmp (info.dli_sname, "test") != 0)
45 printf ("fname %s sname %s\n", info.dli_fname, info.dli_sname);
46 exit (1);
48 if (info.dli_saddr != (void *) test)
50 printf ("saddr %p != test %p\n", info.dli_saddr, test);
51 exit (1);
55 ElfW(Sym) *sym;
56 void *symp;
57 res = dladdr1 (test, &info, &symp, RTLD_DL_SYMENT);
58 if (res == 0)
60 puts ("dladdr1 returned 0");
61 exit (1);
63 else
65 if (strstr (info.dli_fname, "modstatic2.so") == NULL
66 || strcmp (info.dli_sname, "test") != 0)
68 printf ("fname %s sname %s\n", info.dli_fname, info.dli_sname);
69 exit (1);
71 if (info.dli_saddr != (void *) test)
73 printf ("saddr %p != test %p\n", info.dli_saddr, test);
74 exit (1);
76 sym = symp;
77 if (sym == NULL)
79 puts ("sym == NULL\n");
80 exit (1);
82 if (ELF32_ST_BIND (sym->st_info) != STB_GLOBAL
83 || ELF32_ST_VISIBILITY (sym->st_other) != STV_DEFAULT)
85 printf ("bind %d visibility %d\n",
86 (int) ELF32_ST_BIND (sym->st_info),
87 (int) ELF32_ST_VISIBILITY (sym->st_other));
88 exit (1);
92 Lmid_t lmid;
93 res = dlinfo (handle, RTLD_DI_LMID, &lmid);
94 if (res != 0)
96 printf ("dlinfo returned %d %s\n", res, dlerror ());
97 exit (1);
99 else if (lmid != LM_ID_BASE)
101 printf ("lmid %d != %d\n", (int) lmid, (int) LM_ID_BASE);
102 exit (1);
105 res = test (stdout, 2);
106 if (res != 4)
108 printf ("Got %i, expected 4\n", res);
109 exit (1);
112 void *handle2 = dlopen (LIBDL_SO, RTLD_LAZY);
113 if (handle2 == NULL)
115 printf ("libdl.so: %s\n", dlerror ());
116 exit (1);
119 /* _exit is very unlikely to receive a second symbol version. */
120 void *exit_ptr = dlvsym (handle2, "_exit", FIRST_VERSION_libc__exit_STRING);
121 if (exit_ptr == NULL)
123 printf ("dlvsym: %s\n", dlerror ());
124 exit (1);
126 if (exit_ptr != dlsym (handle2, "_exit"))
128 printf ("dlvsym for _exit does not match dlsym\n");
129 exit (1);
132 void *(*dlsymfn) (void *, const char *);
133 dlsymfn = dlsym (handle2, "dlsym");
134 if (dlsymfn == NULL)
136 printf ("dlsym \"dlsym\": %s\n", dlerror ());
137 exit (1);
139 void *test2 = dlsymfn (handle, "test");
140 if (test2 == NULL)
142 printf ("%s\n", dlerror ());
143 exit (1);
145 else if (test2 != (void *) test)
147 printf ("test %p != test2 %p\n", test, test2);
148 exit (1);
151 dlclose (handle2);
152 dlclose (handle);
154 handle = dlmopen (LM_ID_BASE, "modstatic2.so", RTLD_LAZY);
155 if (handle == NULL)
157 printf ("%s\n", dlerror ());
158 exit (1);
160 dlclose (handle);
162 handle = dlmopen (LM_ID_NEWLM, "modstatic2.so", RTLD_LAZY);
163 if (handle == NULL)
164 printf ("LM_ID_NEWLM: %s\n", dlerror ());
165 else
167 puts ("LM_ID_NEWLM unexpectedly succeeded");
168 exit (1);
171 return 0;
174 #define TEST_FUNCTION do_test ()
175 #include "../test-skeleton.c"