math: Remove slow paths from atan2 [BZ #15267]
[glibc.git] / include / shlib-compat.h
blob28baef1ea42731f8b72ab08999658abf530e03aa
1 /* Macros for managing ABI-compatibility definitions using ELF symbol versions.
2 Copyright (C) 2000-2021 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 <https://www.gnu.org/licenses/>. */
19 #ifndef _SHLIB_COMPAT_H
20 #define _SHLIB_COMPAT_H 1
22 # include <abi-versions.h>
24 /* The file abi-versions.h (generated by scripts/abi-versions.awk) defines
25 symbols like `ABI_libm_GLIBC_2_0' for each version set in the source
26 code for each library. For a version set that is subsumed by a later
27 version set, the definition gives the subsuming set, i.e. if GLIBC_2_0
28 is subsumed by GLIBC_2_1, then ABI_libm_GLIBC_2_0 == ABI_libm_GLIBC_2_1.
29 Each version set that is to be distinctly defined in the output has an
30 unique positive integer value, increasing with newer versions. Thus,
31 evaluating two ABI_* symbols reduces to integer values that differ only
32 when the two version sets named are in fact two different ABIs we are
33 supporting. If these do not differ, then there is no need to compile in
34 extra code to support this version set where it has been superseded by a
35 newer version. */
36 #define LIB_COMPAT(lib, introduced, obsoleted) \
37 _LIB_COMPAT (lib, introduced, obsoleted)
38 #define _LIB_COMPAT(lib, introduced, obsoleted) \
39 (IS_IN (lib) \
40 && (!(ABI_##lib##_##obsoleted - 0) \
41 || ((ABI_##lib##_##introduced - 0) < (ABI_##lib##_##obsoleted - 0))))
43 #ifdef SHARED
45 /* Similar to LIB_COMPAT, but evaluate to 0 for static build. The
46 compatibility code should be conditionalized with e.g.
47 `#if SHLIB_COMPAT (libm, GLIBC_2_0, GLIBC_2_2)' for code introduced
48 in the GLIBC_2.0 version and obsoleted in the GLIBC_2.2 version. */
50 # define SHLIB_COMPAT(lib, introduced, obsoleted) \
51 _LIB_COMPAT (lib, introduced, obsoleted)
53 /* That header also defines symbols like `VERSION_libm_GLIBC_2_1' to
54 the version set name to use for e.g. symbols first introduced into
55 libm in the GLIBC_2.1 version. Definitions of symbols with explicit
56 versions should look like:
57 versioned_symbol (libm, new_foo, foo, GLIBC_2_1);
58 This will define the symbol `foo' with the appropriate default version,
59 i.e. either GLIBC_2.1 or the "earliest version" specified in
60 shlib-versions if that is newer. */
62 # define versioned_symbol(lib, local, symbol, version) \
63 versioned_symbol_1 (lib, local, symbol, version)
64 # define versioned_symbol_1(lib, local, symbol, version) \
65 versioned_symbol_2 (local, symbol, VERSION_##lib##_##version)
66 # define versioned_symbol_2(local, symbol, name) \
67 default_symbol_version (local, symbol, name)
69 # define compat_symbol(lib, local, symbol, version) \
70 compat_symbol_reference (lib, local, symbol, version)
72 /* This is similar to compat_symbol, but allows versioning the same symbol
73 to multiple version without having multiple symbol definitions. For
74 instance:
76 #if (SHLIB_COMPAT (libpthread, GLIBC_2_1_2, GLIBC_2_2))
77 compat_symbol_unique (libc, old_foo, GLIBC_2_1_2)
78 #endif
80 #if (SHLIB_COMPAT (libpthread, GLIBC_2_2_6, GLIBC_2_3))
81 compat_symbol_unique (libc, old_foo, GLIBC_2_2_6)
82 #endif
84 Internally it creates a unique strong alias to the input symbol and
85 creates one compat_symbol on the alias. Using the above example,
86 it is similar to:
88 #if (SHLIB_COMPAT (libpthread, GLIBC_2_1_2, GLIBC_2_2))
89 strong_alias (old_foo, old_foo__COUNTER__)
90 compat_symbol (libc, old_foo__COUNTER__, foo, GLIBC_2_2)
91 #endif.
93 With __COUNTER__ being a monotonic number generated by the compiler. */
95 # define __compat_symbol_unique_concat(x, y) x ## y
96 # define _compat_symbol_unique_concat(x, y) \
97 __compat_symbol_unique_concat (x, y)
98 # define _compat_symbol_unique_alias(name) \
99 _compat_symbol_unique_concat (name, __COUNTER__)
100 # define _compat_symbol_unique(lib, orig_name, name, version) \
101 strong_alias (orig_name, name) \
102 compat_symbol (lib, name, orig_name, version)
103 # define compat_symbol_unique(lib, name, version) \
104 _compat_symbol_unique (lib, name, _compat_symbol_unique_alias (name), \
105 version)
107 #else
109 /* Not compiling ELF shared libraries at all, so never any old versions. */
110 # define SHLIB_COMPAT(lib, introduced, obsoleted) 0
112 /* No versions to worry about, just make this the global definition. */
113 # define versioned_symbol(lib, local, symbol, version) \
114 weak_alias (local, symbol)
116 /* This should not appear outside `#if SHLIB_COMPAT (...)'. */
117 # define compat_symbol(lib, local, symbol, version) ...
118 # define compat_symbol_unique(lib, name, version) ...
120 #endif
122 /* Use compat_symbol_reference for a reference *or* definition of a
123 specific version of a symbol. Definitions are primarily used to
124 ensure tests reference the exact compat symbol required, or define an
125 interposing symbol of the right version e.g. __malloc_initialize_hook
126 in mcheck-init.c. Use compat_symbol to define such a symbol within
127 the shared libraries that are built for users. */
128 #define compat_symbol_reference(lib, local, symbol, version) \
129 compat_symbol_reference_1 (lib, local, symbol, version)
130 #define compat_symbol_reference_1(lib, local, symbol, version) \
131 compat_symbol_reference_2 (local, symbol, VERSION_##lib##_##version)
132 #define compat_symbol_reference_2(local, symbol, name) \
133 symbol_version_reference (local, symbol, name)
135 /* Export the symbol only for shared-library compatibility. */
136 #define libc_sunrpc_symbol(name, aliasname, version) \
137 compat_symbol (libc, name, aliasname, version);
139 /* The TEST_COMPAT macro acts just like the SHLIB_COMPAT macro except
140 that it does not check IS_IN. It is used by tests that are testing
141 functionality that is only available in specific GLIBC versions. */
143 # define TEST_COMPAT(lib, introduced, obsoleted) \
144 _TEST_COMPAT (lib, introduced, obsoleted)
145 # define _TEST_COMPAT(lib, introduced, obsoleted) \
146 (!(ABI_##lib##_##obsoleted - 0) \
147 || ((ABI_##lib##_##introduced - 0) < (ABI_##lib##_##obsoleted - 0)))
149 #endif /* shlib-compat.h */