]> git.ipfire.org Git - thirdparty/glibc.git/blame - include/shlib-compat.h
misc: Fix tst-select timeout handling (BZ#27648)
[thirdparty/glibc.git] / include / shlib-compat.h
CommitLineData
361742ed 1/* Macros for managing ABI-compatibility definitions using ELF symbol versions.
2b778ceb 2 Copyright (C) 2000-2021 Free Software Foundation, Inc.
361742ed
RM
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
41bdb6e2
AJ
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.
361742ed
RM
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
41bdb6e2 13 Lesser General Public License for more details.
361742ed 14
41bdb6e2 15 You should have received a copy of the GNU Lesser General Public
59ba27a6 16 License along with the GNU C Library; if not, see
5a82c748 17 <https://www.gnu.org/licenses/>. */
361742ed
RM
18
19#ifndef _SHLIB_COMPAT_H
20#define _SHLIB_COMPAT_H 1
21
3f2e46a4 22# include <abi-versions.h>
361742ed 23
3a24ddea
FW
24/* Obtain the definition of symbol_version_reference. */
25#include <libc-symver.h>
26
361742ed 27/* The file abi-versions.h (generated by scripts/abi-versions.awk) defines
cb832354
RM
28 symbols like `ABI_libm_GLIBC_2_0' for each version set in the source
29 code for each library. For a version set that is subsumed by a later
30 version set, the definition gives the subsuming set, i.e. if GLIBC_2_0
31 is subsumed by GLIBC_2_1, then ABI_libm_GLIBC_2_0 == ABI_libm_GLIBC_2_1.
32 Each version set that is to be distinctly defined in the output has an
33 unique positive integer value, increasing with newer versions. Thus,
34 evaluating two ABI_* symbols reduces to integer values that differ only
35 when the two version sets named are in fact two different ABIs we are
36 supporting. If these do not differ, then there is no need to compile in
37 extra code to support this version set where it has been superseded by a
46c1c765
AZ
38 newer version. */
39#define LIB_COMPAT(lib, introduced, obsoleted) \
40 _LIB_COMPAT (lib, introduced, obsoleted)
41#define _LIB_COMPAT(lib, introduced, obsoleted) \
286663c3 42 (IS_IN (lib) \
ce460d04
RM
43 && (!(ABI_##lib##_##obsoleted - 0) \
44 || ((ABI_##lib##_##introduced - 0) < (ABI_##lib##_##obsoleted - 0))))
45
46c1c765
AZ
46#ifdef SHARED
47
48/* Similar to LIB_COMPAT, but evaluate to 0 for static build. The
49 compatibility code should be conditionalized with e.g.
50 `#if SHLIB_COMPAT (libm, GLIBC_2_0, GLIBC_2_2)' for code introduced
51 in the GLIBC_2.0 version and obsoleted in the GLIBC_2.2 version. */
52
53# define SHLIB_COMPAT(lib, introduced, obsoleted) \
54 _LIB_COMPAT (lib, introduced, obsoleted)
55
361742ed
RM
56/* That header also defines symbols like `VERSION_libm_GLIBC_2_1' to
57 the version set name to use for e.g. symbols first introduced into
58 libm in the GLIBC_2.1 version. Definitions of symbols with explicit
59 versions should look like:
350635a5 60 versioned_symbol (libm, new_foo, foo, GLIBC_2_1);
361742ed
RM
61 This will define the symbol `foo' with the appropriate default version,
62 i.e. either GLIBC_2.1 or the "earliest version" specified in
63 shlib-versions if that is newer. */
64
0923f74a
FW
65/* versioned_symbol (LIB, LOCAL, SYMBOL, VERSION) emits a definition
66 of SYMBOL with a default (@@) VERSION appropriate for LIB. (The
67 actually emitted symbol version is adjusted according to the
68 baseline symbol version for LIB.) The address of the symbol is
69 taken from LOCAL. Properties of LOCAL are copied to the exported
70 symbol. In particular, LOCAL itself should be global. It is
71 unspecified whether SYMBOL@VERSION is associated with LOCAL, or if
72 an intermediate alias is created. If LOCAL and SYMBOL are
73 distinct, and LOCAL is also intended for export, its version should
74 be specified explicitly with versioned_symbol, too.
75
76 If LOCAL is a data symbol and does not have a non-zero initializer,
77 it should be defined with __attribute__ ((nocommon)) for
78 compatibility with GCC versions that default to -fcommon. */
cb162e13 79# define versioned_symbol(lib, local, symbol, version) \
11bf311e
UD
80 versioned_symbol_1 (lib, local, symbol, version)
81# define versioned_symbol_1(lib, local, symbol, version) \
82 versioned_symbol_2 (local, symbol, VERSION_##lib##_##version)
83# define versioned_symbol_2(local, symbol, name) \
cb162e13 84 default_symbol_version (local, symbol, name)
361742ed 85
0923f74a
FW
86/* compat_symbol is like versioned_symbol, but emits a compatibility
87 version (with @ instead of @@). The same issue related to
88 intermediate aliases applies, so LOCAL should not be listed in the
89 Versions file, or otherwise it can be exported with an undesired
90 default symbol version. */
2ae13e20 91# define compat_symbol(lib, local, symbol, version) \
0923f74a
FW
92 compat_symbol_1 (lib, local, symbol, version)
93# define compat_symbol_1(lib, local, symbol, version) \
94 compat_symbol_2 (local, symbol, VERSION_##lib##_##version)
95/* See <libc-symver.h>. */
96# ifdef __ASSEMBLER__
97#define compat_symbol_2(local, symbol, name) \
98 _set_symbol_version (local, symbol@name)
99# else
100# define compat_symbol_2(local, symbol, name) \
101 compat_symbol_3 (local, symbol, name)
102# define compat_symbol_3(local, symbol, name) \
103 _set_symbol_version (local, #symbol "@" #name)
104# endif
361742ed
RM
105#else
106
107/* Not compiling ELF shared libraries at all, so never any old versions. */
cb832354 108# define SHLIB_COMPAT(lib, introduced, obsoleted) 0
361742ed
RM
109
110/* No versions to worry about, just make this the global definition. */
cb162e13 111# define versioned_symbol(lib, local, symbol, version) \
361742ed
RM
112 weak_alias (local, symbol)
113
2ae13e20
RM
114/* This should not appear outside `#if SHLIB_COMPAT (...)'. */
115# define compat_symbol(lib, local, symbol, version) ...
116
361742ed
RM
117#endif
118
3480ddc4 119/* Use compat_symbol_reference for a reference *or* definition of a
0923f74a
FW
120 specific version of a symbol. compat_symbol_reference does not
121 create intermediate aliases. Definitions are primarily used to
122 ensure tests reference the exact compat symbol required, or define
123 an interposing symbol of the right version e.g.,
124 __malloc_initialize_hook in mcheck-init.c. Use compat_symbol to
125 define such a symbol within the shared libraries that are built for
126 users. */
968dc26d
FW
127#define compat_symbol_reference(lib, local, symbol, version) \
128 compat_symbol_reference_1 (lib, local, symbol, version)
129#define compat_symbol_reference_1(lib, local, symbol, version) \
130 compat_symbol_reference_2 (local, symbol, VERSION_##lib##_##version)
131#define compat_symbol_reference_2(local, symbol, name) \
132 symbol_version_reference (local, symbol, name)
361742ed 133
07c58f8f 134/* Export the symbol only for shared-library compatibility. */
5500cdba 135#define libc_sunrpc_symbol(name, aliasname, version) \
07c58f8f 136 compat_symbol (libc, name, aliasname, version);
07c58f8f 137
05b38d64
SE
138/* The TEST_COMPAT macro acts just like the SHLIB_COMPAT macro except
139 that it does not check IS_IN. It is used by tests that are testing
140 functionality that is only available in specific GLIBC versions. */
141
142# define TEST_COMPAT(lib, introduced, obsoleted) \
143 _TEST_COMPAT (lib, introduced, obsoleted)
144# define _TEST_COMPAT(lib, introduced, obsoleted) \
145 (!(ABI_##lib##_##obsoleted - 0) \
146 || ((ABI_##lib##_##introduced - 0) < (ABI_##lib##_##obsoleted - 0)))
147
361742ed 148#endif /* shlib-compat.h */