Ignore absolute symbols in ABI tests.
[glibc.git] / elf / tst-libc_dlvsym.h
blob6b1d8d5b3a5a885698eb903f54c41241eadeb626
1 /* Compare dlvsym and __libc_dlvsym results. Common code.
2 Copyright (C) 2017 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 /* compare_vsyms is the main entry point for these tests.
21 Indirectly, It calls __libc_dlvsym (from libc.so; internal
22 interface) and dlvsym (from libdl.so; public interface) to compare
23 the results for a selected set of symbols in libc.so which
24 typically have more than one symbol version. The two functions are
25 implemented by somewhat different code, and this test checks that
26 their results are the same.
28 The versions are generated to range from GLIBC_2.0 to GLIBC_2.Y,
29 with Y being the current __GLIBC_MINOR__ version plus two. In
30 addition, there is a list of special symbol versions of the form
31 GLIBC_2.Y.Z, which were used for some releases.
33 Comparing the two dlvsym results at versions which do not actually
34 exist does not test much, but it will not contribute to false test
35 failures, either. */
37 #include <array_length.h>
38 #include <gnu/lib-names.h>
39 #include <stdbool.h>
40 #include <stdio.h>
41 #include <support/check.h>
42 #include <support/xdlfcn.h>
44 /* Run consistency check for versioned symbol NAME@VERSION. NB: We
45 may execute in a shared object, so exit on error for proper error
46 reporting. */
47 static void
48 compare_vsyms_0 (void *libc_handle, const char *name, const char *version,
49 bool *pfound)
51 void *dlvsym_address = dlvsym (libc_handle, name, version);
52 void *libc_dlvsym_address
53 = __libc_dlvsym (libc_handle, name, version);
54 if (dlvsym_address != libc_dlvsym_address)
55 FAIL_EXIT1 ("%s@%s mismatch: %p != %p",
56 name, version, dlvsym_address, libc_dlvsym_address);
57 if (dlvsym_address != NULL)
58 *pfound = true;
62 /* Run consistency check for versioned symbol NAME at multiple symbol
63 version. */
64 static void
65 compare_vsyms_1 (void *libc_handle, const char *name)
67 bool found = false;
69 /* Historic versions which do not follow the usual GLIBC_2.Y
70 pattern, to increase test coverage. Not all architectures have
71 those, but probing additional versions does not hurt. */
72 static const char special_versions[][12] =
74 "GLIBC_2.1.1",
75 "GLIBC_2.1.2",
76 "GLIBC_2.1.3",
77 "GLIBC_2.1.4",
78 "GLIBC_2.2.1",
79 "GLIBC_2.2.2",
80 "GLIBC_2.2.3",
81 "GLIBC_2.2.4",
82 "GLIBC_2.2.5",
83 "GLIBC_2.2.6",
84 "GLIBC_2.3.2",
85 "GLIBC_2.3.3",
86 "GLIBC_2.3.4",
88 for (int i = 0; i < array_length (special_versions); ++i)
89 compare_vsyms_0 (libc_handle, name, special_versions[i], &found);
91 /* Iterate to an out-of-range version, to cover some unused symbols
92 as well. */
93 for (int minor_version = 0; minor_version <= __GLIBC_MINOR__ + 2;
94 ++minor_version)
96 char version[30];
97 snprintf (version, sizeof (version), "GLIBC_%d.%d",
98 __GLIBC__, minor_version);
99 compare_vsyms_0 (libc_handle, name, version, &found);
102 if (!found)
103 FAIL_EXIT1 ("symbol %s not found at any version", name);
106 /* Run consistency checks for various symbols which usually have
107 multiple versions. */
108 static void
109 compare_vsyms (void)
111 /* The minor version loop in compare_vsyms_1 needs updating in case
112 we ever switch to glibc 3.0. */
113 if (__GLIBC__ != 2)
114 FAIL_EXIT1 ("unexpected glibc major version: %d", __GLIBC__);
116 /* __libc_dlvsym does not recognize the special RTLD_* handles, so
117 obtain an explicit handle for libc.so. */
118 void *libc_handle = xdlopen (LIBC_SO, RTLD_LAZY | RTLD_NOLOAD);
120 compare_vsyms_1 (libc_handle, "_sys_errlist");
121 compare_vsyms_1 (libc_handle, "_sys_siglist");
122 compare_vsyms_1 (libc_handle, "quick_exit");
124 xdlclose (libc_handle);