| 1 | /* Macros for managing ABI-compatibility definitions using ELF symbol versions. | 
|---|
| 2 | Copyright (C) 2000-2020 Free Software Foundation, Inc. | 
|---|
| 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 | <https://www.gnu.org/licenses/>.  */ | 
|---|
| 18 |  | 
|---|
| 19 | #ifndef _SHLIB_COMPAT_H | 
|---|
| 20 | #define _SHLIB_COMPAT_H	1 | 
|---|
| 21 |  | 
|---|
| 22 | # include <abi-versions.h> | 
|---|
| 23 |  | 
|---|
| 24 | #ifdef SHARED | 
|---|
| 25 |  | 
|---|
| 26 | /* The file abi-versions.h (generated by scripts/abi-versions.awk) defines | 
|---|
| 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 |  | 
|---|
| 41 | # define SHLIB_COMPAT(lib, introduced, obsoleted)			      \ | 
|---|
| 42 | _SHLIB_COMPAT (lib, introduced, obsoleted) | 
|---|
| 43 | # define _SHLIB_COMPAT(lib, introduced, obsoleted)			      \ | 
|---|
| 44 | (IS_IN (lib)								      \ | 
|---|
| 45 | && (!(ABI_##lib##_##obsoleted - 0)					      \ | 
|---|
| 46 | || ((ABI_##lib##_##introduced - 0) < (ABI_##lib##_##obsoleted - 0)))) | 
|---|
| 47 |  | 
|---|
| 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: | 
|---|
| 52 | versioned_symbol (libm, new_foo, foo, GLIBC_2_1); | 
|---|
| 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 |  | 
|---|
| 57 | # define versioned_symbol(lib, local, symbol, version) \ | 
|---|
| 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) \ | 
|---|
| 62 | default_symbol_version (local, symbol, name) | 
|---|
| 63 |  | 
|---|
| 64 | # define compat_symbol(lib, local, symbol, version) \ | 
|---|
| 65 | compat_symbol_reference (lib, local, symbol, version) | 
|---|
| 66 |  | 
|---|
| 67 | /* This is similar to compat_symbol, but allows versioning the same symbol | 
|---|
| 68 | to multiple version without having multiple symbol definitions.  For | 
|---|
| 69 | instance: | 
|---|
| 70 |  | 
|---|
| 71 | #if (SHLIB_COMPAT (libpthread, GLIBC_2_1_2, GLIBC_2_2)) | 
|---|
| 72 | compat_symbol_unique (libc, old_foo, GLIBC_2_1_2) | 
|---|
| 73 | #endif | 
|---|
| 74 |  | 
|---|
| 75 | #if (SHLIB_COMPAT (libpthread, GLIBC_2_2_6, GLIBC_2_3)) | 
|---|
| 76 | compat_symbol_unique (libc, old_foo, GLIBC_2_2_6) | 
|---|
| 77 | #endif | 
|---|
| 78 |  | 
|---|
| 79 | Internally it creates a unique strong alias to the input symbol and | 
|---|
| 80 | creates one compat_symbol on the alias.  Using the above example, | 
|---|
| 81 | it is similar to: | 
|---|
| 82 |  | 
|---|
| 83 | #if (SHLIB_COMPAT (libpthread, GLIBC_2_1_2, GLIBC_2_2)) | 
|---|
| 84 | strong_alias (old_foo, old_foo__COUNTER__) | 
|---|
| 85 | compat_symbol (libc, old_foo__COUNTER__, foo, GLIBC_2_2) | 
|---|
| 86 | #endif. | 
|---|
| 87 |  | 
|---|
| 88 | With __COUNTER__ being a monotonic number generated by the compiler.  */ | 
|---|
| 89 |  | 
|---|
| 90 | # define __compat_symbol_unique_concat(x, y) x ## y | 
|---|
| 91 | # define _compat_symbol_unique_concat(x, y) \ | 
|---|
| 92 | __compat_symbol_unique_concat (x, y) | 
|---|
| 93 | # define _compat_symbol_unique_alias(name) \ | 
|---|
| 94 | _compat_symbol_unique_concat (name, __COUNTER__) | 
|---|
| 95 | # define _compat_symbol_unique(lib, orig_name, name, version) \ | 
|---|
| 96 | strong_alias (orig_name, name) \ | 
|---|
| 97 | compat_symbol (lib, name, orig_name, version) | 
|---|
| 98 | # define compat_symbol_unique(lib, name, version) \ | 
|---|
| 99 | _compat_symbol_unique (lib, name, _compat_symbol_unique_alias (name), \ | 
|---|
| 100 | version) | 
|---|
| 101 |  | 
|---|
| 102 | #else | 
|---|
| 103 |  | 
|---|
| 104 | /* Not compiling ELF shared libraries at all, so never any old versions.  */ | 
|---|
| 105 | # define SHLIB_COMPAT(lib, introduced, obsoleted)	0 | 
|---|
| 106 |  | 
|---|
| 107 | /* No versions to worry about, just make this the global definition.  */ | 
|---|
| 108 | # define versioned_symbol(lib, local, symbol, version) \ | 
|---|
| 109 | weak_alias (local, symbol) | 
|---|
| 110 |  | 
|---|
| 111 | /* This should not appear outside `#if SHLIB_COMPAT (...)'.  */ | 
|---|
| 112 | # define compat_symbol(lib, local, symbol, version) ... | 
|---|
| 113 | # define compat_symbol_unique(lib, name, version) ... | 
|---|
| 114 |  | 
|---|
| 115 | #endif | 
|---|
| 116 |  | 
|---|
| 117 | /* Use compat_symbol_reference for a reference *or* definition of a | 
|---|
| 118 | specific version of a symbol.  Definitions are primarily used to | 
|---|
| 119 | ensure tests reference the exact compat symbol required, or define an | 
|---|
| 120 | interposing symbol of the right version e.g. __malloc_initialize_hook | 
|---|
| 121 | in mcheck-init.c.  Use compat_symbol to define such a symbol within | 
|---|
| 122 | the shared libraries that are built for users.  */ | 
|---|
| 123 | #define compat_symbol_reference(lib, local, symbol, version) \ | 
|---|
| 124 | compat_symbol_reference_1 (lib, local, symbol, version) | 
|---|
| 125 | #define compat_symbol_reference_1(lib, local, symbol, version) \ | 
|---|
| 126 | compat_symbol_reference_2 (local, symbol, VERSION_##lib##_##version) | 
|---|
| 127 | #define compat_symbol_reference_2(local, symbol, name) \ | 
|---|
| 128 | symbol_version_reference (local, symbol, name) | 
|---|
| 129 |  | 
|---|
| 130 | /* Export the symbol only for shared-library compatibility.  */ | 
|---|
| 131 | #define libc_sunrpc_symbol(name, aliasname, version) \ | 
|---|
| 132 | compat_symbol (libc, name, aliasname, version); | 
|---|
| 133 |  | 
|---|
| 134 | /* The TEST_COMPAT macro acts just like the SHLIB_COMPAT macro except | 
|---|
| 135 | that it does not check IS_IN.  It is used by tests that are testing | 
|---|
| 136 | functionality that is only available in specific GLIBC versions.  */ | 
|---|
| 137 |  | 
|---|
| 138 | # define TEST_COMPAT(lib, introduced, obsoleted)			      \ | 
|---|
| 139 | _TEST_COMPAT (lib, introduced, obsoleted) | 
|---|
| 140 | # define _TEST_COMPAT(lib, introduced, obsoleted)			      \ | 
|---|
| 141 | (!(ABI_##lib##_##obsoleted - 0)					      \ | 
|---|
| 142 | || ((ABI_##lib##_##introduced - 0) < (ABI_##lib##_##obsoleted - 0))) | 
|---|
| 143 |  | 
|---|
| 144 | #endif	/* shlib-compat.h */ | 
|---|
| 145 |  | 
|---|