]> git.ipfire.org Git - thirdparty/glibc.git/blame - elf/tst-libc_dlvsym.h
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / elf / tst-libc_dlvsym.h
CommitLineData
82eef55f 1/* Compare dlvsym and __libc_dlvsym results. Common code.
04277e02 2 Copyright (C) 2017-2019 Free Software Foundation, Inc.
82eef55f
FW
3 This file is part of the GNU C Library.
4
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.
9
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.
14
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/>. */
18
19/* compare_vsyms is the main entry point for these tests.
20
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.
27
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.
32
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. */
36
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>
43
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. */
47static void
48compare_vsyms_0 (void *libc_handle, const char *name, const char *version,
49 bool *pfound)
50{
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;
59}
60
61
62/* Run consistency check for versioned symbol NAME at multiple symbol
63 version. */
64static void
65compare_vsyms_1 (void *libc_handle, const char *name)
66{
67 bool found = false;
68
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] =
73 {
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",
87 };
88 for (int i = 0; i < array_length (special_versions); ++i)
89 compare_vsyms_0 (libc_handle, name, special_versions[i], &found);
90
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)
95 {
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);
100 }
101
102 if (!found)
103 FAIL_EXIT1 ("symbol %s not found at any version", name);
104}
105
106/* Run consistency checks for various symbols which usually have
107 multiple versions. */
108static void
109compare_vsyms (void)
110{
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__);
115
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);
119
120 compare_vsyms_1 (libc_handle, "_sys_errlist");
121 compare_vsyms_1 (libc_handle, "_sys_siglist");
122 compare_vsyms_1 (libc_handle, "quick_exit");
123
124 xdlclose (libc_handle);
125}