x86_64: Remove _dl_skip_args usage
[glibc.git] / include / libc-symbols.h
blob4bb3d8c7ba55d9c07a6193db537b57c44a97996d
1 /* Support macros for making weak and strong aliases for symbols,
2 and for using symbol sets and linker warnings with GNU ld.
3 Copyright (C) 1995-2022 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <https://www.gnu.org/licenses/>. */
20 #ifndef _LIBC_SYMBOLS_H
21 #define _LIBC_SYMBOLS_H 1
23 /* This file is included implicitly in the compilation of every source file,
24 using -include. It includes config.h. */
26 /* Enable declarations of GNU extensions, since we are compiling them. */
27 #define _GNU_SOURCE 1
29 #ifdef MODULE_NAME
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)
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)
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
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
62 #ifndef _ISOMAC
64 /* This is defined for the compilation of all C library code. features.h
65 tests this to avoid inclusion of stubs.h while compiling the library,
66 before stubs.h has been generated. Some library code that is shared
67 with other packages also tests this symbol to see if it is being
68 compiled as part of the C library. We must define this before including
69 config.h, because it makes some definitions conditional on whether libc
70 itself is being compiled, or just some generator program. */
71 #define _LIBC 1
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
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
85 #include <config.h>
87 /* Obtain the definition of symbol_version_reference. */
88 #include <libc-symver.h>
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
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
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! */
109 #define STDC_HEADERS 1
110 #define HAVE_MBSTATE_T 1
111 #define HAVE_MBSRTOWCS 1
112 #define HAVE_LIBINTL_H 1
113 #define HAVE_WCTYPE_H 1
114 #define HAVE_ISWCTYPE 1
115 #define ENABLE_NLS 1
117 /* The symbols in all the user (non-_) macros are C symbols. */
119 #ifndef __SYMBOL_PREFIX
120 # define __SYMBOL_PREFIX
121 #endif
123 #ifndef C_SYMBOL_NAME
124 # define C_SYMBOL_NAME(name) name
125 #endif
127 #ifndef ASM_LINE_SEP
128 # define ASM_LINE_SEP ;
129 #endif
131 #ifndef __attribute_copy__
132 /* Provide an empty definition when cdefs.h is not included. */
133 # define __attribute_copy__(arg)
134 #endif
136 #ifndef __ASSEMBLER__
137 /* GCC understands weak symbols and aliases; use its interface where
138 possible, instead of embedded assembly language. */
140 /* Define ALIASNAME as a strong alias for NAME. */
141 # define strong_alias(name, aliasname) _strong_alias(name, aliasname)
142 # define _strong_alias(name, aliasname) \
143 extern __typeof (name) aliasname __attribute__ ((alias (#name))) \
144 __attribute_copy__ (name);
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__))
151 /* Define ALIASNAME as a weak alias for NAME.
152 If weak aliases are not available, this defines a strong alias. */
153 # define weak_alias(name, aliasname) _weak_alias (name, aliasname)
154 # define _weak_alias(name, aliasname) \
155 extern __typeof (name) aliasname __attribute__ ((weak, alias (#name))) \
156 __attribute_copy__ (name);
158 /* Same as WEAK_ALIAS, but mark symbol as hidden. */
159 # define weak_hidden_alias(name, aliasname) \
160 _weak_hidden_alias (name, aliasname)
161 # define _weak_hidden_alias(name, aliasname) \
162 extern __typeof (name) aliasname \
163 __attribute__ ((weak, alias (#name), __visibility__ ("hidden"))) \
164 __attribute_copy__ (name);
166 /* Declare SYMBOL as weak undefined symbol (resolved to 0 if not defined). */
167 # define weak_extern(symbol) _weak_extern (weak symbol)
168 # define _weak_extern(expr) _Pragma (#expr)
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); \
184 # endif
186 #else /* __ASSEMBLER__ */
188 # ifdef HAVE_ASM_SET_DIRECTIVE
189 # define strong_alias(original, alias) \
190 .globl C_SYMBOL_NAME (alias) ASM_LINE_SEP \
191 .set C_SYMBOL_NAME (alias),C_SYMBOL_NAME (original)
192 # define strong_data_alias(original, alias) strong_alias(original, alias)
193 # else
194 # define strong_alias(original, alias) \
195 .globl C_SYMBOL_NAME (alias) ASM_LINE_SEP \
196 C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original)
197 # define strong_data_alias(original, alias) strong_alias(original, alias)
198 # endif
200 # define weak_alias(original, alias) \
201 .weak C_SYMBOL_NAME (alias) ASM_LINE_SEP \
202 C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original)
204 # define weak_extern(symbol) \
205 .weak C_SYMBOL_NAME (symbol)
207 #endif /* __ASSEMBLER__ */
209 /* Determine the return address. */
210 #define RETURN_ADDRESS(nr) \
211 __builtin_extract_return_addr (__builtin_return_address (nr))
213 /* When a reference to SYMBOL is encountered, the linker will emit a
214 warning message MSG. */
215 /* We want the .gnu.warning.SYMBOL section to be unallocated. */
216 #define __make_section_unallocated(section_string) \
217 asm (".section " section_string "\n\t.previous");
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. */
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) \
227 __make_section_unallocated (".gnu.warning." #symbol) \
228 static const char __evoke_link_warning_##symbol[] \
229 __attribute__ ((used, section (".gnu.warning." #symbol __sec_comment))) \
230 = msg;
232 /* A canned warning for sysdeps/stub functions. */
233 #define stub_warning(name) \
234 __make_section_unallocated (".gnu.glibc-stub." #name) \
235 link_warning (name, #name " is not implemented and will always fail")
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
248 /* Resource Freeing Hooks:
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.
256 A single public API exists and is __libc_freeres(), and this is used
257 by applications like valgrind to freee resouces.
259 There are 3 cases:
261 (a) __libc_freeres
263 In this case all you need to do is define the freeing routine:
265 foo.c:
266 libfoo_freeres_fn (foo_freeres)
268 complex_free (mem);
271 This ensures the function is called at the right point to free
272 resources.
274 (b) __libc_freeres_ptr
276 The framework for (a) iterates over the list of pointers-to-free
277 in (b) and frees them.
279 foo.c:
280 libc_freeres_ptr (static char *foo_buffer);
282 Freeing these resources alaways happens last and is equivalent
283 to registering a function that does 'free (foo_buffer)'.
285 (c) Explicit lists of free routines to call or objects to free.
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.
292 As of today the following subsystems use (c):
294 Per-thread cleanup:
295 * malloc/thread-freeres.c
297 libdl cleanup:
298 * dlfcn/dlfreeres.c
300 libpthread cleanup:
301 * nptl/nptlfreeres.c
303 So if you need any shutdown routines to run you should add them
304 directly to the appropriate subsystem's shutdown list. */
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)))
311 /* Resource freeing functions from libc.so go in this section. */
312 #define __libc_freeres_fn_section \
313 __attribute__ ((__used__, section ("__libc_freeres_fn")))
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)
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).
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. */
327 #ifdef __ASSEMBLER__
328 # define declare_object_symbol_alias(symbol, original, size) \
329 declare_object_symbol_alias_1 (symbol, original, size)
330 # define declare_object_symbol_alias_1(symbol, original, s_size) \
331 strong_alias (original, symbol) ASM_LINE_SEP \
332 .type C_SYMBOL_NAME (symbol), %object ASM_LINE_SEP \
333 .size C_SYMBOL_NAME (symbol), s_size ASM_LINE_SEP
334 #else /* Not __ASSEMBLER__. */
335 # define declare_symbol_alias(symbol, original, type, size) \
336 declare_symbol_alias_1 (symbol, original, type, size)
337 # define declare_symbol_alias_1(symbol, original, type, size) \
338 asm (".globl " __SYMBOL_PREFIX #symbol \
339 "\n\t" declare_symbol_alias_1_alias (symbol, original) \
340 "\n\t.type " __SYMBOL_PREFIX #symbol ", " \
341 "%" #type \
342 "\n\t.size " __SYMBOL_PREFIX #symbol ", " #size);
343 # ifdef HAVE_ASM_SET_DIRECTIVE
344 # define declare_symbol_alias_1_alias(symbol, original) \
345 ".set " __SYMBOL_PREFIX #symbol ", " __SYMBOL_PREFIX #original
346 # else
347 # define declare_symbol_alias_1_alias(symbol, original) \
348 __SYMBOL_PREFIX #symbol " = " __SYMBOL_PREFIX #original
349 # endif /* HAVE_ASM_SET_DIRECTIVE */
350 #endif /* __ASSEMBLER__ */
357 #ifdef HAVE_GNU_RETAIN
358 # define attribute_used_retain __attribute__ ((__used__, __retain__))
359 #else
360 # define attribute_used_retain __attribute__ ((__used__))
361 #endif
363 /* Symbol set support macros. */
365 /* Make SYMBOL, which is in the text segment, an element of SET. */
366 #define text_set_element(set, symbol) _elf_set_element(set, symbol)
367 /* Make SYMBOL, which is in the data segment, an element of SET. */
368 #define data_set_element(set, symbol) _elf_set_element(set, symbol)
369 /* Make SYMBOL, which is in the bss segment, an element of SET. */
370 #define bss_set_element(set, symbol) _elf_set_element(set, symbol)
372 /* These are all done the same way in ELF.
373 There is a new section created for each set. */
374 #ifdef SHARED
375 /* When building a shared library, make the set section writable,
376 because it will need to be relocated at run time anyway. */
377 # define _elf_set_element(set, symbol) \
378 static const void *__elf_set_##set##_element_##symbol##__ \
379 attribute_used_retain __attribute__ ((section (#set))) = &(symbol)
380 #else
381 # define _elf_set_element(set, symbol) \
382 static const void *const __elf_set_##set##_element_##symbol##__ \
383 attribute_used_retain __attribute__ ((section (#set))) = &(symbol)
384 #endif
386 /* Define SET as a symbol set. This may be required (it is in a.out) to
387 be able to use the set's contents. */
388 #define symbol_set_define(set) symbol_set_declare(set)
390 /* Declare SET for use in this module, if defined in another module.
391 In a shared library, this is always local to that shared object.
392 For static linking, the set might be wholly absent and so we use
393 weak references. */
394 #define symbol_set_declare(set) \
395 extern char const __start_##set[] __symbol_set_attribute; \
396 extern char const __stop_##set[] __symbol_set_attribute;
397 #ifdef SHARED
398 # define __symbol_set_attribute attribute_hidden
399 #else
400 # define __symbol_set_attribute __attribute__ ((weak))
401 #endif
403 /* Return a pointer (void *const *) to the first element of SET. */
404 #define symbol_set_first_element(set) ((void *const *) (&__start_##set))
406 /* Return true iff PTR (a void *const *) has been incremented
407 past the last element in SET. */
408 #define symbol_set_end_p(set, ptr) ((ptr) >= (void *const *) &__stop_##set)
410 #ifdef SHARED
411 # define symbol_version(real, name, version) \
412 symbol_version_reference(real, name, version)
413 # define default_symbol_version(real, name, version) \
414 _default_symbol_version(real, name, version)
415 /* See <libc-symver.h>. */
416 # ifdef __ASSEMBLER__
417 # define _default_symbol_version(real, name, version) \
418 _set_symbol_version (real, name@@version)
419 # else
420 # define _default_symbol_version(real, name, version) \
421 _set_symbol_version (real, #name "@@" #version)
422 # endif
424 /* Evalutes to a string literal for VERSION in LIB. */
425 # define symbol_version_string(lib, version) \
426 _symbol_version_stringify_1 (VERSION_##lib##_##version)
427 # define _symbol_version_stringify_1(arg) _symbol_version_stringify_2 (arg)
428 # define _symbol_version_stringify_2(arg) #arg
430 #else /* !SHARED */
431 # define symbol_version(real, name, version)
432 # define default_symbol_version(real, name, version) \
433 strong_alias(real, name)
434 #endif
436 #if defined SHARED || defined LIBC_NONSHARED \
437 || (BUILD_PIE_DEFAULT && IS_IN (libc))
438 # define attribute_hidden __attribute__ ((visibility ("hidden")))
439 #else
440 # define attribute_hidden
441 #endif
443 #define attribute_tls_model_ie __attribute__ ((tls_model ("initial-exec")))
445 #define attribute_relro __attribute__ ((section (".data.rel.ro")))
448 /* Used to disable stack protection in sensitive places, like ifunc
449 resolvers and early static TLS init. */
450 #ifdef HAVE_CC_NO_STACK_PROTECTOR
451 # define inhibit_stack_protector \
452 __attribute__ ((__optimize__ ("-fno-stack-protector")))
453 #else
454 # define inhibit_stack_protector
455 #endif
457 /* The following macros are used for PLT bypassing within libc.so
458 (and if needed other libraries similarly).
459 First of all, you need to have the function prototyped somewhere,
460 say in foo/foo.h:
462 int foo (int __bar);
464 If calls to foo within libc.so should always go to foo defined in libc.so,
465 then in include/foo.h you add:
467 libc_hidden_proto (foo)
469 line and after the foo function definition:
471 int foo (int __bar)
473 return __bar;
475 libc_hidden_def (foo)
479 int foo (int __bar)
481 return __bar;
483 libc_hidden_weak (foo)
485 Similarly for global data. If references to foo within libc.so should
486 always go to foo defined in libc.so, then in include/foo.h you add:
488 libc_hidden_proto (foo)
490 line and after foo's definition:
492 int foo = INITIAL_FOO_VALUE;
493 libc_hidden_data_def (foo)
497 int foo = INITIAL_FOO_VALUE;
498 libc_hidden_data_weak (foo)
500 If foo is normally just an alias (strong or weak) to some other function,
501 you should use the normal strong_alias first, then add libc_hidden_def
502 or libc_hidden_weak:
504 int baz (int __bar)
506 return __bar;
508 strong_alias (baz, foo)
509 libc_hidden_weak (foo)
511 If the function should be internal to multiple objects, say ld.so and
512 libc.so, the best way is to use:
514 #if IS_IN (libc) || IS_IN (rtld)
515 hidden_proto (foo)
516 #endif
518 in include/foo.h and the normal macros at all function definitions
519 depending on what DSO they belong to.
521 If versioned_symbol macro is used to define foo,
522 libc_hidden_ver macro should be used, as in:
524 int __real_foo (int __bar)
526 return __bar;
528 versioned_symbol (libc, __real_foo, foo, GLIBC_2_1);
529 libc_hidden_ver (__real_foo, foo) */
531 #if defined SHARED && !defined NO_HIDDEN
532 # ifndef __ASSEMBLER__
533 # define __hidden_proto_hiddenattr(attrs...) \
534 __attribute__ ((visibility ("hidden"), ##attrs))
535 # define hidden_proto(name, attrs...) \
536 __hidden_proto (name, , __GI_##name, ##attrs)
537 # define hidden_tls_proto(name, attrs...) \
538 __hidden_proto (name, __thread, __GI_##name, ##attrs)
539 # define __hidden_proto(name, thread, internal, attrs...) \
540 extern thread __typeof (name) name __asm__ (__hidden_asmname (#internal)) \
541 __hidden_proto_hiddenattr (attrs);
542 # define __hidden_asmname(name) \
543 __hidden_asmname1 (__USER_LABEL_PREFIX__, name)
544 # define __hidden_asmname1(prefix, name) __hidden_asmname2(prefix, name)
545 # define __hidden_asmname2(prefix, name) #prefix name
546 # define __hidden_ver1(local, internal, name) \
547 __hidden_ver2 (, local, internal, name)
548 # define __hidden_ver2(thread, local, internal, name) \
549 extern thread __typeof (name) __EI_##name \
550 __asm__(__hidden_asmname (#internal)); \
551 extern thread __typeof (name) __EI_##name \
552 __attribute__((alias (__hidden_asmname (#local)))) \
553 __attribute_copy__ (name)
554 # define hidden_ver(local, name) __hidden_ver1(local, __GI_##name, name);
555 # define hidden_data_ver(local, name) hidden_ver(local, name)
556 # define hidden_def(name) __hidden_ver1(__GI_##name, name, name);
557 # define hidden_data_def(name) hidden_def(name)
558 # define hidden_tls_def(name) \
559 __hidden_ver2 (__thread, __GI_##name, name, name);
560 # define hidden_weak(name) \
561 __hidden_ver1(__GI_##name, name, name) __attribute__((weak));
562 # define hidden_data_weak(name) hidden_weak(name)
563 # define hidden_nolink(name, lib, version) \
564 __hidden_nolink1 (__GI_##name, __EI_##name, name, VERSION_##lib##_##version)
565 # define __hidden_nolink1(local, internal, name, version) \
566 __hidden_nolink2 (local, internal, name, version)
567 # define __hidden_nolink2(local, internal, name, version) \
568 extern __typeof (name) internal __attribute__ ((alias (#local))) \
569 __attribute_copy__ (name); \
570 __hidden_nolink3 (local, internal, #name "@" #version)
571 # define __hidden_nolink3(local, internal, vername) \
572 __asm__ (".symver " #internal ", " vername);
573 # else
574 /* For assembly, we need to do the opposite of what we do in C:
575 in assembly gcc __REDIRECT stuff is not in place, so functions
576 are defined by its normal name and we need to create the
577 __GI_* alias to it, in C __REDIRECT causes the function definition
578 to use __GI_* name and we need to add alias to the real name.
579 There is no reason to use hidden_weak over hidden_def in assembly,
580 but we provide it for consistency with the C usage.
581 hidden_proto doesn't make sense for assembly but the equivalent
582 is to call via the HIDDEN_JUMPTARGET macro instead of JUMPTARGET. */
583 # define hidden_def(name) strong_alias (name, __GI_##name)
584 # define hidden_weak(name) hidden_def (name)
585 # define hidden_ver(local, name) strong_alias (local, __GI_##name)
586 # define hidden_data_def(name) strong_data_alias (name, __GI_##name)
587 # define hidden_tls_def(name) hidden_data_def (name)
588 # define hidden_data_weak(name) hidden_data_def (name)
589 # define hidden_data_ver(local, name) strong_data_alias (local, __GI_##name)
590 # define HIDDEN_JUMPTARGET(name) __GI_##name
591 # endif
592 #else
593 # ifndef __ASSEMBLER__
594 # if !defined SHARED && IS_IN (libc) && !defined LIBC_NONSHARED \
595 && (!defined PIC || !defined NO_HIDDEN_EXTERN_FUNC_IN_PIE) \
596 && !defined NO_HIDDEN
597 # define __hidden_proto_hiddenattr(attrs...) \
598 __attribute__ ((visibility ("hidden"), ##attrs))
599 # define hidden_proto(name, attrs...) \
600 __hidden_proto (name, , name, ##attrs)
601 # define hidden_tls_proto(name, attrs...) \
602 __hidden_proto (name, __thread, name, ##attrs)
603 # define __hidden_proto(name, thread, internal, attrs...) \
604 extern thread __typeof (name) name __hidden_proto_hiddenattr (attrs);
605 # else
606 # define hidden_proto(name, attrs...)
607 # define hidden_tls_proto(name, attrs...)
608 # endif
609 # else
610 # define HIDDEN_JUMPTARGET(name) JUMPTARGET(name)
611 # endif /* Not __ASSEMBLER__ */
612 # define hidden_weak(name)
613 # define hidden_def(name)
614 # define hidden_ver(local, name)
615 # define hidden_data_weak(name)
616 # define hidden_data_def(name)
617 # define hidden_tls_def(name)
618 # define hidden_data_ver(local, name)
619 # define hidden_nolink(name, lib, version)
620 #endif
622 #if IS_IN (libc)
623 # define libc_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
624 # define libc_hidden_tls_proto(name, attrs...) hidden_tls_proto (name, ##attrs)
625 # define libc_hidden_def(name) hidden_def (name)
626 # define libc_hidden_weak(name) hidden_weak (name)
627 # define libc_hidden_nolink_sunrpc(name, version) hidden_nolink (name, libc, version)
628 # define libc_hidden_ver(local, name) hidden_ver (local, name)
629 # define libc_hidden_data_def(name) hidden_data_def (name)
630 # define libc_hidden_tls_def(name) hidden_tls_def (name)
631 # define libc_hidden_data_weak(name) hidden_data_weak (name)
632 # define libc_hidden_data_ver(local, name) hidden_data_ver (local, name)
633 #else
634 # define libc_hidden_proto(name, attrs...)
635 # define libc_hidden_tls_proto(name, attrs...)
636 # define libc_hidden_def(name)
637 # define libc_hidden_weak(name)
638 # define libc_hidden_ver(local, name)
639 # define libc_hidden_data_def(name)
640 # define libc_hidden_tls_def(name)
641 # define libc_hidden_data_weak(name)
642 # define libc_hidden_data_ver(local, name)
643 #endif
645 #if IS_IN (rtld)
646 # define rtld_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
647 # define rtld_hidden_tls_proto(name, attrs...) hidden_tls_proto (name, ##attrs)
648 # define rtld_hidden_def(name) hidden_def (name)
649 # define rtld_hidden_weak(name) hidden_weak (name)
650 # define rtld_hidden_ver(local, name) hidden_ver (local, name)
651 # define rtld_hidden_data_def(name) hidden_data_def (name)
652 # define rtld_hidden_tls_def(name) hidden_tls_def (name)
653 # define rtld_hidden_data_weak(name) hidden_data_weak (name)
654 # define rtld_hidden_data_ver(local, name) hidden_data_ver (local, name)
655 #else
656 # define rtld_hidden_proto(name, attrs...)
657 # define rtld_hidden_tls_proto(name, attrs...)
658 # define rtld_hidden_def(name)
659 # define rtld_hidden_weak(name)
660 # define rtld_hidden_ver(local, name)
661 # define rtld_hidden_data_def(name)
662 # define rtld_hidden_tls_def(name)
663 # define rtld_hidden_data_weak(name)
664 # define rtld_hidden_data_ver(local, name)
665 #endif
667 #if IS_IN (libm)
668 # define libm_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
669 # define libm_hidden_tls_proto(name, attrs...) hidden_tls_proto (name, ##attrs)
670 # define libm_hidden_def(name) hidden_def (name)
671 # define libm_hidden_weak(name) hidden_weak (name)
672 # define libm_hidden_ver(local, name) hidden_ver (local, name)
673 # define libm_hidden_data_def(name) hidden_data_def (name)
674 # define libm_hidden_tls_def(name) hidden_tls_def (name)
675 # define libm_hidden_data_weak(name) hidden_data_weak (name)
676 # define libm_hidden_data_ver(local, name) hidden_data_ver (local, name)
677 #else
678 # define libm_hidden_proto(name, attrs...)
679 # define libm_hidden_tls_proto(name, attrs...)
680 # define libm_hidden_def(name)
681 # define libm_hidden_weak(name)
682 # define libm_hidden_ver(local, name)
683 # define libm_hidden_data_def(name)
684 # define libm_hidden_tls_def(name)
685 # define libm_hidden_data_weak(name)
686 # define libm_hidden_data_ver(local, name)
687 #endif
689 #if IS_IN (libmvec)
690 # define libmvec_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
691 # define libmvec_hidden_tls_proto(name, attrs...) hidden_tls_proto (name, ##attrs)
692 # define libmvec_hidden_def(name) hidden_def (name)
693 # define libmvec_hidden_weak(name) hidden_weak (name)
694 # define libmvec_hidden_ver(local, name) hidden_ver (local, name)
695 # define libmvec_hidden_data_def(name) hidden_data_def (name)
696 # define libmvec_hidden_tls_def(name) hidden_tls_def (name)
697 # define libmvec_hidden_data_weak(name) hidden_data_weak (name)
698 # define libmvec_hidden_data_ver(local, name) hidden_data_ver (local, name)
699 #else
700 # define libmvec_hidden_proto(name, attrs...)
701 # define libmvec_hidden_tls_proto(name, attrs...)
702 # define libmvec_hidden_def(name)
703 # define libmvec_hidden_weak(name)
704 # define libmvec_hidden_ver(local, name)
705 # define libmvec_hidden_data_def(name)
706 # define libmvec_hidden_tls_def(name)
707 # define libmvec_hidden_data_weak(name)
708 # define libmvec_hidden_data_ver(local, name)
709 #endif
711 #if IS_IN (libresolv)
712 # define libresolv_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
713 # define libresolv_hidden_tls_proto(name, attrs...) \
714 hidden_tls_proto (name, ##attrs)
715 # define libresolv_hidden_def(name) hidden_def (name)
716 # define libresolv_hidden_weak(name) hidden_weak (name)
717 # define libresolv_hidden_ver(local, name) hidden_ver (local, name)
718 # define libresolv_hidden_data_def(name) hidden_data_def (name)
719 # define libresolv_hidden_tls_def(name) hidden_tls_def (name)
720 # define libresolv_hidden_data_weak(name) hidden_data_weak (name)
721 # define libresolv_hidden_data_ver(local, name) hidden_data_ver (local, name)
722 #else
723 # define libresolv_hidden_proto(name, attrs...)
724 # define libresolv_hidden_tls_proto(name, attrs...)
725 # define libresolv_hidden_def(name)
726 # define libresolv_hidden_weak(name)
727 # define libresolv_hidden_ver(local, name)
728 # define libresolv_hidden_data_def(name)
729 # define libresolv_hidden_tls_def(name)
730 # define libresolv_hidden_data_weak(name)
731 # define libresolv_hidden_data_ver(local, name)
732 #endif
734 #if IS_IN (libpthread)
735 # define libpthread_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
736 # define libpthread_hidden_tls_proto(name, attrs...) \
737 hidden_tls_proto (name, ##attrs)
738 # define libpthread_hidden_def(name) hidden_def (name)
739 # define libpthread_hidden_weak(name) hidden_weak (name)
740 # define libpthread_hidden_ver(local, name) hidden_ver (local, name)
741 # define libpthread_hidden_data_def(name) hidden_data_def (name)
742 # define libpthread_hidden_tls_def(name) hidden_tls_def (name)
743 # define libpthread_hidden_data_weak(name) hidden_data_weak (name)
744 # define libpthread_hidden_data_ver(local, name) hidden_data_ver (local, name)
745 #else
746 # define libpthread_hidden_proto(name, attrs...)
747 # define libpthread_hidden_tls_proto(name, attrs...)
748 # define libpthread_hidden_def(name)
749 # define libpthread_hidden_weak(name)
750 # define libpthread_hidden_ver(local, name)
751 # define libpthread_hidden_data_def(name)
752 # define libpthread_hidden_tls_def(name)
753 # define libpthread_hidden_data_weak(name)
754 # define libpthread_hidden_data_ver(local, name)
755 #endif
757 #if IS_IN (librt)
758 # define librt_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
759 # define librt_hidden_tls_proto(name, attrs...) \
760 hidden_tls_proto (name, ##attrs)
761 # define librt_hidden_def(name) hidden_def (name)
762 # define librt_hidden_weak(name) hidden_weak (name)
763 # define librt_hidden_ver(local, name) hidden_ver (local, name)
764 # define librt_hidden_data_def(name) hidden_data_def (name)
765 # define librt_hidden_tls_def(name) hidden_tls_def (name)
766 # define librt_hidden_data_weak(name) hidden_data_weak (name)
767 # define librt_hidden_data_ver(local, name) hidden_data_ver (local, name)
768 #else
769 # define librt_hidden_proto(name, attrs...)
770 # define librt_hidden_tls_proto(name, attrs...)
771 # define librt_hidden_def(name)
772 # define librt_hidden_weak(name)
773 # define librt_hidden_ver(local, name)
774 # define librt_hidden_data_def(name)
775 # define librt_hidden_tls_def(name)
776 # define librt_hidden_data_weak(name)
777 # define librt_hidden_data_ver(local, name)
778 #endif
780 #if IS_IN (libdl)
781 # define libdl_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
782 # define libdl_hidden_tls_proto(name, attrs...) \
783 hidden_tls_proto (name, ##attrs)
784 # define libdl_hidden_def(name) hidden_def (name)
785 # define libdl_hidden_weak(name) hidden_weak (name)
786 # define libdl_hidden_ver(local, name) hidden_ver (local, name)
787 # define libdl_hidden_data_def(name) hidden_data_def (name)
788 # define libdl_hidden_tls_def(name) hidden_tls_def (name)
789 # define libdl_hidden_data_weak(name) hidden_data_weak (name)
790 # define libdl_hidden_data_ver(local, name) hidden_data_ver (local, name)
791 #else
792 # define libdl_hidden_proto(name, attrs...)
793 # define libdl_hidden_tls_proto(name, attrs...)
794 # define libdl_hidden_def(name)
795 # define libdl_hidden_weak(name)
796 # define libdl_hidden_ver(local, name)
797 # define libdl_hidden_data_def(name)
798 # define libdl_hidden_tls_def(name)
799 # define libdl_hidden_data_weak(name)
800 # define libdl_hidden_data_ver(local, name)
801 #endif
803 #if IS_IN (libnsl)
804 # define libnsl_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
805 # define libnsl_hidden_tls_proto(name, attrs...) \
806 hidden_tls_proto (name, ##attrs)
807 # define libnsl_hidden_nolink_def(name, version) hidden_nolink (name, libnsl, version)
808 # define libnsl_hidden_weak(name) hidden_weak (name)
809 # define libnsl_hidden_ver(local, name) hidden_ver (local, name)
810 # define libnsl_hidden_data_def(name) hidden_data_def (name)
811 # define libnsl_hidden_tls_def(name) hidden_tls_def (name)
812 # define libnsl_hidden_data_weak(name) hidden_data_weak (name)
813 # define libnsl_hidden_data_ver(local, name) hidden_data_ver (local, name)
814 #else
815 # define libnsl_hidden_proto(name, attrs...)
816 # define libnsl_hidden_tls_proto(name, attrs...)
817 # define libnsl_hidden_weak(name)
818 # define libnsl_hidden_ver(local, name)
819 # define libnsl_hidden_data_def(name)
820 # define libnsl_hidden_tls_def(name)
821 # define libnsl_hidden_data_weak(name)
822 # define libnsl_hidden_data_ver(local, name)
823 #endif
825 #define libc_hidden_builtin_proto(name, attrs...) libc_hidden_proto (name, ##attrs)
826 #define libc_hidden_builtin_def(name) libc_hidden_def (name)
827 #define libc_hidden_builtin_weak(name) libc_hidden_weak (name)
828 #define libc_hidden_builtin_ver(local, name) libc_hidden_ver (local, name)
830 #define libc_hidden_ldbl_proto(name, attrs...) libc_hidden_proto (name, ##attrs)
831 #ifdef __ASSEMBLER__
832 # define HIDDEN_BUILTIN_JUMPTARGET(name) HIDDEN_JUMPTARGET(name)
833 #endif
835 #if IS_IN (libutil)
836 # define libutil_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
837 # define libutil_hidden_tls_proto(name, attrs...) \
838 hidden_tls_proto (name, ##attrs)
839 # define libutil_hidden_def(name) hidden_def (name)
840 # define libutil_hidden_weak(name) hidden_weak (name)
841 # define libutil_hidden_ver(local, name) hidden_ver (local, name)
842 # define libutil_hidden_data_def(name) hidden_data_def (name)
843 # define libutil_hidden_tls_def(name) hidden_tls_def (name)
844 # define libutil_hidden_data_weak(name) hidden_data_weak (name)
845 # define libutil_hidden_data_ver(local, name) hidden_data_ver (local, name)
846 #else
847 # define libutil_hidden_proto(name, attrs...)
848 # define libutil_hidden_tls_proto(name, attrs...)
849 # define libutil_hidden_def(name)
850 # define libutil_hidden_weak(name)
851 # define libutil_hidden_ver(local, name)
852 # define libutil_hidden_data_def(name)
853 # define libutil_hidden_tls_def(name)
854 # define libutil_hidden_data_weak(name)
855 # define libutil_hidden_data_ver(local, name)
856 #endif
858 #if IS_IN (libanl)
859 # define libanl_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
860 # define libanl_hidden_def(name) hidden_def (name)
861 #else
862 # define libanl_hidden_proto(name, attrs...)
863 # define libanl_hidden_def(name)
864 #endif
866 /* Get some dirty hacks. */
867 #include <symbol-hacks.h>
869 /* Move compatibility symbols out of the way by placing them all in a
870 special section. */
871 #ifndef __ASSEMBLER__
872 # define attribute_compat_text_section \
873 __attribute__ ((section (".text.compat")))
874 # define attribute_compat_data_section \
875 __attribute__ ((section (".data.compat")))
876 #else
877 # define compat_text_section .section ".text.compat", "ax";
878 # define compat_data_section .section ".data.compat", "aw";
879 #endif
881 /* Helper / base macros for indirect function symbols. */
882 #define __ifunc_resolver(type_name, name, expr, arg, init, classifier) \
883 classifier inhibit_stack_protector \
884 __typeof (type_name) *name##_ifunc (arg) \
886 init (); \
887 __typeof (type_name) *res = expr; \
888 return res; \
891 #ifdef HAVE_GCC_IFUNC
892 # define __ifunc(type_name, name, expr, arg, init) \
893 extern __typeof (type_name) name __attribute__ \
894 ((ifunc (#name "_ifunc"))); \
895 __ifunc_resolver (type_name, name, expr, arg, init, static)
897 # define __ifunc_hidden(type_name, name, expr, arg, init) \
898 __ifunc (type_name, name, expr, arg, init)
899 #else
900 /* Gcc does not support __attribute__ ((ifunc (...))). Use the old behaviour
901 as fallback. But keep in mind that the debug information for the ifunc
902 resolver functions is not correct. It contains the ifunc'ed function as
903 DW_AT_linkage_name. E.g. lldb uses this field and an inferior function
904 call of the ifunc'ed function will fail due to "no matching function for
905 call to ..." because the ifunc'ed function and the resolver function have
906 different signatures. (Gcc support is disabled at least on a ppc64le
907 Ubuntu 14.04 system.) */
909 # define __ifunc(type_name, name, expr, arg, init) \
910 extern __typeof (type_name) name; \
911 __typeof (type_name) *name##_ifunc (arg) __asm__ (#name); \
912 __ifunc_resolver (type_name, name, expr, arg, init,) \
913 __asm__ (".type " #name ", %gnu_indirect_function");
915 # define __ifunc_hidden(type_name, name, expr, arg, init) \
916 extern __typeof (type_name) __libc_##name; \
917 __ifunc (type_name, __libc_##name, expr, arg, init) \
918 strong_alias (__libc_##name, name);
919 #endif /* !HAVE_GCC_IFUNC */
921 /* The following macros are used for indirect function symbols in libc.so.
922 First of all, you need to have the function prototyped somewhere,
923 say in foo.h:
925 int foo (int __bar);
927 If you have an implementation for foo which e.g. uses a special hardware
928 feature which isn't available on all machines where this libc.so will be
929 used but decideable if available at runtime e.g. via hwcaps, you can provide
930 two or multiple implementations of foo:
932 int __foo_default (int __bar)
934 return __bar;
937 int __foo_special (int __bar)
939 return __bar;
942 If your function foo has no libc_hidden_proto (foo) defined for PLT
943 bypassing, you can use:
945 #define INIT_ARCH() unsigned long int hwcap = __GLRO(dl_hwcap);
947 libc_ifunc (foo, (hwcap & HWCAP_SPECIAL) ? __foo_special : __foo_default);
949 This will define a resolver function for foo which returns __foo_special or
950 __foo_default depending on your specified expression. Please note that you
951 have to define a macro function INIT_ARCH before using libc_ifunc macro as
952 it is called by the resolver function before evaluating the specified
953 expression. In this example it is used to prepare the hwcap variable.
954 The resolver function is assigned to an ifunc'ed symbol foo. Calls to foo
955 from inside or outside of libc.so will be indirected by a PLT call.
957 If your function foo has a libc_hidden_proto (foo) defined for PLT bypassing
958 and calls to foo within libc.so should always go to one specific
959 implementation of foo e.g. __foo_default then you have to add:
961 __hidden_ver1 (__foo_default, __GI_foo, __foo_default);
963 or a tweaked definition of libc_hidden_def macro after the __foo_default
964 function definition. Calls to foo within libc.so will always go directly to
965 __foo_default. Calls to foo from outside libc.so will be indirected by a
966 PLT call to ifunc'ed symbol foo which you have to define in a separate
967 compile unit:
969 #define foo __redirect_foo
970 #include <foo.h>
971 #undef foo
973 extern __typeof (__redirect_foo) __foo_default attribute_hidden;
974 extern __typeof (__redirect_foo) __foo_special attribute_hidden;
976 libc_ifunc_redirected (__redirect_foo, foo,
977 (hwcap & HWCAP_SPECIAL)
978 ? __foo_special
979 : __foo_default);
981 This will define the ifunc'ed symbol foo like above. The redirection of foo
982 in header file is needed to omit an additional defintion of __GI_foo which
983 would end in a linker error while linking libc.so. You have to specify
984 __redirect_foo as first parameter which is used within libc_ifunc_redirected
985 macro in conjunction with typeof to define the ifunc'ed symbol foo.
987 If your function foo has a libc_hidden_proto (foo) defined and calls to foo
988 within or from outside libc.so should go via ifunc'ed symbol, then you have
989 to use:
991 libc_ifunc_hidden (foo, foo,
992 (hwcap & HWCAP_SPECIAL)
993 ? __foo_special
994 : __foo_default);
995 libc_hidden_def (foo)
997 The first parameter foo of libc_ifunc_hidden macro is used in the same way
998 as for libc_ifunc_redirected macro. */
1000 #define libc_ifunc(name, expr) __ifunc (name, name, expr, void, INIT_ARCH)
1002 #define libc_ifunc_redirected(redirected_name, name, expr) \
1003 __ifunc (redirected_name, name, expr, void, INIT_ARCH)
1005 #define libc_ifunc_hidden(redirected_name, name, expr) \
1006 __ifunc_hidden (redirected_name, name, expr, void, INIT_ARCH)
1008 /* The body of the function is supposed to use __get_cpu_features
1009 which will, if necessary, initialize the data first. */
1010 #define libm_ifunc_init()
1011 #define libm_ifunc(name, expr) \
1012 __ifunc (name, name, expr, void, libm_ifunc_init)
1014 /* Add the compiler optimization to inhibit loop transformation to library
1015 calls. This is used to avoid recursive calls in memset and memmove
1016 default implementations. */
1017 #ifdef HAVE_CC_INHIBIT_LOOP_TO_LIBCALL
1018 # define inhibit_loop_to_libcall \
1019 __attribute__ ((__optimize__ ("-fno-tree-loop-distribute-patterns")))
1020 #else
1021 # define inhibit_loop_to_libcall
1022 #endif
1024 /* These macros facilitate sharing source files with gnulib.
1026 They are here instead of sys/cdefs.h because they should not be
1027 used in public header files.
1029 Their definitions should be kept consistent with the definitions in
1030 gnulib-common.m4, but it is not necessary to cater to old non-GCC
1031 compilers, since they will only be used while building glibc itself.
1032 (Note that _GNUC_PREREQ cannot be used in this file.) */
1034 /* Define as a marker that can be attached to declarations that might not
1035 be used. This helps to reduce warnings, such as from
1036 GCC -Wunused-parameter. */
1037 #if __GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
1038 # define _GL_UNUSED __attribute__ ((__unused__))
1039 #else
1040 # define _GL_UNUSED
1041 #endif
1043 /* gcc supports the "unused" attribute on possibly unused labels, and
1044 g++ has since version 4.5. Note to support C++ as well as C,
1045 _GL_UNUSED_LABEL should be used with a trailing ; */
1046 #if !defined __cplusplus || __GNUC__ > 4 \
1047 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
1048 # define _GL_UNUSED_LABEL _GL_UNUSED
1049 #else
1050 # define _GL_UNUSED_LABEL
1051 #endif
1053 /* The __pure__ attribute was added in gcc 2.96. */
1054 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
1055 # define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
1056 #else
1057 # define _GL_ATTRIBUTE_PURE /* empty */
1058 #endif
1060 /* The __const__ attribute was added in gcc 2.95. */
1061 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)
1062 # define _GL_ATTRIBUTE_CONST __attribute__ ((__const__))
1063 #else
1064 # define _GL_ATTRIBUTE_CONST /* empty */
1065 #endif
1067 #endif /* !_ISOMAC */
1068 #endif /* libc-symbols.h */