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