| 1 | /* Support macros for making weak and strong aliases for symbols, | 
|---|
| 2 | and for using symbol sets and linker warnings with GNU ld. | 
|---|
| 3 | Copyright (C) 1995-2017 Free Software Foundation, Inc. | 
|---|
| 4 | This file is part of the GNU C Library. | 
|---|
| 5 |  | 
|---|
| 6 | The GNU C Library is free software; you can redistribute it and/or | 
|---|
| 7 | modify it under the terms of the GNU Lesser General Public | 
|---|
| 8 | License as published by the Free Software Foundation; either | 
|---|
| 9 | version 2.1 of the License, or (at your option) any later version. | 
|---|
| 10 |  | 
|---|
| 11 | The GNU C Library is distributed in the hope that it will be useful, | 
|---|
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | 
|---|
| 14 | Lesser General Public License for more details. | 
|---|
| 15 |  | 
|---|
| 16 | You should have received a copy of the GNU Lesser General Public | 
|---|
| 17 | License along with the GNU C Library; if not, see | 
|---|
| 18 | <http://www.gnu.org/licenses/>.  */ | 
|---|
| 19 |  | 
|---|
| 20 | #ifndef _LIBC_SYMBOLS_H | 
|---|
| 21 | #define _LIBC_SYMBOLS_H	1 | 
|---|
| 22 |  | 
|---|
| 23 | /* This file is included implicitly in the compilation of every source file, | 
|---|
| 24 | using -include.  It includes config.h.  */ | 
|---|
| 25 |  | 
|---|
| 26 | /* Enable declarations of GNU extensions, since we are compiling them.  */ | 
|---|
| 27 | #define _GNU_SOURCE 1 | 
|---|
| 28 |  | 
|---|
| 29 | #ifdef MODULE_NAME | 
|---|
| 30 |  | 
|---|
| 31 | /* Use `#if IS_IN (module)` to detect what component is being compiled.  */ | 
|---|
| 32 | #define PASTE_NAME1(a,b) a##b | 
|---|
| 33 | #define PASTE_NAME(a,b)	 PASTE_NAME1 (a,b) | 
|---|
| 34 | #define IN_MODULE	 PASTE_NAME (MODULE_, MODULE_NAME) | 
|---|
| 35 | #define IS_IN(lib)	 (IN_MODULE == MODULE_##lib) | 
|---|
| 36 |  | 
|---|
| 37 | /* True if the current module is a versioned library.  Versioned | 
|---|
| 38 | library names culled from shlib-versions files are assigned a | 
|---|
| 39 | MODULE_* value greater than MODULE_LIBS_BEGIN.  */ | 
|---|
| 40 | #define IS_IN_LIB	 (IN_MODULE > MODULE_LIBS_BEGIN) | 
|---|
| 41 |  | 
|---|
| 42 | /* The testsuite, and some other ancillary code, should be compiled against | 
|---|
| 43 | as close an approximation to the installed headers as possible. | 
|---|
| 44 | Defining this symbol disables most internal-use-only declarations | 
|---|
| 45 | provided by this header, and all those provided by other internal | 
|---|
| 46 | wrapper headers.  */ | 
|---|
| 47 | #if IS_IN (testsuite) || defined IS_IN_build || defined __cplusplus | 
|---|
| 48 | # define _ISOMAC 1 | 
|---|
| 49 | #endif | 
|---|
| 50 |  | 
|---|
| 51 | #else | 
|---|
| 52 | /* The generation process for a few files created very early in the | 
|---|
| 53 | build (notably libc-modules.h itself) involves preprocessing this | 
|---|
| 54 | header without defining MODULE_NAME.  Under these conditions, | 
|---|
| 55 | internal declarations (especially from config.h) must be visible, | 
|---|
| 56 | but IS_IN should always evaluate as false.  */ | 
|---|
| 57 | # define IS_IN(lib) 0 | 
|---|
| 58 | # define IS_IN_LIB 0 | 
|---|
| 59 | # define IN_MODULE (-1) | 
|---|
| 60 | #endif | 
|---|
| 61 |  | 
|---|
| 62 | #ifndef _ISOMAC | 
|---|
| 63 |  | 
|---|
| 64 | /* This is defined for the compilation of all C library code.  features.h | 
|---|
| 65 | tests this to avoid inclusion of stubs.h while compiling the library, | 
|---|
| 66 | before stubs.h has been generated.  Some library code that is shared | 
|---|
| 67 | with other packages also tests this symbol to see if it is being | 
|---|
| 68 | compiled as part of the C library.  We must define this before including | 
|---|
| 69 | config.h, because it makes some definitions conditional on whether libc | 
|---|
| 70 | itself is being compiled, or just some generator program.  */ | 
|---|
| 71 | #define _LIBC	1 | 
|---|
| 72 |  | 
|---|
| 73 | /* Some files must be compiled with optimization on.  */ | 
|---|
| 74 | #if !defined __ASSEMBLER__ && !defined __OPTIMIZE__ | 
|---|
| 75 | # error "glibc cannot be compiled without optimization" | 
|---|
| 76 | #endif | 
|---|
| 77 |  | 
|---|
| 78 | /* -ffast-math cannot be applied to the C library, as it alters the ABI. | 
|---|
| 79 | Some test components that use -ffast-math are currently not part of | 
|---|
| 80 | IS_IN (testsuite) for technical reasons, so we have a secondary override.  */ | 
|---|
| 81 | #if defined __FAST_MATH__ && !defined TEST_FAST_MATH | 
|---|
| 82 | # error "glibc must not be compiled with -ffast-math" | 
|---|
| 83 | #endif | 
|---|
| 84 |  | 
|---|
| 85 | #include <config.h> | 
|---|
| 86 |  | 
|---|
| 87 | /* Define this for the benefit of portable GNU code that wants to check it. | 
|---|
| 88 | Code that checks with #if will not #include <config.h> again, since we've | 
|---|
| 89 | already done it (and this file is implicitly included in every compile, | 
|---|
| 90 | via -include).  Code that checks with #ifdef will #include <config.h>, | 
|---|
| 91 | but that file should always be idempotent (i.e., it's just #define/#undef | 
|---|
| 92 | and nothing else anywhere should be changing the macro state it touches), | 
|---|
| 93 | so it's harmless.  */ | 
|---|
| 94 | #define HAVE_CONFIG_H	0 | 
|---|
| 95 |  | 
|---|
| 96 | /* Define these macros for the benefit of portable GNU code that wants to check | 
|---|
| 97 | them.  Of course, STDC_HEADERS is never false when building libc!  */ | 
|---|
| 98 | #define 	1 | 
|---|
| 99 | #define HAVE_MBSTATE_T	1 | 
|---|
| 100 | #define HAVE_MBSRTOWCS	1 | 
|---|
| 101 | #define HAVE_LIBINTL_H	1 | 
|---|
| 102 | #define HAVE_WCTYPE_H	1 | 
|---|
| 103 | #define HAVE_ISWCTYPE	1 | 
|---|
| 104 | #define ENABLE_NLS	1 | 
|---|
| 105 |  | 
|---|
| 106 | /* The symbols in all the user (non-_) macros are C symbols.  */ | 
|---|
| 107 |  | 
|---|
| 108 | #ifndef __SYMBOL_PREFIX | 
|---|
| 109 | # define __SYMBOL_PREFIX | 
|---|
| 110 | #endif | 
|---|
| 111 |  | 
|---|
| 112 | #ifndef C_SYMBOL_NAME | 
|---|
| 113 | # define C_SYMBOL_NAME(name) name | 
|---|
| 114 | #endif | 
|---|
| 115 |  | 
|---|
| 116 | #ifndef ASM_LINE_SEP | 
|---|
| 117 | # define ASM_LINE_SEP ; | 
|---|
| 118 | #endif | 
|---|
| 119 |  | 
|---|
| 120 | #ifndef __ASSEMBLER__ | 
|---|
| 121 | /* GCC understands weak symbols and aliases; use its interface where | 
|---|
| 122 | possible, instead of embedded assembly language.  */ | 
|---|
| 123 |  | 
|---|
| 124 | /* Define ALIASNAME as a strong alias for NAME.  */ | 
|---|
| 125 | # define strong_alias(name, aliasname) _strong_alias(name, aliasname) | 
|---|
| 126 | # define _strong_alias(name, aliasname) \ | 
|---|
| 127 | extern __typeof (name) aliasname __attribute__ ((alias (#name))); | 
|---|
| 128 |  | 
|---|
| 129 | /* This comes between the return type and function name in | 
|---|
| 130 | a function definition to make that definition weak.  */ | 
|---|
| 131 | # define weak_function __attribute__ ((weak)) | 
|---|
| 132 | # define weak_const_function __attribute__ ((weak, __const__)) | 
|---|
| 133 |  | 
|---|
| 134 | /* Define ALIASNAME as a weak alias for NAME. | 
|---|
| 135 | If weak aliases are not available, this defines a strong alias.  */ | 
|---|
| 136 | # define weak_alias(name, aliasname) _weak_alias (name, aliasname) | 
|---|
| 137 | # define _weak_alias(name, aliasname) \ | 
|---|
| 138 | extern __typeof (name) aliasname __attribute__ ((weak, alias (#name))); | 
|---|
| 139 |  | 
|---|
| 140 | /* Same as WEAK_ALIAS, but mark symbol as hidden.  */ | 
|---|
| 141 | # define weak_hidden_alias(name, aliasname) \ | 
|---|
| 142 | _weak_hidden_alias (name, aliasname) | 
|---|
| 143 | # define _weak_hidden_alias(name, aliasname) \ | 
|---|
| 144 | extern __typeof (name) aliasname \ | 
|---|
| 145 | __attribute__ ((weak, alias (#name), __visibility__ ("hidden"))); | 
|---|
| 146 |  | 
|---|
| 147 | /* Declare SYMBOL as weak undefined symbol (resolved to 0 if not defined).  */ | 
|---|
| 148 | # define weak_extern(symbol) _weak_extern (weak symbol) | 
|---|
| 149 | # define _weak_extern(expr) _Pragma (#expr) | 
|---|
| 150 |  | 
|---|
| 151 | /* In shared builds, the expression call_function_static_weak | 
|---|
| 152 | (FUNCTION-SYMBOL, ARGUMENTS) invokes FUNCTION-SYMBOL (an | 
|---|
| 153 | identifier) unconditionally, with the (potentially empty) argument | 
|---|
| 154 | list ARGUMENTS.  In static builds, if FUNCTION-SYMBOL has a | 
|---|
| 155 | definition, the function is invoked as before; if FUNCTION-SYMBOL | 
|---|
| 156 | is NULL, no call is performed.  */ | 
|---|
| 157 | # ifdef SHARED | 
|---|
| 158 | #  define call_function_static_weak(func, ...) func (__VA_ARGS__) | 
|---|
| 159 | # else	/* !SHARED */ | 
|---|
| 160 | #  define call_function_static_weak(func, ...)		\ | 
|---|
| 161 | ({							\ | 
|---|
| 162 | extern __typeof__ (func) func weak_function;	\ | 
|---|
| 163 | (func != NULL ? func (__VA_ARGS__) : (void)0);	\ | 
|---|
| 164 | }) | 
|---|
| 165 | # endif | 
|---|
| 166 |  | 
|---|
| 167 | #else /* __ASSEMBLER__ */ | 
|---|
| 168 |  | 
|---|
| 169 | # ifdef HAVE_ASM_SET_DIRECTIVE | 
|---|
| 170 | #  define strong_alias(original, alias)				\ | 
|---|
| 171 | .globl C_SYMBOL_NAME (alias) ASM_LINE_SEP		\ | 
|---|
| 172 | .set C_SYMBOL_NAME (alias),C_SYMBOL_NAME (original) | 
|---|
| 173 | #  define strong_data_alias(original, alias) strong_alias(original, alias) | 
|---|
| 174 | # else | 
|---|
| 175 | #  define strong_alias(original, alias)				\ | 
|---|
| 176 | .globl C_SYMBOL_NAME (alias) ASM_LINE_SEP		\ | 
|---|
| 177 | C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original) | 
|---|
| 178 | #  define strong_data_alias(original, alias) strong_alias(original, alias) | 
|---|
| 179 | # endif | 
|---|
| 180 |  | 
|---|
| 181 | # define weak_alias(original, alias)					\ | 
|---|
| 182 | .weak C_SYMBOL_NAME (alias) ASM_LINE_SEP				\ | 
|---|
| 183 | C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original) | 
|---|
| 184 |  | 
|---|
| 185 | # define weak_extern(symbol)						\ | 
|---|
| 186 | .weak C_SYMBOL_NAME (symbol) | 
|---|
| 187 |  | 
|---|
| 188 | #endif /* __ASSEMBLER__ */ | 
|---|
| 189 |  | 
|---|
| 190 | /* On some platforms we can make internal function calls (i.e., calls of | 
|---|
| 191 | functions not exported) a bit faster by using a different calling | 
|---|
| 192 | convention.  */ | 
|---|
| 193 | #ifndef internal_function | 
|---|
| 194 | # define internal_function	/* empty */ | 
|---|
| 195 | #endif | 
|---|
| 196 |  | 
|---|
| 197 | /* Determine the return address.  */ | 
|---|
| 198 | #define RETURN_ADDRESS(nr) \ | 
|---|
| 199 | __builtin_extract_return_addr (__builtin_return_address (nr)) | 
|---|
| 200 |  | 
|---|
| 201 | /* When a reference to SYMBOL is encountered, the linker will emit a | 
|---|
| 202 | warning message MSG.  */ | 
|---|
| 203 | /* We want the .gnu.warning.SYMBOL section to be unallocated.  */ | 
|---|
| 204 | #define __make_section_unallocated(section_string)	\ | 
|---|
| 205 | asm (".section " section_string "\n\t.previous"); | 
|---|
| 206 |  | 
|---|
| 207 | /* Tacking on "\n\t#" to the section name makes gcc put it's bogus | 
|---|
| 208 | section attributes on what looks like a comment to the assembler.  */ | 
|---|
| 209 | #ifdef HAVE_SECTION_QUOTES | 
|---|
| 210 | # define __sec_comment "\"\n\t#\"" | 
|---|
| 211 | #else | 
|---|
| 212 | # define  "\n\t#" | 
|---|
| 213 | #endif | 
|---|
| 214 | #define link_warning(symbol, msg) \ | 
|---|
| 215 | __make_section_unallocated (".gnu.warning." #symbol) \ | 
|---|
| 216 | static const char __evoke_link_warning_##symbol[]	\ | 
|---|
| 217 | __attribute__ ((used, section (".gnu.warning." #symbol __sec_comment))) \ | 
|---|
| 218 | = msg; | 
|---|
| 219 | #define libc_freeres_ptr(decl) \ | 
|---|
| 220 | __make_section_unallocated ("__libc_freeres_ptrs, \"aw\", %nobits") \ | 
|---|
| 221 | decl __attribute__ ((section ("__libc_freeres_ptrs" __sec_comment))) | 
|---|
| 222 | #define __libc_freeres_fn_section \ | 
|---|
| 223 | __attribute__ ((section ("__libc_freeres_fn"))) | 
|---|
| 224 |  | 
|---|
| 225 | #define libc_freeres_fn(name)	\ | 
|---|
| 226 | static void name (void) __attribute_used__ __libc_freeres_fn_section;	\ | 
|---|
| 227 | text_set_element (__libc_subfreeres, name);				\ | 
|---|
| 228 | static void name (void) | 
|---|
| 229 |  | 
|---|
| 230 | /* A canned warning for sysdeps/stub functions.  */ | 
|---|
| 231 | #define	stub_warning(name) \ | 
|---|
| 232 | __make_section_unallocated (".gnu.glibc-stub." #name) \ | 
|---|
| 233 | link_warning (name, #name " is not implemented and will always fail") | 
|---|
| 234 |  | 
|---|
| 235 | /* Warning for linking functions calling dlopen into static binaries.  */ | 
|---|
| 236 | #ifdef SHARED | 
|---|
| 237 | #define static_link_warning(name) | 
|---|
| 238 | #else | 
|---|
| 239 | #define static_link_warning(name) static_link_warning1(name) | 
|---|
| 240 | #define static_link_warning1(name) \ | 
|---|
| 241 | link_warning(name, "Using '" #name "' in statically linked applications \ | 
|---|
| 242 | requires at runtime the shared libraries from the glibc version used \ | 
|---|
| 243 | for linking") | 
|---|
| 244 | #endif | 
|---|
| 245 |  | 
|---|
| 246 | /* Declare SYMBOL to be TYPE (`function' or `object') of SIZE bytes | 
|---|
| 247 | alias to ORIGINAL, when the assembler supports such declarations | 
|---|
| 248 | (such as in ELF). | 
|---|
| 249 | This is only necessary when defining something in assembly, or playing | 
|---|
| 250 | funny alias games where the size should be other than what the compiler | 
|---|
| 251 | thinks it is.  */ | 
|---|
| 252 | #define declare_symbol_alias(symbol, original, type, size) \ | 
|---|
| 253 | declare_symbol_alias_1 (symbol, original, type, size) | 
|---|
| 254 | #ifdef __ASSEMBLER__ | 
|---|
| 255 | # define declare_symbol_alias_1(symbol, original, type, size) \ | 
|---|
| 256 | strong_alias (original, symbol); \ | 
|---|
| 257 | .type C_SYMBOL_NAME (symbol), %##type; \ | 
|---|
| 258 | .size C_SYMBOL_NAME (symbol), size | 
|---|
| 259 | #else /* Not __ASSEMBLER__.  */ | 
|---|
| 260 | # define declare_symbol_alias_1(symbol, original, type, size) \ | 
|---|
| 261 | asm (".globl " __SYMBOL_PREFIX #symbol \ | 
|---|
| 262 | "\n\t" declare_symbol_alias_1_alias (symbol, original) \ | 
|---|
| 263 | "\n\t.type " __SYMBOL_PREFIX #symbol ", " \ | 
|---|
| 264 | "%" #type \ | 
|---|
| 265 | "\n\t.size " __SYMBOL_PREFIX #symbol ", " #size); | 
|---|
| 266 | # ifdef HAVE_ASM_SET_DIRECTIVE | 
|---|
| 267 | #  define declare_symbol_alias_1_alias(symbol, original) \ | 
|---|
| 268 | ".set " __SYMBOL_PREFIX #symbol ", " __SYMBOL_PREFIX #original | 
|---|
| 269 | # else | 
|---|
| 270 | #  define declare_symbol_alias_1_alias(symbol, original) \ | 
|---|
| 271 | __SYMBOL_PREFIX #symbol " = " __SYMBOL_PREFIX #original | 
|---|
| 272 | # endif /* HAVE_ASM_SET_DIRECTIVE */ | 
|---|
| 273 | #endif /* __ASSEMBLER__ */ | 
|---|
| 274 |  | 
|---|
| 275 |  | 
|---|
| 276 | /* | 
|---|
| 277 |  | 
|---|
| 278 | */ | 
|---|
| 279 |  | 
|---|
| 280 | /* Symbol set support macros.  */ | 
|---|
| 281 |  | 
|---|
| 282 | /* Make SYMBOL, which is in the text segment, an element of SET.  */ | 
|---|
| 283 | #define text_set_element(set, symbol)	_elf_set_element(set, symbol) | 
|---|
| 284 | /* Make SYMBOL, which is in the data segment, an element of SET.  */ | 
|---|
| 285 | #define data_set_element(set, symbol)	_elf_set_element(set, symbol) | 
|---|
| 286 | /* Make SYMBOL, which is in the bss segment, an element of SET.  */ | 
|---|
| 287 | #define bss_set_element(set, symbol)	_elf_set_element(set, symbol) | 
|---|
| 288 |  | 
|---|
| 289 | /* These are all done the same way in ELF. | 
|---|
| 290 | There is a new section created for each set.  */ | 
|---|
| 291 | #ifdef SHARED | 
|---|
| 292 | /* When building a shared library, make the set section writable, | 
|---|
| 293 | because it will need to be relocated at run time anyway.  */ | 
|---|
| 294 | # define _elf_set_element(set, symbol) \ | 
|---|
| 295 | static const void *__elf_set_##set##_element_##symbol##__ \ | 
|---|
| 296 | __attribute__ ((used, section (#set))) = &(symbol) | 
|---|
| 297 | #else | 
|---|
| 298 | # define _elf_set_element(set, symbol) \ | 
|---|
| 299 | static const void *const __elf_set_##set##_element_##symbol##__ \ | 
|---|
| 300 | __attribute__ ((used, section (#set))) = &(symbol) | 
|---|
| 301 | #endif | 
|---|
| 302 |  | 
|---|
| 303 | /* Define SET as a symbol set.  This may be required (it is in a.out) to | 
|---|
| 304 | be able to use the set's contents.  */ | 
|---|
| 305 | #define symbol_set_define(set)	symbol_set_declare(set) | 
|---|
| 306 |  | 
|---|
| 307 | /* Declare SET for use in this module, if defined in another module. | 
|---|
| 308 | In a shared library, this is always local to that shared object. | 
|---|
| 309 | For static linking, the set might be wholly absent and so we use | 
|---|
| 310 | weak references.  */ | 
|---|
| 311 | #define symbol_set_declare(set) \ | 
|---|
| 312 | extern char const __start_##set[] __symbol_set_attribute; \ | 
|---|
| 313 | extern char const __stop_##set[] __symbol_set_attribute; | 
|---|
| 314 | #ifdef SHARED | 
|---|
| 315 | # define __symbol_set_attribute attribute_hidden | 
|---|
| 316 | #else | 
|---|
| 317 | # define __symbol_set_attribute __attribute__ ((weak)) | 
|---|
| 318 | #endif | 
|---|
| 319 |  | 
|---|
| 320 | /* Return a pointer (void *const *) to the first element of SET.  */ | 
|---|
| 321 | #define symbol_set_first_element(set)	((void *const *) (&__start_##set)) | 
|---|
| 322 |  | 
|---|
| 323 | /* Return true iff PTR (a void *const *) has been incremented | 
|---|
| 324 | past the last element in SET.  */ | 
|---|
| 325 | #define symbol_set_end_p(set, ptr) ((ptr) >= (void *const *) &__stop_##set) | 
|---|
| 326 |  | 
|---|
| 327 | /* Use symbol_version_reference to specify the version a symbol | 
|---|
| 328 | reference should link to.  Use symbol_version or | 
|---|
| 329 | default_symbol_version for the definition of a versioned symbol. | 
|---|
| 330 | The difference is that the latter is a no-op in non-shared | 
|---|
| 331 | builds.  */ | 
|---|
| 332 | #ifdef __ASSEMBLER__ | 
|---|
| 333 | # define symbol_version_reference(real, name, version) \ | 
|---|
| 334 | .symver real, name##@##version | 
|---|
| 335 | #else  /* !__ASSEMBLER__ */ | 
|---|
| 336 | # define symbol_version_reference(real, name, version) \ | 
|---|
| 337 | __asm__ (".symver " #real "," #name "@" #version) | 
|---|
| 338 | #endif | 
|---|
| 339 |  | 
|---|
| 340 | #ifdef SHARED | 
|---|
| 341 | # define symbol_version(real, name, version) \ | 
|---|
| 342 | symbol_version_reference(real, name, version) | 
|---|
| 343 | # define default_symbol_version(real, name, version) \ | 
|---|
| 344 | _default_symbol_version(real, name, version) | 
|---|
| 345 | # ifdef __ASSEMBLER__ | 
|---|
| 346 | #  define _default_symbol_version(real, name, version) \ | 
|---|
| 347 | .symver real, name##@##@##version | 
|---|
| 348 | # else | 
|---|
| 349 | #  define _default_symbol_version(real, name, version) \ | 
|---|
| 350 | __asm__ (".symver " #real "," #name "@@" #version) | 
|---|
| 351 | # endif | 
|---|
| 352 | #else | 
|---|
| 353 | # define symbol_version(real, name, version) | 
|---|
| 354 | # define default_symbol_version(real, name, version) \ | 
|---|
| 355 | strong_alias(real, name) | 
|---|
| 356 | #endif | 
|---|
| 357 |  | 
|---|
| 358 | #if defined SHARED || defined LIBC_NONSHARED | 
|---|
| 359 | # define attribute_hidden __attribute__ ((visibility ("hidden"))) | 
|---|
| 360 | #else | 
|---|
| 361 | # define attribute_hidden | 
|---|
| 362 | #endif | 
|---|
| 363 |  | 
|---|
| 364 | #define attribute_tls_model_ie __attribute__ ((tls_model ("initial-exec"))) | 
|---|
| 365 |  | 
|---|
| 366 | #define attribute_relro __attribute__ ((section (".data.rel.ro"))) | 
|---|
| 367 |  | 
|---|
| 368 |  | 
|---|
| 369 | /* Used to disable stack protection in sensitive places, like ifunc | 
|---|
| 370 | resolvers and early static TLS init.  */ | 
|---|
| 371 | #ifdef HAVE_CC_NO_STACK_PROTECTOR | 
|---|
| 372 | # define inhibit_stack_protector \ | 
|---|
| 373 | __attribute__ ((__optimize__ ("-fno-stack-protector"))) | 
|---|
| 374 | #else | 
|---|
| 375 | # define inhibit_stack_protector | 
|---|
| 376 | #endif | 
|---|
| 377 |  | 
|---|
| 378 | /* The following macros are used for PLT bypassing within libc.so | 
|---|
| 379 | (and if needed other libraries similarly). | 
|---|
| 380 | First of all, you need to have the function prototyped somewhere, | 
|---|
| 381 | say in foo/foo.h: | 
|---|
| 382 |  | 
|---|
| 383 | int foo (int __bar); | 
|---|
| 384 |  | 
|---|
| 385 | If calls to foo within libc.so should always go to foo defined in libc.so, | 
|---|
| 386 | then in include/foo.h you add: | 
|---|
| 387 |  | 
|---|
| 388 | libc_hidden_proto (foo) | 
|---|
| 389 |  | 
|---|
| 390 | line and after the foo function definition: | 
|---|
| 391 |  | 
|---|
| 392 | int foo (int __bar) | 
|---|
| 393 | { | 
|---|
| 394 | return __bar; | 
|---|
| 395 | } | 
|---|
| 396 | libc_hidden_def (foo) | 
|---|
| 397 |  | 
|---|
| 398 | or | 
|---|
| 399 |  | 
|---|
| 400 | int foo (int __bar) | 
|---|
| 401 | { | 
|---|
| 402 | return __bar; | 
|---|
| 403 | } | 
|---|
| 404 | libc_hidden_weak (foo) | 
|---|
| 405 |  | 
|---|
| 406 | Similarly for global data.  If references to foo within libc.so should | 
|---|
| 407 | always go to foo defined in libc.so, then in include/foo.h you add: | 
|---|
| 408 |  | 
|---|
| 409 | libc_hidden_proto (foo) | 
|---|
| 410 |  | 
|---|
| 411 | line and after foo's definition: | 
|---|
| 412 |  | 
|---|
| 413 | int foo = INITIAL_FOO_VALUE; | 
|---|
| 414 | libc_hidden_data_def (foo) | 
|---|
| 415 |  | 
|---|
| 416 | or | 
|---|
| 417 |  | 
|---|
| 418 | int foo = INITIAL_FOO_VALUE; | 
|---|
| 419 | libc_hidden_data_weak (foo) | 
|---|
| 420 |  | 
|---|
| 421 | If foo is normally just an alias (strong or weak) to some other function, | 
|---|
| 422 | you should use the normal strong_alias first, then add libc_hidden_def | 
|---|
| 423 | or libc_hidden_weak: | 
|---|
| 424 |  | 
|---|
| 425 | int baz (int __bar) | 
|---|
| 426 | { | 
|---|
| 427 | return __bar; | 
|---|
| 428 | } | 
|---|
| 429 | strong_alias (baz, foo) | 
|---|
| 430 | libc_hidden_weak (foo) | 
|---|
| 431 |  | 
|---|
| 432 | If the function should be internal to multiple objects, say ld.so and | 
|---|
| 433 | libc.so, the best way is to use: | 
|---|
| 434 |  | 
|---|
| 435 | #if IS_IN (libc) || IS_IN (rtld) | 
|---|
| 436 | hidden_proto (foo) | 
|---|
| 437 | #endif | 
|---|
| 438 |  | 
|---|
| 439 | in include/foo.h and the normal macros at all function definitions | 
|---|
| 440 | depending on what DSO they belong to. | 
|---|
| 441 |  | 
|---|
| 442 | If versioned_symbol macro is used to define foo, | 
|---|
| 443 | libc_hidden_ver macro should be used, as in: | 
|---|
| 444 |  | 
|---|
| 445 | int __real_foo (int __bar) | 
|---|
| 446 | { | 
|---|
| 447 | return __bar; | 
|---|
| 448 | } | 
|---|
| 449 | versioned_symbol (libc, __real_foo, foo, GLIBC_2_1); | 
|---|
| 450 | libc_hidden_ver (__real_foo, foo)  */ | 
|---|
| 451 |  | 
|---|
| 452 | #if defined SHARED && !defined NO_HIDDEN | 
|---|
| 453 | # ifndef __ASSEMBLER__ | 
|---|
| 454 | #  define __hidden_proto_hiddenattr(attrs...) \ | 
|---|
| 455 | __attribute__ ((visibility ("hidden"), ##attrs)) | 
|---|
| 456 | #  define hidden_proto(name, attrs...) \ | 
|---|
| 457 | __hidden_proto (name, , __GI_##name, ##attrs) | 
|---|
| 458 | #  define hidden_tls_proto(name, attrs...) \ | 
|---|
| 459 | __hidden_proto (name, __thread, __GI_##name, ##attrs) | 
|---|
| 460 | #  define __hidden_proto(name, thread, internal, attrs...)	     \ | 
|---|
| 461 | extern thread __typeof (name) name __asm__ (__hidden_asmname (#internal)) \ | 
|---|
| 462 | __hidden_proto_hiddenattr (attrs); | 
|---|
| 463 | #  define __hidden_asmname(name) \ | 
|---|
| 464 | __hidden_asmname1 (__USER_LABEL_PREFIX__, name) | 
|---|
| 465 | #  define __hidden_asmname1(prefix, name) __hidden_asmname2(prefix, name) | 
|---|
| 466 | #  define __hidden_asmname2(prefix, name) #prefix name | 
|---|
| 467 | #  define __hidden_ver1(local, internal, name) \ | 
|---|
| 468 | extern __typeof (name) __EI_##name __asm__(__hidden_asmname (#internal)); \ | 
|---|
| 469 | extern __typeof (name) __EI_##name \ | 
|---|
| 470 | __attribute__((alias (__hidden_asmname (#local)))) | 
|---|
| 471 | #  define hidden_ver(local, name)	__hidden_ver1(local, __GI_##name, name); | 
|---|
| 472 | #  define hidden_data_ver(local, name)	hidden_ver(local, name) | 
|---|
| 473 | #  define hidden_def(name)		__hidden_ver1(__GI_##name, name, name); | 
|---|
| 474 | #  define hidden_data_def(name)		hidden_def(name) | 
|---|
| 475 | #  define hidden_weak(name) \ | 
|---|
| 476 | __hidden_ver1(__GI_##name, name, name) __attribute__((weak)); | 
|---|
| 477 | #  define hidden_data_weak(name)	hidden_weak(name) | 
|---|
| 478 | #  define hidden_nolink(name, lib, version) \ | 
|---|
| 479 | __hidden_nolink1 (__GI_##name, __EI_##name, name, VERSION_##lib##_##version) | 
|---|
| 480 | #  define __hidden_nolink1(local, internal, name, version) \ | 
|---|
| 481 | __hidden_nolink2 (local, internal, name, version) | 
|---|
| 482 | #  define __hidden_nolink2(local, internal, name, version) \ | 
|---|
| 483 | extern __typeof (name) internal __attribute__ ((alias (#local))); \ | 
|---|
| 484 | __hidden_nolink3 (local, internal, #name "@" #version) | 
|---|
| 485 | #  define __hidden_nolink3(local, internal, vername) \ | 
|---|
| 486 | __asm__ (".symver " #internal ", " vername); | 
|---|
| 487 | # else | 
|---|
| 488 | /* For assembly, we need to do the opposite of what we do in C: | 
|---|
| 489 | in assembly gcc __REDIRECT stuff is not in place, so functions | 
|---|
| 490 | are defined by its normal name and we need to create the | 
|---|
| 491 | __GI_* alias to it, in C __REDIRECT causes the function definition | 
|---|
| 492 | to use __GI_* name and we need to add alias to the real name. | 
|---|
| 493 | There is no reason to use hidden_weak over hidden_def in assembly, | 
|---|
| 494 | but we provide it for consistency with the C usage. | 
|---|
| 495 | hidden_proto doesn't make sense for assembly but the equivalent | 
|---|
| 496 | is to call via the HIDDEN_JUMPTARGET macro instead of JUMPTARGET.  */ | 
|---|
| 497 | #  define hidden_def(name)	strong_alias (name, __GI_##name) | 
|---|
| 498 | #  define hidden_weak(name)	hidden_def (name) | 
|---|
| 499 | #  define hidden_ver(local, name) strong_alias (local, __GI_##name) | 
|---|
| 500 | #  define hidden_data_def(name)	strong_data_alias (name, __GI_##name) | 
|---|
| 501 | #  define hidden_data_weak(name)	hidden_data_def (name) | 
|---|
| 502 | #  define hidden_data_ver(local, name) strong_data_alias (local, __GI_##name) | 
|---|
| 503 | #  define HIDDEN_JUMPTARGET(name) __GI_##name | 
|---|
| 504 | # endif | 
|---|
| 505 | #else | 
|---|
| 506 | # ifndef __ASSEMBLER__ | 
|---|
| 507 | #  define hidden_proto(name, attrs...) | 
|---|
| 508 | #  define hidden_tls_proto(name, attrs...) | 
|---|
| 509 | # else | 
|---|
| 510 | #  define HIDDEN_JUMPTARGET(name) JUMPTARGET(name) | 
|---|
| 511 | # endif /* Not  __ASSEMBLER__ */ | 
|---|
| 512 | # define hidden_weak(name) | 
|---|
| 513 | # define hidden_def(name) | 
|---|
| 514 | # define hidden_ver(local, name) | 
|---|
| 515 | # define hidden_data_weak(name) | 
|---|
| 516 | # define hidden_data_def(name) | 
|---|
| 517 | # define hidden_data_ver(local, name) | 
|---|
| 518 | # define hidden_nolink(name, lib, version) | 
|---|
| 519 | #endif | 
|---|
| 520 |  | 
|---|
| 521 | #if IS_IN (libc) | 
|---|
| 522 | # define libc_hidden_proto(name, attrs...) hidden_proto (name, ##attrs) | 
|---|
| 523 | # define libc_hidden_tls_proto(name, attrs...) hidden_tls_proto (name, ##attrs) | 
|---|
| 524 | # define libc_hidden_def(name) hidden_def (name) | 
|---|
| 525 | # define libc_hidden_weak(name) hidden_weak (name) | 
|---|
| 526 | # ifdef LINK_OBSOLETE_RPC | 
|---|
| 527 | /* libc_hidden_nolink_sunrpc should only get used in sunrpc code.  */ | 
|---|
| 528 | #  define libc_hidden_nolink_sunrpc(name, version) hidden_def (name) | 
|---|
| 529 | # else | 
|---|
| 530 | #  define libc_hidden_nolink_sunrpc(name, version) hidden_nolink (name, libc, version) | 
|---|
| 531 | # endif | 
|---|
| 532 | # define libc_hidden_ver(local, name) hidden_ver (local, name) | 
|---|
| 533 | # define libc_hidden_data_def(name) hidden_data_def (name) | 
|---|
| 534 | # define libc_hidden_data_weak(name) hidden_data_weak (name) | 
|---|
| 535 | # define libc_hidden_data_ver(local, name) hidden_data_ver (local, name) | 
|---|
| 536 | #else | 
|---|
| 537 | # define libc_hidden_proto(name, attrs...) | 
|---|
| 538 | # define libc_hidden_tls_proto(name, attrs...) | 
|---|
| 539 | # define libc_hidden_def(name) | 
|---|
| 540 | # define libc_hidden_weak(name) | 
|---|
| 541 | # define libc_hidden_ver(local, name) | 
|---|
| 542 | # define libc_hidden_data_def(name) | 
|---|
| 543 | # define libc_hidden_data_weak(name) | 
|---|
| 544 | # define libc_hidden_data_ver(local, name) | 
|---|
| 545 | #endif | 
|---|
| 546 |  | 
|---|
| 547 | #if IS_IN (rtld) | 
|---|
| 548 | # define rtld_hidden_proto(name, attrs...) hidden_proto (name, ##attrs) | 
|---|
| 549 | # define rtld_hidden_tls_proto(name, attrs...) hidden_tls_proto (name, ##attrs) | 
|---|
| 550 | # define rtld_hidden_def(name) hidden_def (name) | 
|---|
| 551 | # define rtld_hidden_weak(name) hidden_weak (name) | 
|---|
| 552 | # define rtld_hidden_ver(local, name) hidden_ver (local, name) | 
|---|
| 553 | # define rtld_hidden_data_def(name) hidden_data_def (name) | 
|---|
| 554 | # define rtld_hidden_data_weak(name) hidden_data_weak (name) | 
|---|
| 555 | # define rtld_hidden_data_ver(local, name) hidden_data_ver (local, name) | 
|---|
| 556 | #else | 
|---|
| 557 | # define rtld_hidden_proto(name, attrs...) | 
|---|
| 558 | # define rtld_hidden_tls_proto(name, attrs...) | 
|---|
| 559 | # define rtld_hidden_def(name) | 
|---|
| 560 | # define rtld_hidden_weak(name) | 
|---|
| 561 | # define rtld_hidden_ver(local, name) | 
|---|
| 562 | # define rtld_hidden_data_def(name) | 
|---|
| 563 | # define rtld_hidden_data_weak(name) | 
|---|
| 564 | # define rtld_hidden_data_ver(local, name) | 
|---|
| 565 | #endif | 
|---|
| 566 |  | 
|---|
| 567 | #if IS_IN (libm) | 
|---|
| 568 | # define libm_hidden_proto(name, attrs...) hidden_proto (name, ##attrs) | 
|---|
| 569 | # define libm_hidden_tls_proto(name, attrs...) hidden_tls_proto (name, ##attrs) | 
|---|
| 570 | # define libm_hidden_def(name) hidden_def (name) | 
|---|
| 571 | # define libm_hidden_weak(name) hidden_weak (name) | 
|---|
| 572 | # define libm_hidden_ver(local, name) hidden_ver (local, name) | 
|---|
| 573 | # define libm_hidden_data_def(name) hidden_data_def (name) | 
|---|
| 574 | # define libm_hidden_data_weak(name) hidden_data_weak (name) | 
|---|
| 575 | # define libm_hidden_data_ver(local, name) hidden_data_ver (local, name) | 
|---|
| 576 | #else | 
|---|
| 577 | # define libm_hidden_proto(name, attrs...) | 
|---|
| 578 | # define libm_hidden_tls_proto(name, attrs...) | 
|---|
| 579 | # define libm_hidden_def(name) | 
|---|
| 580 | # define libm_hidden_weak(name) | 
|---|
| 581 | # define libm_hidden_ver(local, name) | 
|---|
| 582 | # define libm_hidden_data_def(name) | 
|---|
| 583 | # define libm_hidden_data_weak(name) | 
|---|
| 584 | # define libm_hidden_data_ver(local, name) | 
|---|
| 585 | #endif | 
|---|
| 586 |  | 
|---|
| 587 | #if IS_IN (libmvec) | 
|---|
| 588 | # define libmvec_hidden_proto(name, attrs...) hidden_proto (name, ##attrs) | 
|---|
| 589 | # define libmvec_hidden_tls_proto(name, attrs...) hidden_tls_proto (name, ##attrs) | 
|---|
| 590 | # define libmvec_hidden_def(name) hidden_def (name) | 
|---|
| 591 | # define libmvec_hidden_weak(name) hidden_weak (name) | 
|---|
| 592 | # define libmvec_hidden_ver(local, name) hidden_ver (local, name) | 
|---|
| 593 | # define libmvec_hidden_data_def(name) hidden_data_def (name) | 
|---|
| 594 | # define libmvec_hidden_data_weak(name) hidden_data_weak (name) | 
|---|
| 595 | # define libmvec_hidden_data_ver(local, name) hidden_data_ver (local, name) | 
|---|
| 596 | #else | 
|---|
| 597 | # define libmvec_hidden_proto(name, attrs...) | 
|---|
| 598 | # define libmvec_hidden_tls_proto(name, attrs...) | 
|---|
| 599 | # define libmvec_hidden_def(name) | 
|---|
| 600 | # define libmvec_hidden_weak(name) | 
|---|
| 601 | # define libmvec_hidden_ver(local, name) | 
|---|
| 602 | # define libmvec_hidden_data_def(name) | 
|---|
| 603 | # define libmvec_hidden_data_weak(name) | 
|---|
| 604 | # define libmvec_hidden_data_ver(local, name) | 
|---|
| 605 | #endif | 
|---|
| 606 |  | 
|---|
| 607 | #if IS_IN (libresolv) | 
|---|
| 608 | # define libresolv_hidden_proto(name, attrs...) hidden_proto (name, ##attrs) | 
|---|
| 609 | # define libresolv_hidden_tls_proto(name, attrs...) \ | 
|---|
| 610 | hidden_tls_proto (name, ##attrs) | 
|---|
| 611 | # define libresolv_hidden_def(name) hidden_def (name) | 
|---|
| 612 | # define libresolv_hidden_weak(name) hidden_weak (name) | 
|---|
| 613 | # define libresolv_hidden_ver(local, name) hidden_ver (local, name) | 
|---|
| 614 | # define libresolv_hidden_data_def(name) hidden_data_def (name) | 
|---|
| 615 | # define libresolv_hidden_data_weak(name) hidden_data_weak (name) | 
|---|
| 616 | # define libresolv_hidden_data_ver(local, name) hidden_data_ver (local, name) | 
|---|
| 617 | #else | 
|---|
| 618 | # define libresolv_hidden_proto(name, attrs...) | 
|---|
| 619 | # define libresolv_hidden_tls_proto(name, attrs...) | 
|---|
| 620 | # define libresolv_hidden_def(name) | 
|---|
| 621 | # define libresolv_hidden_weak(name) | 
|---|
| 622 | # define libresolv_hidden_ver(local, name) | 
|---|
| 623 | # define libresolv_hidden_data_def(name) | 
|---|
| 624 | # define libresolv_hidden_data_weak(name) | 
|---|
| 625 | # define libresolv_hidden_data_ver(local, name) | 
|---|
| 626 | #endif | 
|---|
| 627 |  | 
|---|
| 628 | #if IS_IN (librt) | 
|---|
| 629 | # define librt_hidden_proto(name, attrs...) hidden_proto (name, ##attrs) | 
|---|
| 630 | # define librt_hidden_tls_proto(name, attrs...) \ | 
|---|
| 631 | hidden_tls_proto (name, ##attrs) | 
|---|
| 632 | # define librt_hidden_def(name) hidden_def (name) | 
|---|
| 633 | # define librt_hidden_weak(name) hidden_weak (name) | 
|---|
| 634 | # define librt_hidden_ver(local, name) hidden_ver (local, name) | 
|---|
| 635 | # define librt_hidden_data_def(name) hidden_data_def (name) | 
|---|
| 636 | # define librt_hidden_data_weak(name) hidden_data_weak (name) | 
|---|
| 637 | # define librt_hidden_data_ver(local, name) hidden_data_ver (local, name) | 
|---|
| 638 | #else | 
|---|
| 639 | # define librt_hidden_proto(name, attrs...) | 
|---|
| 640 | # define librt_hidden_tls_proto(name, attrs...) | 
|---|
| 641 | # define librt_hidden_def(name) | 
|---|
| 642 | # define librt_hidden_weak(name) | 
|---|
| 643 | # define librt_hidden_ver(local, name) | 
|---|
| 644 | # define librt_hidden_data_def(name) | 
|---|
| 645 | # define librt_hidden_data_weak(name) | 
|---|
| 646 | # define librt_hidden_data_ver(local, name) | 
|---|
| 647 | #endif | 
|---|
| 648 |  | 
|---|
| 649 | #if IS_IN (libdl) | 
|---|
| 650 | # define libdl_hidden_proto(name, attrs...) hidden_proto (name, ##attrs) | 
|---|
| 651 | # define libdl_hidden_tls_proto(name, attrs...) \ | 
|---|
| 652 | hidden_tls_proto (name, ##attrs) | 
|---|
| 653 | # define libdl_hidden_def(name) hidden_def (name) | 
|---|
| 654 | # define libdl_hidden_weak(name) hidden_weak (name) | 
|---|
| 655 | # define libdl_hidden_ver(local, name) hidden_ver (local, name) | 
|---|
| 656 | # define libdl_hidden_data_def(name) hidden_data_def (name) | 
|---|
| 657 | # define libdl_hidden_data_weak(name) hidden_data_weak (name) | 
|---|
| 658 | # define libdl_hidden_data_ver(local, name) hidden_data_ver (local, name) | 
|---|
| 659 | #else | 
|---|
| 660 | # define libdl_hidden_proto(name, attrs...) | 
|---|
| 661 | # define libdl_hidden_tls_proto(name, attrs...) | 
|---|
| 662 | # define libdl_hidden_def(name) | 
|---|
| 663 | # define libdl_hidden_weak(name) | 
|---|
| 664 | # define libdl_hidden_ver(local, name) | 
|---|
| 665 | # define libdl_hidden_data_def(name) | 
|---|
| 666 | # define libdl_hidden_data_weak(name) | 
|---|
| 667 | # define libdl_hidden_data_ver(local, name) | 
|---|
| 668 | #endif | 
|---|
| 669 |  | 
|---|
| 670 | #if IS_IN (libnss_files) | 
|---|
| 671 | # define libnss_files_hidden_proto(name, attrs...) hidden_proto (name, ##attrs) | 
|---|
| 672 | # define libnss_files_hidden_tls_proto(name, attrs...) \ | 
|---|
| 673 | hidden_tls_proto (name, ##attrs) | 
|---|
| 674 | # define libnss_files_hidden_def(name) hidden_def (name) | 
|---|
| 675 | # define libnss_files_hidden_weak(name) hidden_weak (name) | 
|---|
| 676 | # define libnss_files_hidden_ver(local, name) hidden_ver (local, name) | 
|---|
| 677 | # define libnss_files_hidden_data_def(name) hidden_data_def (name) | 
|---|
| 678 | # define libnss_files_hidden_data_weak(name) hidden_data_weak (name) | 
|---|
| 679 | # define libnss_files_hidden_data_ver(local, name) hidden_data_ver(local, name) | 
|---|
| 680 | #else | 
|---|
| 681 | # define libnss_files_hidden_proto(name, attrs...) | 
|---|
| 682 | # define libnss_files_hidden_tls_proto(name, attrs...) | 
|---|
| 683 | # define libnss_files_hidden_def(name) | 
|---|
| 684 | # define libnss_files_hidden_weak(name) | 
|---|
| 685 | # define libnss_files_hidden_ver(local, name) | 
|---|
| 686 | # define libnss_files_hidden_data_def(name) | 
|---|
| 687 | # define libnss_files_hidden_data_weak(name) | 
|---|
| 688 | # define libnss_files_hidden_data_ver(local, name) | 
|---|
| 689 | #endif | 
|---|
| 690 |  | 
|---|
| 691 | #if IS_IN (libnsl) | 
|---|
| 692 | # define libnsl_hidden_proto(name, attrs...) hidden_proto (name, ##attrs) | 
|---|
| 693 | # define libnsl_hidden_tls_proto(name, attrs...) \ | 
|---|
| 694 | hidden_tls_proto (name, ##attrs) | 
|---|
| 695 | # ifdef LINK_OBSOLETE_NSL | 
|---|
| 696 | /* libnsl_hidden_nolink should only get used in libnsl code.  */ | 
|---|
| 697 | #  define libnsl_hidden_nolink_def(name, version) libnsl_hidden_def (name) | 
|---|
| 698 | # else | 
|---|
| 699 | #  define libnsl_hidden_nolink_def(name, version) hidden_nolink (name, libnsl, version) | 
|---|
| 700 | # endif | 
|---|
| 701 | # define libnsl_hidden_def(name) hidden_def (name) | 
|---|
| 702 | # define libnsl_hidden_weak(name) hidden_weak (name) | 
|---|
| 703 | # define libnsl_hidden_ver(local, name) hidden_ver (local, name) | 
|---|
| 704 | # define libnsl_hidden_data_def(name) hidden_data_def (name) | 
|---|
| 705 | # define libnsl_hidden_data_weak(name) hidden_data_weak (name) | 
|---|
| 706 | # define libnsl_hidden_data_ver(local, name) hidden_data_ver (local, name) | 
|---|
| 707 | #else | 
|---|
| 708 | # define libnsl_hidden_proto(name, attrs...) | 
|---|
| 709 | # define libnsl_hidden_tls_proto(name, attrs...) | 
|---|
| 710 | # define libnsl_hidden_def(name) | 
|---|
| 711 | # define libnsl_hidden_weak(name) | 
|---|
| 712 | # define libnsl_hidden_ver(local, name) | 
|---|
| 713 | # define libnsl_hidden_data_def(name) | 
|---|
| 714 | # define libnsl_hidden_data_weak(name) | 
|---|
| 715 | # define libnsl_hidden_data_ver(local, name) | 
|---|
| 716 | #endif | 
|---|
| 717 |  | 
|---|
| 718 | #if IS_IN (libnss_nisplus) | 
|---|
| 719 | # define libnss_nisplus_hidden_proto(name, attrs...) hidden_proto (name, ##attrs) | 
|---|
| 720 | # define libnss_nisplus_hidden_tls_proto(name, attrs...) \ | 
|---|
| 721 | hidden_tls_proto (name, ##attrs) | 
|---|
| 722 | # define libnss_nisplus_hidden_def(name) hidden_def (name) | 
|---|
| 723 | # define libnss_nisplus_hidden_weak(name) hidden_weak (name) | 
|---|
| 724 | # define libnss_nisplus_hidden_ver(local, name) hidden_ver (local, name) | 
|---|
| 725 | # define libnss_nisplus_hidden_data_def(name) hidden_data_def (name) | 
|---|
| 726 | # define libnss_nisplus_hidden_data_weak(name) hidden_data_weak (name) | 
|---|
| 727 | # define libnss_nisplus_hidden_data_ver(local, name) hidden_data_ver (local, name) | 
|---|
| 728 | #else | 
|---|
| 729 | # define libnss_nisplus_hidden_proto(name, attrs...) | 
|---|
| 730 | # define libnss_nisplus_hidden_tls_proto(name, attrs...) | 
|---|
| 731 | # define libnss_nisplus_hidden_def(name) | 
|---|
| 732 | # define libnss_nisplus_hidden_weak(name) | 
|---|
| 733 | # define libnss_nisplus_hidden_ver(local, name) | 
|---|
| 734 | # define libnss_nisplus_hidden_data_def(name) | 
|---|
| 735 | # define libnss_nisplus_hidden_data_weak(name) | 
|---|
| 736 | # define libnss_nisplus_hidden_data_ver(local, name) | 
|---|
| 737 | #endif | 
|---|
| 738 |  | 
|---|
| 739 | #define libc_hidden_builtin_proto(name, attrs...) libc_hidden_proto (name, ##attrs) | 
|---|
| 740 | #define libc_hidden_builtin_def(name) libc_hidden_def (name) | 
|---|
| 741 | #define libc_hidden_builtin_weak(name) libc_hidden_weak (name) | 
|---|
| 742 | #define libc_hidden_builtin_ver(local, name) libc_hidden_ver (local, name) | 
|---|
| 743 | #ifdef __ASSEMBLER__ | 
|---|
| 744 | # define HIDDEN_BUILTIN_JUMPTARGET(name) HIDDEN_JUMPTARGET(name) | 
|---|
| 745 | #endif | 
|---|
| 746 |  | 
|---|
| 747 | #if IS_IN (libutil) | 
|---|
| 748 | # define libutil_hidden_proto(name, attrs...) hidden_proto (name, ##attrs) | 
|---|
| 749 | # define libutil_hidden_tls_proto(name, attrs...) \ | 
|---|
| 750 | hidden_tls_proto (name, ##attrs) | 
|---|
| 751 | # define libutil_hidden_def(name) hidden_def (name) | 
|---|
| 752 | # define libutil_hidden_weak(name) hidden_weak (name) | 
|---|
| 753 | # define libutil_hidden_ver(local, name) hidden_ver (local, name) | 
|---|
| 754 | # define libutil_hidden_data_def(name) hidden_data_def (name) | 
|---|
| 755 | # define libutil_hidden_data_weak(name) hidden_data_weak (name) | 
|---|
| 756 | # define libutil_hidden_data_ver(local, name) hidden_data_ver (local, name) | 
|---|
| 757 | #else | 
|---|
| 758 | # define libutil_hidden_proto(name, attrs...) | 
|---|
| 759 | # define libutil_hidden_tls_proto(name, attrs...) | 
|---|
| 760 | # define libutil_hidden_def(name) | 
|---|
| 761 | # define libutil_hidden_weak(name) | 
|---|
| 762 | # define libutil_hidden_ver(local, name) | 
|---|
| 763 | # define libutil_hidden_data_def(name) | 
|---|
| 764 | # define libutil_hidden_data_weak(name) | 
|---|
| 765 | # define libutil_hidden_data_ver(local, name) | 
|---|
| 766 | #endif | 
|---|
| 767 |  | 
|---|
| 768 | /* Get some dirty hacks.  */ | 
|---|
| 769 | #include <symbol-hacks.h> | 
|---|
| 770 |  | 
|---|
| 771 | /* Move compatibility symbols out of the way by placing them all in a | 
|---|
| 772 | special section.  */ | 
|---|
| 773 | #ifndef __ASSEMBLER__ | 
|---|
| 774 | # define attribute_compat_text_section \ | 
|---|
| 775 | __attribute__ ((section (".text.compat"))) | 
|---|
| 776 | # define attribute_compat_data_section \ | 
|---|
| 777 | __attribute__ ((section (".data.compat"))) | 
|---|
| 778 | #else | 
|---|
| 779 | # define compat_text_section .section ".text.compat", "ax"; | 
|---|
| 780 | # define compat_data_section .section ".data.compat", "aw"; | 
|---|
| 781 | #endif | 
|---|
| 782 |  | 
|---|
| 783 | /* Helper / base  macros for indirect function symbols.  */ | 
|---|
| 784 | #define __ifunc_resolver(type_name, name, expr, arg, init, classifier)	\ | 
|---|
| 785 | classifier inhibit_stack_protector void *name##_ifunc (arg)					\ | 
|---|
| 786 | {									\ | 
|---|
| 787 | init ();								\ | 
|---|
| 788 | __typeof (type_name) *res = expr;					\ | 
|---|
| 789 | return res;								\ | 
|---|
| 790 | } | 
|---|
| 791 |  | 
|---|
| 792 | #ifdef HAVE_GCC_IFUNC | 
|---|
| 793 | # define __ifunc(type_name, name, expr, arg, init)			\ | 
|---|
| 794 | extern __typeof (type_name) name __attribute__			\ | 
|---|
| 795 | ((ifunc (#name "_ifunc")));		\ | 
|---|
| 796 | __ifunc_resolver (type_name, name, expr, arg, init, static) | 
|---|
| 797 |  | 
|---|
| 798 | # define __ifunc_hidden(type_name, name, expr, arg, init)	\ | 
|---|
| 799 | __ifunc (type_name, name, expr, arg, init) | 
|---|
| 800 | #else | 
|---|
| 801 | /* Gcc does not support __attribute__ ((ifunc (...))).  Use the old behaviour | 
|---|
| 802 | as fallback.  But keep in mind that the debug information for the ifunc | 
|---|
| 803 | resolver functions is not correct.  It contains the ifunc'ed function as | 
|---|
| 804 | DW_AT_linkage_name.  E.g. lldb uses this field and an inferior function | 
|---|
| 805 | call of the ifunc'ed function will fail due to "no matching function for | 
|---|
| 806 | call to ..." because the ifunc'ed function and the resolver function have | 
|---|
| 807 | different signatures.  (Gcc support is disabled at least on a ppc64le | 
|---|
| 808 | Ubuntu 14.04 system.)  */ | 
|---|
| 809 |  | 
|---|
| 810 | # define __ifunc(type_name, name, expr, arg, init)			\ | 
|---|
| 811 | extern __typeof (type_name) name;					\ | 
|---|
| 812 | void *name##_ifunc (arg) __asm__ (#name);				\ | 
|---|
| 813 | __ifunc_resolver (type_name, name, expr, arg, init,)			\ | 
|---|
| 814 | __asm__ (".type " #name ", %gnu_indirect_function"); | 
|---|
| 815 |  | 
|---|
| 816 | # define __ifunc_hidden(type_name, name, expr, arg, init)		\ | 
|---|
| 817 | extern __typeof (type_name) __libc_##name;				\ | 
|---|
| 818 | __ifunc (type_name, __libc_##name, expr, arg, init)			\ | 
|---|
| 819 | strong_alias (__libc_##name, name); | 
|---|
| 820 | #endif /* !HAVE_GCC_IFUNC  */ | 
|---|
| 821 |  | 
|---|
| 822 | /* The following macros are used for indirect function symbols in libc.so. | 
|---|
| 823 | First of all, you need to have the function prototyped somewhere, | 
|---|
| 824 | say in foo.h: | 
|---|
| 825 |  | 
|---|
| 826 | int foo (int __bar); | 
|---|
| 827 |  | 
|---|
| 828 | If you have an implementation for foo which e.g. uses a special hardware | 
|---|
| 829 | feature which isn't available on all machines where this libc.so will be | 
|---|
| 830 | used but decideable if available at runtime e.g. via hwcaps, you can provide | 
|---|
| 831 | two or multiple implementations of foo: | 
|---|
| 832 |  | 
|---|
| 833 | int __foo_default (int __bar) | 
|---|
| 834 | { | 
|---|
| 835 | return __bar; | 
|---|
| 836 | } | 
|---|
| 837 |  | 
|---|
| 838 | int __foo_special (int __bar) | 
|---|
| 839 | { | 
|---|
| 840 | return __bar; | 
|---|
| 841 | } | 
|---|
| 842 |  | 
|---|
| 843 | If your function foo has no libc_hidden_proto (foo) defined for PLT | 
|---|
| 844 | bypassing, you can use: | 
|---|
| 845 |  | 
|---|
| 846 | #define INIT_ARCH() unsigned long int hwcap = __GLRO(dl_hwcap); | 
|---|
| 847 |  | 
|---|
| 848 | libc_ifunc (foo, (hwcap & HWCAP_SPECIAL) ? __foo_special : __foo_default); | 
|---|
| 849 |  | 
|---|
| 850 | This will define a resolver function for foo which returns __foo_special or | 
|---|
| 851 | __foo_default depending on your specified expression.  Please note that you | 
|---|
| 852 | have to define a macro function INIT_ARCH before using libc_ifunc macro as | 
|---|
| 853 | it is called by the resolver function before evaluating the specified | 
|---|
| 854 | expression.  In this example it is used to prepare the hwcap variable. | 
|---|
| 855 | The resolver function is assigned to an ifunc'ed symbol foo.  Calls to foo | 
|---|
| 856 | from inside or outside of libc.so will be indirected by a PLT call. | 
|---|
| 857 |  | 
|---|
| 858 | If your function foo has a libc_hidden_proto (foo) defined for PLT bypassing | 
|---|
| 859 | and calls to foo within libc.so should always go to one specific | 
|---|
| 860 | implementation of foo e.g. __foo_default then you have to add: | 
|---|
| 861 |  | 
|---|
| 862 | __hidden_ver1 (__foo_default, __GI_foo, __foo_default); | 
|---|
| 863 |  | 
|---|
| 864 | or a tweaked definition of libc_hidden_def macro after the __foo_default | 
|---|
| 865 | function definition.  Calls to foo within libc.so will always go directly to | 
|---|
| 866 | __foo_default.  Calls to foo from outside libc.so will be indirected by a | 
|---|
| 867 | PLT call to ifunc'ed symbol foo which you have to define in a separate | 
|---|
| 868 | compile unit: | 
|---|
| 869 |  | 
|---|
| 870 | #define foo __redirect_foo | 
|---|
| 871 | #include <foo.h> | 
|---|
| 872 | #undef foo | 
|---|
| 873 |  | 
|---|
| 874 | extern __typeof (__redirect_foo) __foo_default attribute_hidden; | 
|---|
| 875 | extern __typeof (__redirect_foo) __foo_special attribute_hidden; | 
|---|
| 876 |  | 
|---|
| 877 | libc_ifunc_redirected (__redirect_foo, foo, | 
|---|
| 878 | (hwcap & HWCAP_SPECIAL) | 
|---|
| 879 | ? __foo_special | 
|---|
| 880 | : __foo_default); | 
|---|
| 881 |  | 
|---|
| 882 | This will define the ifunc'ed symbol foo like above.  The redirection of foo | 
|---|
| 883 | in header file is needed to omit an additional defintion of __GI_foo which | 
|---|
| 884 | would end in a linker error while linking libc.so.  You have to specify | 
|---|
| 885 | __redirect_foo as first parameter which is used within libc_ifunc_redirected | 
|---|
| 886 | macro in conjunction with typeof to define the ifunc'ed symbol foo. | 
|---|
| 887 |  | 
|---|
| 888 | If your function foo has a libc_hidden_proto (foo) defined and calls to foo | 
|---|
| 889 | within or from outside libc.so should go via ifunc'ed symbol, then you have | 
|---|
| 890 | to use: | 
|---|
| 891 |  | 
|---|
| 892 | libc_ifunc_hidden (foo, foo, | 
|---|
| 893 | (hwcap & HWCAP_SPECIAL) | 
|---|
| 894 | ? __foo_special | 
|---|
| 895 | : __foo_default); | 
|---|
| 896 | libc_hidden_def (foo) | 
|---|
| 897 |  | 
|---|
| 898 | The first parameter foo of libc_ifunc_hidden macro is used in the same way | 
|---|
| 899 | as for libc_ifunc_redirected macro.  */ | 
|---|
| 900 |  | 
|---|
| 901 | #define libc_ifunc(name, expr) __ifunc (name, name, expr, void, INIT_ARCH) | 
|---|
| 902 |  | 
|---|
| 903 | #define libc_ifunc_redirected(redirected_name, name, expr)	\ | 
|---|
| 904 | __ifunc (redirected_name, name, expr, void, INIT_ARCH) | 
|---|
| 905 |  | 
|---|
| 906 | #define libc_ifunc_hidden(redirected_name, name, expr)			\ | 
|---|
| 907 | __ifunc_hidden (redirected_name, name, expr, void, INIT_ARCH) | 
|---|
| 908 |  | 
|---|
| 909 | /* The body of the function is supposed to use __get_cpu_features | 
|---|
| 910 | which will, if necessary, initialize the data first.  */ | 
|---|
| 911 | #define libm_ifunc_init() | 
|---|
| 912 | #define libm_ifunc(name, expr)				\ | 
|---|
| 913 | __ifunc (name, name, expr, void, libm_ifunc_init) | 
|---|
| 914 |  | 
|---|
| 915 | /* Add the compiler optimization to inhibit loop transformation to library | 
|---|
| 916 | calls.  This is used to avoid recursive calls in memset and memmove | 
|---|
| 917 | default implementations.  */ | 
|---|
| 918 | #ifdef HAVE_CC_INHIBIT_LOOP_TO_LIBCALL | 
|---|
| 919 | # define inhibit_loop_to_libcall \ | 
|---|
| 920 | __attribute__ ((__optimize__ ("-fno-tree-loop-distribute-patterns"))) | 
|---|
| 921 | #else | 
|---|
| 922 | # define inhibit_loop_to_libcall | 
|---|
| 923 | #endif | 
|---|
| 924 |  | 
|---|
| 925 | /* These macros facilitate sharing source files with gnulib. | 
|---|
| 926 |  | 
|---|
| 927 | They are here instead of sys/cdefs.h because they should not be | 
|---|
| 928 | used in public header files. | 
|---|
| 929 |  | 
|---|
| 930 | Their definitions should be kept consistent with the definitions in | 
|---|
| 931 | gnulib-common.m4, but it is not necessary to cater to old non-GCC | 
|---|
| 932 | compilers, since they will only be used while building glibc itself. | 
|---|
| 933 | (Note that _GNUC_PREREQ cannot be used in this file.)  */ | 
|---|
| 934 |  | 
|---|
| 935 | /* Define as a marker that can be attached to declarations that might not | 
|---|
| 936 | be used.  This helps to reduce warnings, such as from | 
|---|
| 937 | GCC -Wunused-parameter.  */ | 
|---|
| 938 | #if __GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7) | 
|---|
| 939 | # define _GL_UNUSED __attribute__ ((__unused__)) | 
|---|
| 940 | #else | 
|---|
| 941 | # define _GL_UNUSED | 
|---|
| 942 | #endif | 
|---|
| 943 |  | 
|---|
| 944 | /* gcc supports the "unused" attribute on possibly unused labels, and | 
|---|
| 945 | g++ has since version 4.5.  Note to support C++ as well as C, | 
|---|
| 946 | _GL_UNUSED_LABEL should be used with a trailing ;  */ | 
|---|
| 947 | #if !defined __cplusplus || __GNUC__ > 4 \ | 
|---|
| 948 | || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) | 
|---|
| 949 | # define _GL_UNUSED_LABEL _GL_UNUSED | 
|---|
| 950 | #else | 
|---|
| 951 | # define _GL_UNUSED_LABEL | 
|---|
| 952 | #endif | 
|---|
| 953 |  | 
|---|
| 954 | /* The __pure__ attribute was added in gcc 2.96.  */ | 
|---|
| 955 | #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96) | 
|---|
| 956 | # define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__)) | 
|---|
| 957 | #else | 
|---|
| 958 | # define _GL_ATTRIBUTE_PURE /* empty */ | 
|---|
| 959 | #endif | 
|---|
| 960 |  | 
|---|
| 961 | /* The __const__ attribute was added in gcc 2.95.  */ | 
|---|
| 962 | #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95) | 
|---|
| 963 | # define _GL_ATTRIBUTE_CONST __attribute__ ((__const__)) | 
|---|
| 964 | #else | 
|---|
| 965 | # define _GL_ATTRIBUTE_CONST /* empty */ | 
|---|
| 966 | #endif | 
|---|
| 967 |  | 
|---|
| 968 | #endif /* !_ISOMAC */ | 
|---|
| 969 | #endif /* libc-symbols.h */ | 
|---|
| 970 |  | 
|---|