]>
Commit | Line | Data |
---|---|---|
361742ed | 1 | /* Macros for managing ABI-compatibility definitions using ELF symbol versions. |
04277e02 | 2 | Copyright (C) 2000-2019 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 PE |
16 | License along with the GNU C Library; if not, see |
17 | <http://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 | |
968dc26d FW |
24 | #ifdef SHARED |
25 | ||
361742ed | 26 | /* The file abi-versions.h (generated by scripts/abi-versions.awk) defines |
cb832354 RM |
27 | symbols like `ABI_libm_GLIBC_2_0' for each version set in the source |
28 | code for each library. For a version set that is subsumed by a later | |
29 | version set, the definition gives the subsuming set, i.e. if GLIBC_2_0 | |
30 | is subsumed by GLIBC_2_1, then ABI_libm_GLIBC_2_0 == ABI_libm_GLIBC_2_1. | |
31 | Each version set that is to be distinctly defined in the output has an | |
32 | unique positive integer value, increasing with newer versions. Thus, | |
33 | evaluating two ABI_* symbols reduces to integer values that differ only | |
34 | when the two version sets named are in fact two different ABIs we are | |
35 | supporting. If these do not differ, then there is no need to compile in | |
36 | extra code to support this version set where it has been superseded by a | |
37 | newer version. The compatibility code should be conditionalized with | |
38 | e.g. `#if SHLIB_COMPAT (libm, GLIBC_2_0, GLIBC_2_2)' for code introduced | |
39 | in the GLIBC_2.0 version and obsoleted in the GLIBC_2.2 version. */ | |
40 | ||
ce460d04 | 41 | # define SHLIB_COMPAT(lib, introduced, obsoleted) \ |
11bf311e UD |
42 | _SHLIB_COMPAT (lib, introduced, obsoleted) |
43 | # define _SHLIB_COMPAT(lib, introduced, obsoleted) \ | |
286663c3 | 44 | (IS_IN (lib) \ |
ce460d04 RM |
45 | && (!(ABI_##lib##_##obsoleted - 0) \ |
46 | || ((ABI_##lib##_##introduced - 0) < (ABI_##lib##_##obsoleted - 0)))) | |
47 | ||
361742ed RM |
48 | /* That header also defines symbols like `VERSION_libm_GLIBC_2_1' to |
49 | the version set name to use for e.g. symbols first introduced into | |
50 | libm in the GLIBC_2.1 version. Definitions of symbols with explicit | |
51 | versions should look like: | |
350635a5 | 52 | versioned_symbol (libm, new_foo, foo, GLIBC_2_1); |
361742ed RM |
53 | This will define the symbol `foo' with the appropriate default version, |
54 | i.e. either GLIBC_2.1 or the "earliest version" specified in | |
55 | shlib-versions if that is newer. */ | |
56 | ||
cb162e13 | 57 | # define versioned_symbol(lib, local, symbol, version) \ |
11bf311e UD |
58 | versioned_symbol_1 (lib, local, symbol, version) |
59 | # define versioned_symbol_1(lib, local, symbol, version) \ | |
60 | versioned_symbol_2 (local, symbol, VERSION_##lib##_##version) | |
61 | # define versioned_symbol_2(local, symbol, name) \ | |
cb162e13 | 62 | default_symbol_version (local, symbol, name) |
361742ed | 63 | |
2ae13e20 | 64 | # define compat_symbol(lib, local, symbol, version) \ |
968dc26d | 65 | compat_symbol_reference (lib, local, symbol, version) |
2ae13e20 | 66 | |
361742ed RM |
67 | #else |
68 | ||
69 | /* Not compiling ELF shared libraries at all, so never any old versions. */ | |
cb832354 | 70 | # define SHLIB_COMPAT(lib, introduced, obsoleted) 0 |
361742ed RM |
71 | |
72 | /* No versions to worry about, just make this the global definition. */ | |
cb162e13 | 73 | # define versioned_symbol(lib, local, symbol, version) \ |
361742ed RM |
74 | weak_alias (local, symbol) |
75 | ||
2ae13e20 RM |
76 | /* This should not appear outside `#if SHLIB_COMPAT (...)'. */ |
77 | # define compat_symbol(lib, local, symbol, version) ... | |
78 | ||
361742ed RM |
79 | #endif |
80 | ||
3480ddc4 CD |
81 | /* Use compat_symbol_reference for a reference *or* definition of a |
82 | specific version of a symbol. Definitions are primarily used to | |
83 | ensure tests reference the exact compat symbol required, or define an | |
84 | interposing symbol of the right version e.g. __malloc_initialize_hook | |
85 | in mcheck-init.c. Use compat_symbol to define such a symbol within | |
86 | the shared libraries that are built for users. */ | |
968dc26d FW |
87 | #define compat_symbol_reference(lib, local, symbol, version) \ |
88 | compat_symbol_reference_1 (lib, local, symbol, version) | |
89 | #define compat_symbol_reference_1(lib, local, symbol, version) \ | |
90 | compat_symbol_reference_2 (local, symbol, VERSION_##lib##_##version) | |
91 | #define compat_symbol_reference_2(local, symbol, name) \ | |
92 | symbol_version_reference (local, symbol, name) | |
361742ed | 93 | |
07c58f8f AJ |
94 | # ifdef LINK_OBSOLETE_RPC |
95 | /* Export the symbol for both static and dynamic linking. */ | |
96 | # define libc_sunrpc_symbol(name, aliasname, version) \ | |
97 | strong_alias (name, aliasname) | |
98 | # else | |
99 | /* Export the symbol only for shared-library compatibility. */ | |
100 | # define libc_sunrpc_symbol(name, aliasname, version) \ | |
101 | compat_symbol (libc, name, aliasname, version); | |
102 | # endif | |
103 | ||
05b38d64 SE |
104 | /* The TEST_COMPAT macro acts just like the SHLIB_COMPAT macro except |
105 | that it does not check IS_IN. It is used by tests that are testing | |
106 | functionality that is only available in specific GLIBC versions. */ | |
107 | ||
108 | # define TEST_COMPAT(lib, introduced, obsoleted) \ | |
109 | _TEST_COMPAT (lib, introduced, obsoleted) | |
110 | # define _TEST_COMPAT(lib, introduced, obsoleted) \ | |
111 | (!(ABI_##lib##_##obsoleted - 0) \ | |
112 | || ((ABI_##lib##_##introduced - 0) < (ABI_##lib##_##obsoleted - 0))) | |
113 | ||
361742ed | 114 | #endif /* shlib-compat.h */ |