]>
Commit | Line | Data |
---|---|---|
28f540f4 RM |
1 | /* Support macros for making weak and strong aliases for symbols, |
2 | and for using symbol sets and linker warnings with GNU ld. | |
04277e02 | 3 | Copyright (C) 1995-2019 Free Software Foundation, Inc. |
5290baf0 | 4 | This file is part of the GNU C Library. |
28f540f4 | 5 | |
5290baf0 | 6 | The GNU C Library is free software; you can redistribute it and/or |
41bdb6e2 AJ |
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. | |
28f540f4 | 10 | |
5290baf0 UD |
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 | |
41bdb6e2 | 14 | Lesser General Public License for more details. |
28f540f4 | 15 | |
41bdb6e2 | 16 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 | 17 | License along with the GNU C Library; if not, see |
5a82c748 | 18 | <https://www.gnu.org/licenses/>. */ |
28f540f4 RM |
19 | |
20 | #ifndef _LIBC_SYMBOLS_H | |
5290baf0 | 21 | #define _LIBC_SYMBOLS_H 1 |
28f540f4 | 22 | |
7c3018f9 ZW |
23 | /* This file is included implicitly in the compilation of every source file, |
24 | using -include. It includes config.h. */ | |
9cd47470 | 25 | |
7c3018f9 ZW |
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 | |
28f540f4 | 50 | |
7c3018f9 ZW |
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 | |
28f540f4 | 61 | |
7c3018f9 | 62 | #ifndef _ISOMAC |
28f540f4 | 63 | |
92777700 RM |
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. */ | |
c709e372 | 71 | #define _LIBC 1 |
92777700 | 72 | |
7c3018f9 ZW |
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 | |
d3669add | 84 | |
92777700 | 85 | #include <config.h> |
28f540f4 | 86 | |
086df229 L |
87 | /* When PIC is defined and SHARED isn't defined, we are building PIE |
88 | by default. */ | |
89 | #if defined PIC && !defined SHARED | |
90 | # define BUILD_PIE_DEFAULT 1 | |
91 | #else | |
92 | # define BUILD_PIE_DEFAULT 0 | |
93 | #endif | |
94 | ||
26ffd5e6 RM |
95 | /* Define this for the benefit of portable GNU code that wants to check it. |
96 | Code that checks with #if will not #include <config.h> again, since we've | |
97 | already done it (and this file is implicitly included in every compile, | |
98 | via -include). Code that checks with #ifdef will #include <config.h>, | |
99 | but that file should always be idempotent (i.e., it's just #define/#undef | |
100 | and nothing else anywhere should be changing the macro state it touches), | |
101 | so it's harmless. */ | |
102 | #define HAVE_CONFIG_H 0 | |
103 | ||
3f3dd810 SP |
104 | /* Define these macros for the benefit of portable GNU code that wants to check |
105 | them. Of course, STDC_HEADERS is never false when building libc! */ | |
26ffd5e6 | 106 | #define STDC_HEADERS 1 |
3f3dd810 SP |
107 | #define HAVE_MBSTATE_T 1 |
108 | #define HAVE_MBSRTOWCS 1 | |
a476ac4b SP |
109 | #define HAVE_LIBINTL_H 1 |
110 | #define HAVE_WCTYPE_H 1 | |
111 | #define HAVE_ISWCTYPE 1 | |
112 | #define ENABLE_NLS 1 | |
26ffd5e6 | 113 | |
0269750c | 114 | /* The symbols in all the user (non-_) macros are C symbols. */ |
28f540f4 | 115 | |
28f540f4 | 116 | #ifndef __SYMBOL_PREFIX |
a0da5fe1 | 117 | # define __SYMBOL_PREFIX |
28f540f4 RM |
118 | #endif |
119 | ||
120 | #ifndef C_SYMBOL_NAME | |
a0da5fe1 | 121 | # define C_SYMBOL_NAME(name) name |
28f540f4 RM |
122 | #endif |
123 | ||
b15cb495 UD |
124 | #ifndef ASM_LINE_SEP |
125 | # define ASM_LINE_SEP ; | |
126 | #endif | |
127 | ||
1626a1cf MS |
128 | #ifndef __attribute_copy__ |
129 | /* Provide an empty definition when cdefs.h is not included. */ | |
130 | # define __attribute_copy__(arg) | |
131 | #endif | |
132 | ||
428383e8 UD |
133 | #ifndef __ASSEMBLER__ |
134 | /* GCC understands weak symbols and aliases; use its interface where | |
135 | possible, instead of embedded assembly language. */ | |
d02907df | 136 | |
428383e8 | 137 | /* Define ALIASNAME as a strong alias for NAME. */ |
c62f5cab GM |
138 | # define strong_alias(name, aliasname) _strong_alias(name, aliasname) |
139 | # define _strong_alias(name, aliasname) \ | |
1626a1cf MS |
140 | extern __typeof (name) aliasname __attribute__ ((alias (#name))) \ |
141 | __attribute_copy__ (name); | |
428383e8 UD |
142 | |
143 | /* This comes between the return type and function name in | |
144 | a function definition to make that definition weak. */ | |
145 | # define weak_function __attribute__ ((weak)) | |
146 | # define weak_const_function __attribute__ ((weak, __const__)) | |
147 | ||
428383e8 UD |
148 | /* Define ALIASNAME as a weak alias for NAME. |
149 | If weak aliases are not available, this defines a strong alias. */ | |
a0da5fe1 UD |
150 | # define weak_alias(name, aliasname) _weak_alias (name, aliasname) |
151 | # define _weak_alias(name, aliasname) \ | |
1626a1cf MS |
152 | extern __typeof (name) aliasname __attribute__ ((weak, alias (#name))) \ |
153 | __attribute_copy__ (name); | |
428383e8 | 154 | |
11bf311e | 155 | /* Same as WEAK_ALIAS, but mark symbol as hidden. */ |
a0da5fe1 | 156 | # define weak_hidden_alias(name, aliasname) \ |
11bf311e | 157 | _weak_hidden_alias (name, aliasname) |
a0da5fe1 | 158 | # define _weak_hidden_alias(name, aliasname) \ |
11bf311e | 159 | extern __typeof (name) aliasname \ |
1626a1cf MS |
160 | __attribute__ ((weak, alias (#name), __visibility__ ("hidden"))) \ |
161 | __attribute_copy__ (name); | |
11bf311e | 162 | |
428383e8 | 163 | /* Declare SYMBOL as weak undefined symbol (resolved to 0 if not defined). */ |
a0da5fe1 UD |
164 | # define weak_extern(symbol) _weak_extern (weak symbol) |
165 | # define _weak_extern(expr) _Pragma (#expr) | |
428383e8 | 166 | |
ef4f9764 FW |
167 | /* In shared builds, the expression call_function_static_weak |
168 | (FUNCTION-SYMBOL, ARGUMENTS) invokes FUNCTION-SYMBOL (an | |
169 | identifier) unconditionally, with the (potentially empty) argument | |
170 | list ARGUMENTS. In static builds, if FUNCTION-SYMBOL has a | |
171 | definition, the function is invoked as before; if FUNCTION-SYMBOL | |
172 | is NULL, no call is performed. */ | |
173 | # ifdef SHARED | |
174 | # define call_function_static_weak(func, ...) func (__VA_ARGS__) | |
175 | # else /* !SHARED */ | |
176 | # define call_function_static_weak(func, ...) \ | |
177 | ({ \ | |
178 | extern __typeof__ (func) func weak_function; \ | |
179 | (func != NULL ? func (__VA_ARGS__) : (void)0); \ | |
180 | }) | |
181 | # endif | |
428383e8 UD |
182 | |
183 | #else /* __ASSEMBLER__ */ | |
184 | ||
185 | # ifdef HAVE_ASM_SET_DIRECTIVE | |
5ca10a0c | 186 | # define strong_alias(original, alias) \ |
7b8e0d49 | 187 | .globl C_SYMBOL_NAME (alias) ASM_LINE_SEP \ |
c843e065 | 188 | .set C_SYMBOL_NAME (alias),C_SYMBOL_NAME (original) |
5ca10a0c | 189 | # define strong_data_alias(original, alias) strong_alias(original, alias) |
dfd2257a | 190 | # else |
5ca10a0c | 191 | # define strong_alias(original, alias) \ |
7b8e0d49 | 192 | .globl C_SYMBOL_NAME (alias) ASM_LINE_SEP \ |
c843e065 | 193 | C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original) |
5ca10a0c | 194 | # define strong_data_alias(original, alias) strong_alias(original, alias) |
dfd2257a | 195 | # endif |
d02907df | 196 | |
210dd782 | 197 | # define weak_alias(original, alias) \ |
c843e065 | 198 | .weak C_SYMBOL_NAME (alias) ASM_LINE_SEP \ |
28f540f4 | 199 | C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original) |
e6964dd4 | 200 | |
210dd782 | 201 | # define weak_extern(symbol) \ |
af5b3bc3 | 202 | .weak C_SYMBOL_NAME (symbol) |
d02907df | 203 | |
428383e8 | 204 | #endif /* __ASSEMBLER__ */ |
958f803f | 205 | |
e862aada UD |
206 | /* Determine the return address. */ |
207 | #define RETURN_ADDRESS(nr) \ | |
208 | __builtin_extract_return_addr (__builtin_return_address (nr)) | |
209 | ||
44c8d1a2 RM |
210 | /* When a reference to SYMBOL is encountered, the linker will emit a |
211 | warning message MSG. */ | |
fd26970f | 212 | /* We want the .gnu.warning.SYMBOL section to be unallocated. */ |
75b0964b | 213 | #define __make_section_unallocated(section_string) \ |
b15cb495 | 214 | asm (".section " section_string "\n\t.previous"); |
fd26970f | 215 | |
b15cb495 UD |
216 | /* Tacking on "\n\t#" to the section name makes gcc put it's bogus |
217 | section attributes on what looks like a comment to the assembler. */ | |
0269750c UD |
218 | #ifdef HAVE_SECTION_QUOTES |
219 | # define __sec_comment "\"\n\t#\"" | |
220 | #else | |
221 | # define __sec_comment "\n\t#" | |
222 | #endif | |
223 | #define link_warning(symbol, msg) \ | |
e26dd47f | 224 | __make_section_unallocated (".gnu.warning." #symbol) \ |
44c8d1a2 | 225 | static const char __evoke_link_warning_##symbol[] \ |
6c5775c3 | 226 | __attribute__ ((used, section (".gnu.warning." #symbol __sec_comment))) \ |
c877418f | 227 | = msg; |
28f540f4 RM |
228 | |
229 | /* A canned warning for sysdeps/stub functions. */ | |
230 | #define stub_warning(name) \ | |
561bcb80 | 231 | __make_section_unallocated (".gnu.glibc-stub." #name) \ |
cd525923 | 232 | link_warning (name, #name " is not implemented and will always fail") |
5f9e57ba | 233 | |
2f7f7bc6 UD |
234 | /* Warning for linking functions calling dlopen into static binaries. */ |
235 | #ifdef SHARED | |
236 | #define static_link_warning(name) | |
237 | #else | |
238 | #define static_link_warning(name) static_link_warning1(name) | |
239 | #define static_link_warning1(name) \ | |
240 | link_warning(name, "Using '" #name "' in statically linked applications \ | |
241 | requires at runtime the shared libraries from the glibc version used \ | |
242 | for linking") | |
243 | #endif | |
b88ac073 | 244 | |
2827ab99 CD |
245 | /* Resource Freeing Hooks: |
246 | ||
247 | Normally a process exits and the OS cleans up any allocated | |
248 | memory. However, when tooling like mtrace or valgrind is monitoring | |
249 | the process we need to free all resources that are part of the | |
250 | process in order to provide the consistency required to track | |
251 | memory leaks. | |
252 | ||
253 | A single public API exists and is __libc_freeres(), and this is used | |
254 | by applications like valgrind to freee resouces. | |
255 | ||
256 | There are 3 cases: | |
257 | ||
258 | (a) __libc_freeres | |
259 | ||
260 | In this case all you need to do is define the freeing routine: | |
261 | ||
262 | foo.c: | |
263 | libfoo_freeres_fn (foo_freeres) | |
264 | { | |
265 | complex_free (mem); | |
266 | } | |
267 | ||
268 | This ensures the function is called at the right point to free | |
269 | resources. | |
270 | ||
271 | (b) __libc_freeres_ptr | |
272 | ||
273 | The framework for (a) iterates over the list of pointers-to-free | |
274 | in (b) and frees them. | |
275 | ||
276 | foo.c: | |
277 | libc_freeres_ptr (static char *foo_buffer); | |
278 | ||
279 | Freeing these resources alaways happens last and is equivalent | |
280 | to registering a function that does 'free (foo_buffer)'. | |
281 | ||
282 | (c) Explicit lists of free routines to call or objects to free. | |
283 | ||
284 | It is the intended goal to remove (a) and (b) which have some | |
285 | non-determinism based on link order, and instead use explicit | |
286 | lists of functions and frees to resolve cleanup ordering issues | |
287 | and make it easy to debug and maintain. | |
288 | ||
289 | As of today the following subsystems use (c): | |
290 | ||
291 | Per-thread cleanup: | |
292 | * malloc/thread-freeres.c | |
293 | ||
294 | libdl cleanup: | |
295 | * dlfcn/dlfreeres.c | |
296 | ||
297 | libpthread cleanup: | |
298 | * nptl/nptlfreeres.c | |
299 | ||
300 | So if you need any shutdown routines to run you should add them | |
301 | directly to the appropriate subsystem's shutdown list. */ | |
302 | ||
303 | /* Resource pointers to free in libc.so. */ | |
304 | #define libc_freeres_ptr(decl) \ | |
305 | __make_section_unallocated ("__libc_freeres_ptrs, \"aw\", %nobits") \ | |
306 | decl __attribute__ ((section ("__libc_freeres_ptrs" __sec_comment))) | |
307 | ||
308 | /* Resource freeing functions from libc.so go in this section. */ | |
309 | #define __libc_freeres_fn_section \ | |
310 | __attribute__ ((section ("__libc_freeres_fn"))) | |
311 | ||
312 | /* Resource freeing functions for libc.so. */ | |
313 | #define libc_freeres_fn(name) \ | |
314 | static void name (void) __attribute_used__ __libc_freeres_fn_section; \ | |
315 | text_set_element (__libc_subfreeres, name); \ | |
316 | static void name (void) | |
317 | ||
11bf311e UD |
318 | /* Declare SYMBOL to be TYPE (`function' or `object') of SIZE bytes |
319 | alias to ORIGINAL, when the assembler supports such declarations | |
320 | (such as in ELF). | |
b88ac073 RM |
321 | This is only necessary when defining something in assembly, or playing |
322 | funny alias games where the size should be other than what the compiler | |
323 | thinks it is. */ | |
11bf311e UD |
324 | #define declare_symbol_alias(symbol, original, type, size) \ |
325 | declare_symbol_alias_1 (symbol, original, type, size) | |
b67e9372 MP |
326 | #ifdef __ASSEMBLER__ |
327 | # define declare_symbol_alias_1(symbol, original, type, size) \ | |
328 | strong_alias (original, symbol); \ | |
329 | .type C_SYMBOL_NAME (symbol), %##type; \ | |
330 | .size C_SYMBOL_NAME (symbol), size | |
331 | #else /* Not __ASSEMBLER__. */ | |
332 | # define declare_symbol_alias_1(symbol, original, type, size) \ | |
333 | asm (".globl " __SYMBOL_PREFIX #symbol \ | |
334 | "\n\t" declare_symbol_alias_1_alias (symbol, original) \ | |
335 | "\n\t.type " __SYMBOL_PREFIX #symbol ", " \ | |
336 | "%" #type \ | |
337 | "\n\t.size " __SYMBOL_PREFIX #symbol ", " #size); | |
338 | # ifdef HAVE_ASM_SET_DIRECTIVE | |
339 | # define declare_symbol_alias_1_alias(symbol, original) \ | |
340 | ".set " __SYMBOL_PREFIX #symbol ", " __SYMBOL_PREFIX #original | |
341 | # else | |
342 | # define declare_symbol_alias_1_alias(symbol, original) \ | |
343 | __SYMBOL_PREFIX #symbol " = " __SYMBOL_PREFIX #original | |
344 | # endif /* HAVE_ASM_SET_DIRECTIVE */ | |
345 | #endif /* __ASSEMBLER__ */ | |
b88ac073 RM |
346 | |
347 | ||
5f9e57ba | 348 | /* |
28f540f4 | 349 | \f |
5f9e57ba RM |
350 | */ |
351 | ||
28f540f4 RM |
352 | /* Symbol set support macros. */ |
353 | ||
28f540f4 | 354 | /* Make SYMBOL, which is in the text segment, an element of SET. */ |
0269750c | 355 | #define text_set_element(set, symbol) _elf_set_element(set, symbol) |
28f540f4 | 356 | /* Make SYMBOL, which is in the data segment, an element of SET. */ |
0269750c | 357 | #define data_set_element(set, symbol) _elf_set_element(set, symbol) |
28f540f4 | 358 | /* Make SYMBOL, which is in the bss segment, an element of SET. */ |
0269750c | 359 | #define bss_set_element(set, symbol) _elf_set_element(set, symbol) |
28f540f4 RM |
360 | |
361 | /* These are all done the same way in ELF. | |
362 | There is a new section created for each set. */ | |
0269750c | 363 | #ifdef SHARED |
53afa8d9 RM |
364 | /* When building a shared library, make the set section writable, |
365 | because it will need to be relocated at run time anyway. */ | |
0269750c | 366 | # define _elf_set_element(set, symbol) \ |
53afa8d9 | 367 | static const void *__elf_set_##set##_element_##symbol##__ \ |
6c5775c3 | 368 | __attribute__ ((used, section (#set))) = &(symbol) |
0269750c UD |
369 | #else |
370 | # define _elf_set_element(set, symbol) \ | |
28f540f4 | 371 | static const void *const __elf_set_##set##_element_##symbol##__ \ |
6c5775c3 | 372 | __attribute__ ((used, section (#set))) = &(symbol) |
0269750c | 373 | #endif |
28f540f4 RM |
374 | |
375 | /* Define SET as a symbol set. This may be required (it is in a.out) to | |
376 | be able to use the set's contents. */ | |
0269750c | 377 | #define symbol_set_define(set) symbol_set_declare(set) |
28f540f4 | 378 | |
20792f99 RM |
379 | /* Declare SET for use in this module, if defined in another module. |
380 | In a shared library, this is always local to that shared object. | |
381 | For static linking, the set might be wholly absent and so we use | |
382 | weak references. */ | |
0269750c | 383 | #define symbol_set_declare(set) \ |
6f1e513d RH |
384 | extern char const __start_##set[] __symbol_set_attribute; \ |
385 | extern char const __stop_##set[] __symbol_set_attribute; | |
0269750c UD |
386 | #ifdef SHARED |
387 | # define __symbol_set_attribute attribute_hidden | |
388 | #else | |
389 | # define __symbol_set_attribute __attribute__ ((weak)) | |
390 | #endif | |
28f540f4 RM |
391 | |
392 | /* Return a pointer (void *const *) to the first element of SET. */ | |
0269750c | 393 | #define symbol_set_first_element(set) ((void *const *) (&__start_##set)) |
28f540f4 RM |
394 | |
395 | /* Return true iff PTR (a void *const *) has been incremented | |
396 | past the last element in SET. */ | |
0269750c | 397 | #define symbol_set_end_p(set, ptr) ((ptr) >= (void *const *) &__stop_##set) |
28f540f4 | 398 | |
968dc26d FW |
399 | /* Use symbol_version_reference to specify the version a symbol |
400 | reference should link to. Use symbol_version or | |
401 | default_symbol_version for the definition of a versioned symbol. | |
402 | The difference is that the latter is a no-op in non-shared | |
403 | builds. */ | |
404 | #ifdef __ASSEMBLER__ | |
405 | # define symbol_version_reference(real, name, version) \ | |
406 | .symver real, name##@##version | |
407 | #else /* !__ASSEMBLER__ */ | |
408 | # define symbol_version_reference(real, name, version) \ | |
409 | __asm__ (".symver " #real "," #name "@" #version) | |
410 | #endif | |
411 | ||
3f2e46a4 | 412 | #ifdef SHARED |
ebdf53a7 | 413 | # define symbol_version(real, name, version) \ |
968dc26d | 414 | symbol_version_reference(real, name, version) |
ebdf53a7 GM |
415 | # define default_symbol_version(real, name, version) \ |
416 | _default_symbol_version(real, name, version) | |
417 | # ifdef __ASSEMBLER__ | |
5ca10a0c | 418 | # define _default_symbol_version(real, name, version) \ |
da2d1bc5 UD |
419 | .symver real, name##@##@##version |
420 | # else | |
5ca10a0c | 421 | # define _default_symbol_version(real, name, version) \ |
f2ea0f5b | 422 | __asm__ (".symver " #real "," #name "@@" #version) |
da2d1bc5 | 423 | # endif |
1ea89a40 UD |
424 | #else |
425 | # define symbol_version(real, name, version) | |
da2d1bc5 UD |
426 | # define default_symbol_version(real, name, version) \ |
427 | strong_alias(real, name) | |
1ea89a40 UD |
428 | #endif |
429 | ||
7c41b4a1 L |
430 | #if defined SHARED || defined LIBC_NONSHARED \ |
431 | || (BUILD_PIE_DEFAULT && IS_IN (libc)) | |
e6caf4e1 UD |
432 | # define attribute_hidden __attribute__ ((visibility ("hidden"))) |
433 | #else | |
434 | # define attribute_hidden | |
435 | #endif | |
436 | ||
3ce1f295 | 437 | #define attribute_tls_model_ie __attribute__ ((tls_model ("initial-exec"))) |
9b21e6bc | 438 | |
11bf311e | 439 | #define attribute_relro __attribute__ ((section (".data.rel.ro"))) |
392a6b52 | 440 | |
de659123 NA |
441 | |
442 | /* Used to disable stack protection in sensitive places, like ifunc | |
443 | resolvers and early static TLS init. */ | |
444 | #ifdef HAVE_CC_NO_STACK_PROTECTOR | |
445 | # define inhibit_stack_protector \ | |
446 | __attribute__ ((__optimize__ ("-fno-stack-protector"))) | |
447 | #else | |
448 | # define inhibit_stack_protector | |
449 | #endif | |
450 | ||
37ba7d66 UD |
451 | /* The following macros are used for PLT bypassing within libc.so |
452 | (and if needed other libraries similarly). | |
453 | First of all, you need to have the function prototyped somewhere, | |
454 | say in foo/foo.h: | |
455 | ||
456 | int foo (int __bar); | |
457 | ||
458 | If calls to foo within libc.so should always go to foo defined in libc.so, | |
459 | then in include/foo.h you add: | |
460 | ||
461 | libc_hidden_proto (foo) | |
462 | ||
463 | line and after the foo function definition: | |
464 | ||
465 | int foo (int __bar) | |
466 | { | |
467 | return __bar; | |
468 | } | |
469 | libc_hidden_def (foo) | |
470 | ||
471 | or | |
472 | ||
473 | int foo (int __bar) | |
474 | { | |
475 | return __bar; | |
476 | } | |
477 | libc_hidden_weak (foo) | |
478 | ||
5536dfcb | 479 | Similarly for global data. If references to foo within libc.so should |
c843e065 RM |
480 | always go to foo defined in libc.so, then in include/foo.h you add: |
481 | ||
482 | libc_hidden_proto (foo) | |
483 | ||
484 | line and after foo's definition: | |
485 | ||
486 | int foo = INITIAL_FOO_VALUE; | |
487 | libc_hidden_data_def (foo) | |
488 | ||
489 | or | |
490 | ||
491 | int foo = INITIAL_FOO_VALUE; | |
492 | libc_hidden_data_weak (foo) | |
493 | ||
5536dfcb | 494 | If foo is normally just an alias (strong or weak) to some other function, |
37ba7d66 UD |
495 | you should use the normal strong_alias first, then add libc_hidden_def |
496 | or libc_hidden_weak: | |
497 | ||
498 | int baz (int __bar) | |
499 | { | |
500 | return __bar; | |
501 | } | |
502 | strong_alias (baz, foo) | |
503 | libc_hidden_weak (foo) | |
504 | ||
505 | If the function should be internal to multiple objects, say ld.so and | |
506 | libc.so, the best way is to use: | |
507 | ||
9cd47470 | 508 | #if IS_IN (libc) || IS_IN (rtld) |
37ba7d66 UD |
509 | hidden_proto (foo) |
510 | #endif | |
511 | ||
512 | in include/foo.h and the normal macros at all function definitions | |
513 | depending on what DSO they belong to. | |
514 | ||
515 | If versioned_symbol macro is used to define foo, | |
516 | libc_hidden_ver macro should be used, as in: | |
517 | ||
518 | int __real_foo (int __bar) | |
519 | { | |
520 | return __bar; | |
521 | } | |
522 | versioned_symbol (libc, __real_foo, foo, GLIBC_2_1); | |
523 | libc_hidden_ver (__real_foo, foo) */ | |
524 | ||
3f2e46a4 | 525 | #if defined SHARED && !defined NO_HIDDEN |
37ba7d66 | 526 | # ifndef __ASSEMBLER__ |
11bf311e | 527 | # define __hidden_proto_hiddenattr(attrs...) \ |
81cb0d82 | 528 | __attribute__ ((visibility ("hidden"), ##attrs)) |
81cb0d82 | 529 | # define hidden_proto(name, attrs...) \ |
699df45b JM |
530 | __hidden_proto (name, , __GI_##name, ##attrs) |
531 | # define hidden_tls_proto(name, attrs...) \ | |
532 | __hidden_proto (name, __thread, __GI_##name, ##attrs) | |
533 | # define __hidden_proto(name, thread, internal, attrs...) \ | |
534 | extern thread __typeof (name) name __asm__ (__hidden_asmname (#internal)) \ | |
81cb0d82 | 535 | __hidden_proto_hiddenattr (attrs); |
37ba7d66 UD |
536 | # define __hidden_asmname(name) \ |
537 | __hidden_asmname1 (__USER_LABEL_PREFIX__, name) | |
538 | # define __hidden_asmname1(prefix, name) __hidden_asmname2(prefix, name) | |
539 | # define __hidden_asmname2(prefix, name) #prefix name | |
61995d3e | 540 | # define __hidden_ver1(local, internal, name) \ |
9c4b457e JM |
541 | __hidden_ver2 (, local, internal, name) |
542 | # define __hidden_ver2(thread, local, internal, name) \ | |
543 | extern thread __typeof (name) __EI_##name \ | |
544 | __asm__(__hidden_asmname (#internal)); \ | |
545 | extern thread __typeof (name) __EI_##name \ | |
1626a1cf MS |
546 | __attribute__((alias (__hidden_asmname (#local)))) \ |
547 | __attribute_copy__ (name) | |
61995d3e RM |
548 | # define hidden_ver(local, name) __hidden_ver1(local, __GI_##name, name); |
549 | # define hidden_data_ver(local, name) hidden_ver(local, name) | |
550 | # define hidden_def(name) __hidden_ver1(__GI_##name, name, name); | |
551 | # define hidden_data_def(name) hidden_def(name) | |
9c4b457e JM |
552 | # define hidden_tls_def(name) \ |
553 | __hidden_ver2 (__thread, __GI_##name, name, name); | |
61995d3e RM |
554 | # define hidden_weak(name) \ |
555 | __hidden_ver1(__GI_##name, name, name) __attribute__((weak)); | |
556 | # define hidden_data_weak(name) hidden_weak(name) | |
7b57bfe5 UD |
557 | # define hidden_nolink(name, lib, version) \ |
558 | __hidden_nolink1 (__GI_##name, __EI_##name, name, VERSION_##lib##_##version) | |
559 | # define __hidden_nolink1(local, internal, name, version) \ | |
560 | __hidden_nolink2 (local, internal, name, version) | |
561 | # define __hidden_nolink2(local, internal, name, version) \ | |
1626a1cf MS |
562 | extern __typeof (name) internal __attribute__ ((alias (#local))) \ |
563 | __attribute_copy__ (name); \ | |
7b57bfe5 UD |
564 | __hidden_nolink3 (local, internal, #name "@" #version) |
565 | # define __hidden_nolink3(local, internal, vername) \ | |
566 | __asm__ (".symver " #internal ", " vername); | |
37ba7d66 UD |
567 | # else |
568 | /* For assembly, we need to do the opposite of what we do in C: | |
569 | in assembly gcc __REDIRECT stuff is not in place, so functions | |
570 | are defined by its normal name and we need to create the | |
571 | __GI_* alias to it, in C __REDIRECT causes the function definition | |
572 | to use __GI_* name and we need to add alias to the real name. | |
4547dee3 RM |
573 | There is no reason to use hidden_weak over hidden_def in assembly, |
574 | but we provide it for consistency with the C usage. | |
575 | hidden_proto doesn't make sense for assembly but the equivalent | |
dce8f2b6 | 576 | is to call via the HIDDEN_JUMPTARGET macro instead of JUMPTARGET. */ |
4547dee3 RM |
577 | # define hidden_def(name) strong_alias (name, __GI_##name) |
578 | # define hidden_weak(name) hidden_def (name) | |
37ba7d66 | 579 | # define hidden_ver(local, name) strong_alias (local, __GI_##name) |
c843e065 | 580 | # define hidden_data_def(name) strong_data_alias (name, __GI_##name) |
9c4b457e | 581 | # define hidden_tls_def(name) hidden_data_def (name) |
c843e065 RM |
582 | # define hidden_data_weak(name) hidden_data_def (name) |
583 | # define hidden_data_ver(local, name) strong_data_alias (local, __GI_##name) | |
5ca10a0c | 584 | # define HIDDEN_JUMPTARGET(name) __GI_##name |
37ba7d66 UD |
585 | # endif |
586 | #else | |
4547dee3 | 587 | # ifndef __ASSEMBLER__ |
8d2ec553 | 588 | # if !defined SHARED && IS_IN (libc) && !defined LIBC_NONSHARED \ |
ee417882 | 589 | && (!defined PIC || !defined NO_HIDDEN_EXTERN_FUNC_IN_PIE) \ |
8d2ec553 L |
590 | && !defined NO_HIDDEN |
591 | # define __hidden_proto_hiddenattr(attrs...) \ | |
592 | __attribute__ ((visibility ("hidden"), ##attrs)) | |
593 | # define hidden_proto(name, attrs...) \ | |
594 | __hidden_proto (name, , name, ##attrs) | |
595 | # define hidden_tls_proto(name, attrs...) \ | |
596 | __hidden_proto (name, __thread, name, ##attrs) | |
597 | # define __hidden_proto(name, thread, internal, attrs...) \ | |
598 | extern thread __typeof (name) name __hidden_proto_hiddenattr (attrs); | |
599 | # else | |
600 | # define hidden_proto(name, attrs...) | |
601 | # define hidden_tls_proto(name, attrs...) | |
602 | # endif | |
4547dee3 RM |
603 | # else |
604 | # define HIDDEN_JUMPTARGET(name) JUMPTARGET(name) | |
605 | # endif /* Not __ASSEMBLER__ */ | |
606 | # define hidden_weak(name) | |
37ba7d66 UD |
607 | # define hidden_def(name) |
608 | # define hidden_ver(local, name) | |
c843e065 RM |
609 | # define hidden_data_weak(name) |
610 | # define hidden_data_def(name) | |
9c4b457e | 611 | # define hidden_tls_def(name) |
c843e065 | 612 | # define hidden_data_ver(local, name) |
1792c087 | 613 | # define hidden_nolink(name, lib, version) |
37ba7d66 UD |
614 | #endif |
615 | ||
4f41c682 | 616 | #if IS_IN (libc) |
81cb0d82 | 617 | # define libc_hidden_proto(name, attrs...) hidden_proto (name, ##attrs) |
699df45b | 618 | # define libc_hidden_tls_proto(name, attrs...) hidden_tls_proto (name, ##attrs) |
37ba7d66 UD |
619 | # define libc_hidden_def(name) hidden_def (name) |
620 | # define libc_hidden_weak(name) hidden_weak (name) | |
021db4be AJ |
621 | # ifdef LINK_OBSOLETE_RPC |
622 | /* libc_hidden_nolink_sunrpc should only get used in sunrpc code. */ | |
623 | # define libc_hidden_nolink_sunrpc(name, version) hidden_def (name) | |
624 | # else | |
625 | # define libc_hidden_nolink_sunrpc(name, version) hidden_nolink (name, libc, version) | |
626 | # endif | |
37ba7d66 | 627 | # define libc_hidden_ver(local, name) hidden_ver (local, name) |
c843e065 | 628 | # define libc_hidden_data_def(name) hidden_data_def (name) |
9c4b457e | 629 | # define libc_hidden_tls_def(name) hidden_tls_def (name) |
c843e065 RM |
630 | # define libc_hidden_data_weak(name) hidden_data_weak (name) |
631 | # define libc_hidden_data_ver(local, name) hidden_data_ver (local, name) | |
37ba7d66 | 632 | #else |
81cb0d82 | 633 | # define libc_hidden_proto(name, attrs...) |
699df45b | 634 | # define libc_hidden_tls_proto(name, attrs...) |
37ba7d66 UD |
635 | # define libc_hidden_def(name) |
636 | # define libc_hidden_weak(name) | |
637 | # define libc_hidden_ver(local, name) | |
c843e065 | 638 | # define libc_hidden_data_def(name) |
9c4b457e | 639 | # define libc_hidden_tls_def(name) |
c843e065 RM |
640 | # define libc_hidden_data_weak(name) |
641 | # define libc_hidden_data_ver(local, name) | |
37ba7d66 UD |
642 | #endif |
643 | ||
3d1870fa | 644 | #if IS_IN (rtld) && !defined NO_RTLD_HIDDEN |
81cb0d82 | 645 | # define rtld_hidden_proto(name, attrs...) hidden_proto (name, ##attrs) |
699df45b | 646 | # define rtld_hidden_tls_proto(name, attrs...) hidden_tls_proto (name, ##attrs) |
37ba7d66 UD |
647 | # define rtld_hidden_def(name) hidden_def (name) |
648 | # define rtld_hidden_weak(name) hidden_weak (name) | |
649 | # define rtld_hidden_ver(local, name) hidden_ver (local, name) | |
c843e065 | 650 | # define rtld_hidden_data_def(name) hidden_data_def (name) |
9c4b457e | 651 | # define rtld_hidden_tls_def(name) hidden_tls_def (name) |
c843e065 RM |
652 | # define rtld_hidden_data_weak(name) hidden_data_weak (name) |
653 | # define rtld_hidden_data_ver(local, name) hidden_data_ver (local, name) | |
37ba7d66 | 654 | #else |
81cb0d82 | 655 | # define rtld_hidden_proto(name, attrs...) |
699df45b | 656 | # define rtld_hidden_tls_proto(name, attrs...) |
37ba7d66 UD |
657 | # define rtld_hidden_def(name) |
658 | # define rtld_hidden_weak(name) | |
659 | # define rtld_hidden_ver(local, name) | |
c843e065 | 660 | # define rtld_hidden_data_def(name) |
9c4b457e | 661 | # define rtld_hidden_tls_def(name) |
c843e065 RM |
662 | # define rtld_hidden_data_weak(name) |
663 | # define rtld_hidden_data_ver(local, name) | |
37ba7d66 UD |
664 | #endif |
665 | ||
9cd47470 | 666 | #if IS_IN (libm) |
81cb0d82 | 667 | # define libm_hidden_proto(name, attrs...) hidden_proto (name, ##attrs) |
699df45b | 668 | # define libm_hidden_tls_proto(name, attrs...) hidden_tls_proto (name, ##attrs) |
37ba7d66 UD |
669 | # define libm_hidden_def(name) hidden_def (name) |
670 | # define libm_hidden_weak(name) hidden_weak (name) | |
671 | # define libm_hidden_ver(local, name) hidden_ver (local, name) | |
c843e065 | 672 | # define libm_hidden_data_def(name) hidden_data_def (name) |
9c4b457e | 673 | # define libm_hidden_tls_def(name) hidden_tls_def (name) |
c843e065 RM |
674 | # define libm_hidden_data_weak(name) hidden_data_weak (name) |
675 | # define libm_hidden_data_ver(local, name) hidden_data_ver (local, name) | |
37ba7d66 | 676 | #else |
81cb0d82 | 677 | # define libm_hidden_proto(name, attrs...) |
699df45b | 678 | # define libm_hidden_tls_proto(name, attrs...) |
37ba7d66 UD |
679 | # define libm_hidden_def(name) |
680 | # define libm_hidden_weak(name) | |
681 | # define libm_hidden_ver(local, name) | |
c843e065 | 682 | # define libm_hidden_data_def(name) |
9c4b457e | 683 | # define libm_hidden_tls_def(name) |
c843e065 RM |
684 | # define libm_hidden_data_weak(name) |
685 | # define libm_hidden_data_ver(local, name) | |
37ba7d66 UD |
686 | #endif |
687 | ||
829a679f AS |
688 | #if IS_IN (libmvec) |
689 | # define libmvec_hidden_proto(name, attrs...) hidden_proto (name, ##attrs) | |
690 | # define libmvec_hidden_tls_proto(name, attrs...) hidden_tls_proto (name, ##attrs) | |
691 | # define libmvec_hidden_def(name) hidden_def (name) | |
692 | # define libmvec_hidden_weak(name) hidden_weak (name) | |
693 | # define libmvec_hidden_ver(local, name) hidden_ver (local, name) | |
694 | # define libmvec_hidden_data_def(name) hidden_data_def (name) | |
9c4b457e | 695 | # define libmvec_hidden_tls_def(name) hidden_tls_def (name) |
829a679f AS |
696 | # define libmvec_hidden_data_weak(name) hidden_data_weak (name) |
697 | # define libmvec_hidden_data_ver(local, name) hidden_data_ver (local, name) | |
698 | #else | |
699 | # define libmvec_hidden_proto(name, attrs...) | |
700 | # define libmvec_hidden_tls_proto(name, attrs...) | |
701 | # define libmvec_hidden_def(name) | |
702 | # define libmvec_hidden_weak(name) | |
703 | # define libmvec_hidden_ver(local, name) | |
704 | # define libmvec_hidden_data_def(name) | |
9c4b457e | 705 | # define libmvec_hidden_tls_def(name) |
829a679f AS |
706 | # define libmvec_hidden_data_weak(name) |
707 | # define libmvec_hidden_data_ver(local, name) | |
708 | #endif | |
709 | ||
9cd47470 | 710 | #if IS_IN (libresolv) |
6f9d8e68 | 711 | # define libresolv_hidden_proto(name, attrs...) hidden_proto (name, ##attrs) |
699df45b JM |
712 | # define libresolv_hidden_tls_proto(name, attrs...) \ |
713 | hidden_tls_proto (name, ##attrs) | |
6f9d8e68 UD |
714 | # define libresolv_hidden_def(name) hidden_def (name) |
715 | # define libresolv_hidden_weak(name) hidden_weak (name) | |
716 | # define libresolv_hidden_ver(local, name) hidden_ver (local, name) | |
717 | # define libresolv_hidden_data_def(name) hidden_data_def (name) | |
9c4b457e | 718 | # define libresolv_hidden_tls_def(name) hidden_tls_def (name) |
6f9d8e68 UD |
719 | # define libresolv_hidden_data_weak(name) hidden_data_weak (name) |
720 | # define libresolv_hidden_data_ver(local, name) hidden_data_ver (local, name) | |
721 | #else | |
722 | # define libresolv_hidden_proto(name, attrs...) | |
699df45b | 723 | # define libresolv_hidden_tls_proto(name, attrs...) |
6f9d8e68 UD |
724 | # define libresolv_hidden_def(name) |
725 | # define libresolv_hidden_weak(name) | |
726 | # define libresolv_hidden_ver(local, name) | |
727 | # define libresolv_hidden_data_def(name) | |
9c4b457e | 728 | # define libresolv_hidden_tls_def(name) |
6f9d8e68 UD |
729 | # define libresolv_hidden_data_weak(name) |
730 | # define libresolv_hidden_data_ver(local, name) | |
731 | #endif | |
732 | ||
9cd47470 | 733 | #if IS_IN (librt) |
a9564ae9 | 734 | # define librt_hidden_proto(name, attrs...) hidden_proto (name, ##attrs) |
699df45b JM |
735 | # define librt_hidden_tls_proto(name, attrs...) \ |
736 | hidden_tls_proto (name, ##attrs) | |
a9564ae9 UD |
737 | # define librt_hidden_def(name) hidden_def (name) |
738 | # define librt_hidden_weak(name) hidden_weak (name) | |
739 | # define librt_hidden_ver(local, name) hidden_ver (local, name) | |
740 | # define librt_hidden_data_def(name) hidden_data_def (name) | |
9c4b457e | 741 | # define librt_hidden_tls_def(name) hidden_tls_def (name) |
a9564ae9 UD |
742 | # define librt_hidden_data_weak(name) hidden_data_weak (name) |
743 | # define librt_hidden_data_ver(local, name) hidden_data_ver (local, name) | |
744 | #else | |
745 | # define librt_hidden_proto(name, attrs...) | |
699df45b | 746 | # define librt_hidden_tls_proto(name, attrs...) |
a9564ae9 UD |
747 | # define librt_hidden_def(name) |
748 | # define librt_hidden_weak(name) | |
749 | # define librt_hidden_ver(local, name) | |
750 | # define librt_hidden_data_def(name) | |
9c4b457e | 751 | # define librt_hidden_tls_def(name) |
a9564ae9 UD |
752 | # define librt_hidden_data_weak(name) |
753 | # define librt_hidden_data_ver(local, name) | |
754 | #endif | |
755 | ||
9cd47470 | 756 | #if IS_IN (libdl) |
5f21997b | 757 | # define libdl_hidden_proto(name, attrs...) hidden_proto (name, ##attrs) |
699df45b JM |
758 | # define libdl_hidden_tls_proto(name, attrs...) \ |
759 | hidden_tls_proto (name, ##attrs) | |
5f21997b UD |
760 | # define libdl_hidden_def(name) hidden_def (name) |
761 | # define libdl_hidden_weak(name) hidden_weak (name) | |
762 | # define libdl_hidden_ver(local, name) hidden_ver (local, name) | |
763 | # define libdl_hidden_data_def(name) hidden_data_def (name) | |
9c4b457e | 764 | # define libdl_hidden_tls_def(name) hidden_tls_def (name) |
5f21997b UD |
765 | # define libdl_hidden_data_weak(name) hidden_data_weak (name) |
766 | # define libdl_hidden_data_ver(local, name) hidden_data_ver (local, name) | |
767 | #else | |
768 | # define libdl_hidden_proto(name, attrs...) | |
699df45b | 769 | # define libdl_hidden_tls_proto(name, attrs...) |
5f21997b UD |
770 | # define libdl_hidden_def(name) |
771 | # define libdl_hidden_weak(name) | |
772 | # define libdl_hidden_ver(local, name) | |
773 | # define libdl_hidden_data_def(name) | |
9c4b457e | 774 | # define libdl_hidden_tls_def(name) |
5f21997b UD |
775 | # define libdl_hidden_data_weak(name) |
776 | # define libdl_hidden_data_ver(local, name) | |
777 | #endif | |
778 | ||
9cd47470 | 779 | #if IS_IN (libnss_files) |
44843eee | 780 | # define libnss_files_hidden_proto(name, attrs...) hidden_proto (name, ##attrs) |
699df45b JM |
781 | # define libnss_files_hidden_tls_proto(name, attrs...) \ |
782 | hidden_tls_proto (name, ##attrs) | |
44843eee UD |
783 | # define libnss_files_hidden_def(name) hidden_def (name) |
784 | # define libnss_files_hidden_weak(name) hidden_weak (name) | |
785 | # define libnss_files_hidden_ver(local, name) hidden_ver (local, name) | |
786 | # define libnss_files_hidden_data_def(name) hidden_data_def (name) | |
9c4b457e | 787 | # define libnss_files_hidden_tls_def(name) hidden_tls_def (name) |
44843eee UD |
788 | # define libnss_files_hidden_data_weak(name) hidden_data_weak (name) |
789 | # define libnss_files_hidden_data_ver(local, name) hidden_data_ver(local, name) | |
790 | #else | |
791 | # define libnss_files_hidden_proto(name, attrs...) | |
699df45b | 792 | # define libnss_files_hidden_tls_proto(name, attrs...) |
44843eee UD |
793 | # define libnss_files_hidden_def(name) |
794 | # define libnss_files_hidden_weak(name) | |
795 | # define libnss_files_hidden_ver(local, name) | |
796 | # define libnss_files_hidden_data_def(name) | |
9c4b457e | 797 | # define libnss_files_hidden_tls_def(name) |
44843eee UD |
798 | # define libnss_files_hidden_data_weak(name) |
799 | # define libnss_files_hidden_data_ver(local, name) | |
800 | #endif | |
801 | ||
9cd47470 | 802 | #if IS_IN (libnsl) |
1d5cee23 | 803 | # define libnsl_hidden_proto(name, attrs...) hidden_proto (name, ##attrs) |
699df45b JM |
804 | # define libnsl_hidden_tls_proto(name, attrs...) \ |
805 | hidden_tls_proto (name, ##attrs) | |
1e4d83f6 TK |
806 | # ifdef LINK_OBSOLETE_NSL |
807 | /* libnsl_hidden_nolink should only get used in libnsl code. */ | |
808 | # define libnsl_hidden_nolink_def(name, version) libnsl_hidden_def (name) | |
809 | # else | |
810 | # define libnsl_hidden_nolink_def(name, version) hidden_nolink (name, libnsl, version) | |
811 | # endif | |
1d5cee23 UD |
812 | # define libnsl_hidden_def(name) hidden_def (name) |
813 | # define libnsl_hidden_weak(name) hidden_weak (name) | |
814 | # define libnsl_hidden_ver(local, name) hidden_ver (local, name) | |
815 | # define libnsl_hidden_data_def(name) hidden_data_def (name) | |
9c4b457e | 816 | # define libnsl_hidden_tls_def(name) hidden_tls_def (name) |
1d5cee23 UD |
817 | # define libnsl_hidden_data_weak(name) hidden_data_weak (name) |
818 | # define libnsl_hidden_data_ver(local, name) hidden_data_ver (local, name) | |
819 | #else | |
820 | # define libnsl_hidden_proto(name, attrs...) | |
699df45b | 821 | # define libnsl_hidden_tls_proto(name, attrs...) |
1d5cee23 UD |
822 | # define libnsl_hidden_def(name) |
823 | # define libnsl_hidden_weak(name) | |
824 | # define libnsl_hidden_ver(local, name) | |
825 | # define libnsl_hidden_data_def(name) | |
9c4b457e | 826 | # define libnsl_hidden_tls_def(name) |
1d5cee23 UD |
827 | # define libnsl_hidden_data_weak(name) |
828 | # define libnsl_hidden_data_ver(local, name) | |
829 | #endif | |
830 | ||
9cd47470 | 831 | #if IS_IN (libnss_nisplus) |
b31b32b3 | 832 | # define libnss_nisplus_hidden_proto(name, attrs...) hidden_proto (name, ##attrs) |
699df45b JM |
833 | # define libnss_nisplus_hidden_tls_proto(name, attrs...) \ |
834 | hidden_tls_proto (name, ##attrs) | |
b31b32b3 UD |
835 | # define libnss_nisplus_hidden_def(name) hidden_def (name) |
836 | # define libnss_nisplus_hidden_weak(name) hidden_weak (name) | |
837 | # define libnss_nisplus_hidden_ver(local, name) hidden_ver (local, name) | |
838 | # define libnss_nisplus_hidden_data_def(name) hidden_data_def (name) | |
9c4b457e | 839 | # define libnss_nisplus_hidden_tls_def(name) hidden_tls_def (name) |
b31b32b3 UD |
840 | # define libnss_nisplus_hidden_data_weak(name) hidden_data_weak (name) |
841 | # define libnss_nisplus_hidden_data_ver(local, name) hidden_data_ver (local, name) | |
842 | #else | |
843 | # define libnss_nisplus_hidden_proto(name, attrs...) | |
699df45b | 844 | # define libnss_nisplus_hidden_tls_proto(name, attrs...) |
b31b32b3 UD |
845 | # define libnss_nisplus_hidden_def(name) |
846 | # define libnss_nisplus_hidden_weak(name) | |
847 | # define libnss_nisplus_hidden_ver(local, name) | |
848 | # define libnss_nisplus_hidden_data_def(name) | |
9c4b457e | 849 | # define libnss_nisplus_hidden_tls_def(name) |
b31b32b3 UD |
850 | # define libnss_nisplus_hidden_data_weak(name) |
851 | # define libnss_nisplus_hidden_data_ver(local, name) | |
852 | #endif | |
853 | ||
3ce1f295 UD |
854 | #define libc_hidden_builtin_proto(name, attrs...) libc_hidden_proto (name, ##attrs) |
855 | #define libc_hidden_builtin_def(name) libc_hidden_def (name) | |
856 | #define libc_hidden_builtin_weak(name) libc_hidden_weak (name) | |
857 | #define libc_hidden_builtin_ver(local, name) libc_hidden_ver (local, name) | |
858 | #ifdef __ASSEMBLER__ | |
859 | # define HIDDEN_BUILTIN_JUMPTARGET(name) HIDDEN_JUMPTARGET(name) | |
85dd1003 UD |
860 | #endif |
861 | ||
9cd47470 | 862 | #if IS_IN (libutil) |
b31b32b3 | 863 | # define libutil_hidden_proto(name, attrs...) hidden_proto (name, ##attrs) |
699df45b JM |
864 | # define libutil_hidden_tls_proto(name, attrs...) \ |
865 | hidden_tls_proto (name, ##attrs) | |
b31b32b3 UD |
866 | # define libutil_hidden_def(name) hidden_def (name) |
867 | # define libutil_hidden_weak(name) hidden_weak (name) | |
868 | # define libutil_hidden_ver(local, name) hidden_ver (local, name) | |
869 | # define libutil_hidden_data_def(name) hidden_data_def (name) | |
9c4b457e | 870 | # define libutil_hidden_tls_def(name) hidden_tls_def (name) |
b31b32b3 UD |
871 | # define libutil_hidden_data_weak(name) hidden_data_weak (name) |
872 | # define libutil_hidden_data_ver(local, name) hidden_data_ver (local, name) | |
873 | #else | |
874 | # define libutil_hidden_proto(name, attrs...) | |
699df45b | 875 | # define libutil_hidden_tls_proto(name, attrs...) |
b31b32b3 UD |
876 | # define libutil_hidden_def(name) |
877 | # define libutil_hidden_weak(name) | |
878 | # define libutil_hidden_ver(local, name) | |
879 | # define libutil_hidden_data_def(name) | |
9c4b457e | 880 | # define libutil_hidden_tls_def(name) |
b31b32b3 UD |
881 | # define libutil_hidden_data_weak(name) |
882 | # define libutil_hidden_data_ver(local, name) | |
883 | #endif | |
884 | ||
b30542fb UD |
885 | /* Get some dirty hacks. */ |
886 | #include <symbol-hacks.h> | |
887 | ||
4a381a81 UD |
888 | /* Move compatibility symbols out of the way by placing them all in a |
889 | special section. */ | |
d3a4a571 UD |
890 | #ifndef __ASSEMBLER__ |
891 | # define attribute_compat_text_section \ | |
4a381a81 | 892 | __attribute__ ((section (".text.compat"))) |
d3a4a571 | 893 | # define attribute_compat_data_section \ |
4a381a81 | 894 | __attribute__ ((section (".data.compat"))) |
d3a4a571 UD |
895 | #else |
896 | # define compat_text_section .section ".text.compat", "ax"; | |
897 | # define compat_data_section .section ".data.compat", "aw"; | |
898 | #endif | |
4a381a81 | 899 | |
00980d84 SL |
900 | /* Helper / base macros for indirect function symbols. */ |
901 | #define __ifunc_resolver(type_name, name, expr, arg, init, classifier) \ | |
ee4e992e MS |
902 | classifier inhibit_stack_protector \ |
903 | __typeof (type_name) *name##_ifunc (arg) \ | |
425ce2ed | 904 | { \ |
00980d84 SL |
905 | init (); \ |
906 | __typeof (type_name) *res = expr; \ | |
425ce2ed | 907 | return res; \ |
00980d84 SL |
908 | } |
909 | ||
910 | #ifdef HAVE_GCC_IFUNC | |
911 | # define __ifunc(type_name, name, expr, arg, init) \ | |
912 | extern __typeof (type_name) name __attribute__ \ | |
913 | ((ifunc (#name "_ifunc"))); \ | |
914 | __ifunc_resolver (type_name, name, expr, arg, init, static) | |
915 | ||
916 | # define __ifunc_hidden(type_name, name, expr, arg, init) \ | |
917 | __ifunc (type_name, name, expr, arg, init) | |
918 | #else | |
919 | /* Gcc does not support __attribute__ ((ifunc (...))). Use the old behaviour | |
920 | as fallback. But keep in mind that the debug information for the ifunc | |
921 | resolver functions is not correct. It contains the ifunc'ed function as | |
922 | DW_AT_linkage_name. E.g. lldb uses this field and an inferior function | |
923 | call of the ifunc'ed function will fail due to "no matching function for | |
924 | call to ..." because the ifunc'ed function and the resolver function have | |
925 | different signatures. (Gcc support is disabled at least on a ppc64le | |
926 | Ubuntu 14.04 system.) */ | |
927 | ||
928 | # define __ifunc(type_name, name, expr, arg, init) \ | |
929 | extern __typeof (type_name) name; \ | |
b513da7e | 930 | __typeof (type_name) *name##_ifunc (arg) __asm__ (#name); \ |
00980d84 SL |
931 | __ifunc_resolver (type_name, name, expr, arg, init,) \ |
932 | __asm__ (".type " #name ", %gnu_indirect_function"); | |
933 | ||
934 | # define __ifunc_hidden(type_name, name, expr, arg, init) \ | |
935 | extern __typeof (type_name) __libc_##name; \ | |
936 | __ifunc (type_name, __libc_##name, expr, arg, init) \ | |
937 | strong_alias (__libc_##name, name); | |
938 | #endif /* !HAVE_GCC_IFUNC */ | |
939 | ||
940 | /* The following macros are used for indirect function symbols in libc.so. | |
941 | First of all, you need to have the function prototyped somewhere, | |
942 | say in foo.h: | |
943 | ||
944 | int foo (int __bar); | |
945 | ||
946 | If you have an implementation for foo which e.g. uses a special hardware | |
947 | feature which isn't available on all machines where this libc.so will be | |
948 | used but decideable if available at runtime e.g. via hwcaps, you can provide | |
949 | two or multiple implementations of foo: | |
950 | ||
951 | int __foo_default (int __bar) | |
952 | { | |
953 | return __bar; | |
954 | } | |
955 | ||
956 | int __foo_special (int __bar) | |
957 | { | |
958 | return __bar; | |
959 | } | |
960 | ||
961 | If your function foo has no libc_hidden_proto (foo) defined for PLT | |
962 | bypassing, you can use: | |
963 | ||
964 | #define INIT_ARCH() unsigned long int hwcap = __GLRO(dl_hwcap); | |
965 | ||
966 | libc_ifunc (foo, (hwcap & HWCAP_SPECIAL) ? __foo_special : __foo_default); | |
967 | ||
968 | This will define a resolver function for foo which returns __foo_special or | |
969 | __foo_default depending on your specified expression. Please note that you | |
970 | have to define a macro function INIT_ARCH before using libc_ifunc macro as | |
971 | it is called by the resolver function before evaluating the specified | |
972 | expression. In this example it is used to prepare the hwcap variable. | |
973 | The resolver function is assigned to an ifunc'ed symbol foo. Calls to foo | |
974 | from inside or outside of libc.so will be indirected by a PLT call. | |
975 | ||
976 | If your function foo has a libc_hidden_proto (foo) defined for PLT bypassing | |
977 | and calls to foo within libc.so should always go to one specific | |
978 | implementation of foo e.g. __foo_default then you have to add: | |
979 | ||
980 | __hidden_ver1 (__foo_default, __GI_foo, __foo_default); | |
981 | ||
982 | or a tweaked definition of libc_hidden_def macro after the __foo_default | |
983 | function definition. Calls to foo within libc.so will always go directly to | |
984 | __foo_default. Calls to foo from outside libc.so will be indirected by a | |
985 | PLT call to ifunc'ed symbol foo which you have to define in a separate | |
986 | compile unit: | |
987 | ||
988 | #define foo __redirect_foo | |
989 | #include <foo.h> | |
990 | #undef foo | |
991 | ||
992 | extern __typeof (__redirect_foo) __foo_default attribute_hidden; | |
993 | extern __typeof (__redirect_foo) __foo_special attribute_hidden; | |
994 | ||
995 | libc_ifunc_redirected (__redirect_foo, foo, | |
996 | (hwcap & HWCAP_SPECIAL) | |
997 | ? __foo_special | |
998 | : __foo_default); | |
999 | ||
1000 | This will define the ifunc'ed symbol foo like above. The redirection of foo | |
1001 | in header file is needed to omit an additional defintion of __GI_foo which | |
1002 | would end in a linker error while linking libc.so. You have to specify | |
1003 | __redirect_foo as first parameter which is used within libc_ifunc_redirected | |
1004 | macro in conjunction with typeof to define the ifunc'ed symbol foo. | |
1005 | ||
1006 | If your function foo has a libc_hidden_proto (foo) defined and calls to foo | |
1007 | within or from outside libc.so should go via ifunc'ed symbol, then you have | |
1008 | to use: | |
1009 | ||
1010 | libc_ifunc_hidden (foo, foo, | |
1011 | (hwcap & HWCAP_SPECIAL) | |
1012 | ? __foo_special | |
1013 | : __foo_default); | |
1014 | libc_hidden_def (foo) | |
1015 | ||
1016 | The first parameter foo of libc_ifunc_hidden macro is used in the same way | |
1017 | as for libc_ifunc_redirected macro. */ | |
1018 | ||
1019 | #define libc_ifunc(name, expr) __ifunc (name, name, expr, void, INIT_ARCH) | |
1020 | ||
1021 | #define libc_ifunc_redirected(redirected_name, name, expr) \ | |
1022 | __ifunc (redirected_name, name, expr, void, INIT_ARCH) | |
1023 | ||
1024 | #define libc_ifunc_hidden(redirected_name, name, expr) \ | |
1025 | __ifunc_hidden (redirected_name, name, expr, void, INIT_ARCH) | |
425ce2ed | 1026 | |
9a1d2d45 UD |
1027 | /* The body of the function is supposed to use __get_cpu_features |
1028 | which will, if necessary, initialize the data first. */ | |
00980d84 SL |
1029 | #define libm_ifunc_init() |
1030 | #define libm_ifunc(name, expr) \ | |
1031 | __ifunc (name, name, expr, void, libm_ifunc_init) | |
9a1d2d45 | 1032 | |
85c2e611 AZ |
1033 | /* Add the compiler optimization to inhibit loop transformation to library |
1034 | calls. This is used to avoid recursive calls in memset and memmove | |
1035 | default implementations. */ | |
1036 | #ifdef HAVE_CC_INHIBIT_LOOP_TO_LIBCALL | |
1037 | # define inhibit_loop_to_libcall \ | |
1038 | __attribute__ ((__optimize__ ("-fno-tree-loop-distribute-patterns"))) | |
1039 | #else | |
1040 | # define inhibit_loop_to_libcall | |
1041 | #endif | |
0f3be872 ZW |
1042 | \f |
1043 | /* These macros facilitate sharing source files with gnulib. | |
1044 | ||
1045 | They are here instead of sys/cdefs.h because they should not be | |
1046 | used in public header files. | |
1047 | ||
1048 | Their definitions should be kept consistent with the definitions in | |
1049 | gnulib-common.m4, but it is not necessary to cater to old non-GCC | |
1050 | compilers, since they will only be used while building glibc itself. | |
1051 | (Note that _GNUC_PREREQ cannot be used in this file.) */ | |
1052 | ||
1053 | /* Define as a marker that can be attached to declarations that might not | |
1054 | be used. This helps to reduce warnings, such as from | |
1055 | GCC -Wunused-parameter. */ | |
1056 | #if __GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7) | |
1057 | # define _GL_UNUSED __attribute__ ((__unused__)) | |
1058 | #else | |
1059 | # define _GL_UNUSED | |
1060 | #endif | |
1061 | ||
1062 | /* gcc supports the "unused" attribute on possibly unused labels, and | |
1063 | g++ has since version 4.5. Note to support C++ as well as C, | |
1064 | _GL_UNUSED_LABEL should be used with a trailing ; */ | |
1065 | #if !defined __cplusplus || __GNUC__ > 4 \ | |
1066 | || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) | |
1067 | # define _GL_UNUSED_LABEL _GL_UNUSED | |
1068 | #else | |
1069 | # define _GL_UNUSED_LABEL | |
1070 | #endif | |
1071 | ||
1072 | /* The __pure__ attribute was added in gcc 2.96. */ | |
1073 | #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96) | |
1074 | # define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__)) | |
1075 | #else | |
1076 | # define _GL_ATTRIBUTE_PURE /* empty */ | |
1077 | #endif | |
1078 | ||
1079 | /* The __const__ attribute was added in gcc 2.95. */ | |
1080 | #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95) | |
1081 | # define _GL_ATTRIBUTE_CONST __attribute__ ((__const__)) | |
1082 | #else | |
1083 | # define _GL_ATTRIBUTE_CONST /* empty */ | |
1084 | #endif | |
85c2e611 | 1085 | |
7c3018f9 | 1086 | #endif /* !_ISOMAC */ |
28f540f4 | 1087 | #endif /* libc-symbols.h */ |