]> git.ipfire.org Git - thirdparty/glibc.git/blame - include/libc-symbols.h
manual: Remove '.info' suffix in manual names passed to @ref [BZ #32962].
[thirdparty/glibc.git] / include / libc-symbols.h
CommitLineData
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.
26420023 3 Copyright (C) 1995-2025 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
494eb254
L
62#include <libc-misc.h>
63
7c3018f9 64#ifndef _ISOMAC
28f540f4 65
92777700
RM
66/* This is defined for the compilation of all C library code. features.h
67 tests this to avoid inclusion of stubs.h while compiling the library,
68 before stubs.h has been generated. Some library code that is shared
69 with other packages also tests this symbol to see if it is being
70 compiled as part of the C library. We must define this before including
71 config.h, because it makes some definitions conditional on whether libc
72 itself is being compiled, or just some generator program. */
c709e372 73#define _LIBC 1
92777700 74
7c3018f9
ZW
75/* Some files must be compiled with optimization on. */
76#if !defined __ASSEMBLER__ && !defined __OPTIMIZE__
77# error "glibc cannot be compiled without optimization"
78#endif
79
80/* -ffast-math cannot be applied to the C library, as it alters the ABI.
81 Some test components that use -ffast-math are currently not part of
82 IS_IN (testsuite) for technical reasons, so we have a secondary override. */
83#if defined __FAST_MATH__ && !defined TEST_FAST_MATH
84# error "glibc must not be compiled with -ffast-math"
85#endif
d3669add 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
UD
157
158/* Declare SYMBOL as weak undefined symbol (resolved to 0 if not defined). */
a0da5fe1
UD
159# define weak_extern(symbol) _weak_extern (weak symbol)
160# define _weak_extern(expr) _Pragma (#expr)
428383e8 161
ef4f9764
FW
162/* In shared builds, the expression call_function_static_weak
163 (FUNCTION-SYMBOL, ARGUMENTS) invokes FUNCTION-SYMBOL (an
164 identifier) unconditionally, with the (potentially empty) argument
165 list ARGUMENTS. In static builds, if FUNCTION-SYMBOL has a
166 definition, the function is invoked as before; if FUNCTION-SYMBOL
167 is NULL, no call is performed. */
168# ifdef SHARED
169# define call_function_static_weak(func, ...) func (__VA_ARGS__)
170# else /* !SHARED */
171# define call_function_static_weak(func, ...) \
172 ({ \
173 extern __typeof__ (func) func weak_function; \
174 (func != NULL ? func (__VA_ARGS__) : (void)0); \
175 })
176# endif
428383e8
UD
177
178#else /* __ASSEMBLER__ */
179
180# ifdef HAVE_ASM_SET_DIRECTIVE
5ca10a0c 181# define strong_alias(original, alias) \
7b8e0d49 182 .globl C_SYMBOL_NAME (alias) ASM_LINE_SEP \
c843e065 183 .set C_SYMBOL_NAME (alias),C_SYMBOL_NAME (original)
5ca10a0c 184# define strong_data_alias(original, alias) strong_alias(original, alias)
dfd2257a 185# else
5ca10a0c 186# define strong_alias(original, alias) \
7b8e0d49 187 .globl C_SYMBOL_NAME (alias) ASM_LINE_SEP \
c843e065 188 C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original)
5ca10a0c 189# define strong_data_alias(original, alias) strong_alias(original, alias)
dfd2257a 190# endif
d02907df 191
210dd782 192# define weak_alias(original, alias) \
c843e065 193 .weak C_SYMBOL_NAME (alias) ASM_LINE_SEP \
28f540f4 194 C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original)
e6964dd4 195
210dd782 196# define weak_extern(symbol) \
af5b3bc3 197 .weak C_SYMBOL_NAME (symbol)
d02907df 198
428383e8 199#endif /* __ASSEMBLER__ */
958f803f 200
e862aada
UD
201/* Determine the return address. */
202#define RETURN_ADDRESS(nr) \
203 __builtin_extract_return_addr (__builtin_return_address (nr))
204
44c8d1a2
RM
205/* When a reference to SYMBOL is encountered, the linker will emit a
206 warning message MSG. */
fd26970f 207/* We want the .gnu.warning.SYMBOL section to be unallocated. */
75b0964b 208#define __make_section_unallocated(section_string) \
b15cb495 209 asm (".section " section_string "\n\t.previous");
fd26970f 210
a2d2c620 211/* Tacking on "\n\t#" to the section name makes gcc put its bogus
b15cb495 212 section attributes on what looks like a comment to the assembler. */
0269750c
UD
213#ifdef HAVE_SECTION_QUOTES
214# define __sec_comment "\"\n\t#\""
215#else
216# define __sec_comment "\n\t#"
217#endif
218#define link_warning(symbol, msg) \
e26dd47f 219 __make_section_unallocated (".gnu.warning." #symbol) \
44c8d1a2 220 static const char __evoke_link_warning_##symbol[] \
6c5775c3 221 __attribute__ ((used, section (".gnu.warning." #symbol __sec_comment))) \
c877418f 222 = msg;
28f540f4
RM
223
224/* A canned warning for sysdeps/stub functions. */
225#define stub_warning(name) \
561bcb80 226 __make_section_unallocated (".gnu.glibc-stub." #name) \
cd525923 227 link_warning (name, #name " is not implemented and will always fail")
5f9e57ba 228
2f7f7bc6
UD
229/* Warning for linking functions calling dlopen into static binaries. */
230#ifdef SHARED
231#define static_link_warning(name)
232#else
233#define static_link_warning(name) static_link_warning1(name)
234#define static_link_warning1(name) \
235 link_warning(name, "Using '" #name "' in statically linked applications \
236requires at runtime the shared libraries from the glibc version used \
237for linking")
238#endif
b88ac073 239
11bf311e
UD
240/* Declare SYMBOL to be TYPE (`function' or `object') of SIZE bytes
241 alias to ORIGINAL, when the assembler supports such declarations
242 (such as in ELF).
b88ac073
RM
243 This is only necessary when defining something in assembly, or playing
244 funny alias games where the size should be other than what the compiler
245 thinks it is. */
3020f726 246#define declare_object_symbol_alias(symbol, original, size) \
111254f3 247 declare_object_symbol_alias_1 (symbol, original, size)
3020f726 248#ifdef __ASSEMBLER__
111254f3
L
249# define declare_object_symbol_alias_1(symbol, original, s_size) \
250 strong_alias (original, symbol) ASM_LINE_SEP \
251 .type C_SYMBOL_NAME (symbol), %object ASM_LINE_SEP \
252 .size C_SYMBOL_NAME (symbol), s_size ASM_LINE_SEP
b67e9372 253#else /* Not __ASSEMBLER__. */
b67e9372 254# ifdef HAVE_ASM_SET_DIRECTIVE
3020f726
AZN
255# define declare_object_symbol_alias_1(symbol, original, size) \
256 asm (".global " __SYMBOL_PREFIX # symbol "\n" \
257 ".type " __SYMBOL_PREFIX # symbol ", %object\n" \
258 ".set " __SYMBOL_PREFIX #symbol ", " __SYMBOL_PREFIX original "\n" \
259 ".size " __SYMBOL_PREFIX #symbol ", " #size "\n");
b67e9372 260# else
3020f726
AZN
261# define declare_object_symbol_alias_1(symbol, original, size) \
262 asm (".global " __SYMBOL_PREFIX # symbol "\n" \
263 ".type " __SYMBOL_PREFIX # symbol ", %object\n" \
264 __SYMBOL_PREFIX #symbol " = " __SYMBOL_PREFIX original "\n" \
265 ".size " __SYMBOL_PREFIX #symbol ", " #size "\n");
b67e9372
MP
266# endif /* HAVE_ASM_SET_DIRECTIVE */
267#endif /* __ASSEMBLER__ */
b88ac073
RM
268
269
5f9e57ba 270/*
28f540f4 271\f
5f9e57ba
RM
272*/
273
cd6ae7ea
FS
274#ifdef HAVE_GNU_RETAIN
275# define attribute_used_retain __attribute__ ((__used__, __retain__))
276#else
277# define attribute_used_retain __attribute__ ((__used__))
278#endif
279
28f540f4
RM
280/* Symbol set support macros. */
281
28f540f4 282/* Make SYMBOL, which is in the text segment, an element of SET. */
0269750c 283#define text_set_element(set, symbol) _elf_set_element(set, symbol)
28f540f4 284/* Make SYMBOL, which is in the data segment, an element of SET. */
0269750c 285#define data_set_element(set, symbol) _elf_set_element(set, symbol)
28f540f4 286/* Make SYMBOL, which is in the bss segment, an element of SET. */
0269750c 287#define bss_set_element(set, symbol) _elf_set_element(set, symbol)
28f540f4
RM
288
289/* These are all done the same way in ELF.
290 There is a new section created for each set. */
0269750c 291#ifdef SHARED
53afa8d9
RM
292/* When building a shared library, make the set section writable,
293 because it will need to be relocated at run time anyway. */
0269750c 294# define _elf_set_element(set, symbol) \
cd6ae7ea
FS
295 static const void *__elf_set_##set##_element_##symbol##__ \
296 attribute_used_retain __attribute__ ((section (#set))) = &(symbol)
0269750c
UD
297#else
298# define _elf_set_element(set, symbol) \
cd6ae7ea
FS
299 static const void *const __elf_set_##set##_element_##symbol##__ \
300 attribute_used_retain __attribute__ ((section (#set))) = &(symbol)
0269750c 301#endif
28f540f4
RM
302
303/* Define SET as a symbol set. This may be required (it is in a.out) to
304 be able to use the set's contents. */
0269750c 305#define symbol_set_define(set) symbol_set_declare(set)
28f540f4 306
20792f99
RM
307/* Declare SET for use in this module, if defined in another module.
308 In a shared library, this is always local to that shared object.
309 For static linking, the set might be wholly absent and so we use
310 weak references. */
0269750c 311#define symbol_set_declare(set) \
6f1e513d
RH
312 extern char const __start_##set[] __symbol_set_attribute; \
313 extern char const __stop_##set[] __symbol_set_attribute;
0269750c
UD
314#ifdef SHARED
315# define __symbol_set_attribute attribute_hidden
316#else
317# define __symbol_set_attribute __attribute__ ((weak))
318#endif
28f540f4
RM
319
320/* Return a pointer (void *const *) to the first element of SET. */
0269750c 321#define symbol_set_first_element(set) ((void *const *) (&__start_##set))
28f540f4
RM
322
323/* Return true iff PTR (a void *const *) has been incremented
324 past the last element in SET. */
0269750c 325#define symbol_set_end_p(set, ptr) ((ptr) >= (void *const *) &__stop_##set)
28f540f4 326
3f2e46a4 327#ifdef SHARED
ebdf53a7 328# define symbol_version(real, name, version) \
968dc26d 329 symbol_version_reference(real, name, version)
ebdf53a7
GM
330# define default_symbol_version(real, name, version) \
331 _default_symbol_version(real, name, version)
0923f74a 332/* See <libc-symver.h>. */
ebdf53a7 333# ifdef __ASSEMBLER__
5ca10a0c 334# define _default_symbol_version(real, name, version) \
0923f74a 335 _set_symbol_version (real, name@@version)
da2d1bc5 336# else
5ca10a0c 337# define _default_symbol_version(real, name, version) \
0923f74a 338 _set_symbol_version (real, #name "@@" #version)
da2d1bc5 339# endif
3a0ecccb 340
7f0d9e61 341/* Evaluates to a string literal for VERSION in LIB. */
3a0ecccb
FW
342# define symbol_version_string(lib, version) \
343 _symbol_version_stringify_1 (VERSION_##lib##_##version)
344# define _symbol_version_stringify_1(arg) _symbol_version_stringify_2 (arg)
345# define _symbol_version_stringify_2(arg) #arg
346
347#else /* !SHARED */
1ea89a40 348# define symbol_version(real, name, version)
da2d1bc5
UD
349# define default_symbol_version(real, name, version) \
350 strong_alias(real, name)
1ea89a40
UD
351#endif
352
df359a25
SN
353#if defined SHARED || defined LIBC_NONSHARED \
354 || (BUILD_PIE_DEFAULT && IS_IN (libc))
e6caf4e1
UD
355# define attribute_hidden __attribute__ ((visibility ("hidden")))
356#else
357# define attribute_hidden
358#endif
359
3ce1f295 360#define attribute_tls_model_ie __attribute__ ((tls_model ("initial-exec")))
9b21e6bc 361
11bf311e 362#define attribute_relro __attribute__ ((section (".data.rel.ro")))
392a6b52 363
de659123 364
37ba7d66
UD
365/* The following macros are used for PLT bypassing within libc.so
366 (and if needed other libraries similarly).
367 First of all, you need to have the function prototyped somewhere,
368 say in foo/foo.h:
369
370 int foo (int __bar);
371
372 If calls to foo within libc.so should always go to foo defined in libc.so,
373 then in include/foo.h you add:
374
375 libc_hidden_proto (foo)
376
377 line and after the foo function definition:
378
379 int foo (int __bar)
380 {
381 return __bar;
382 }
383 libc_hidden_def (foo)
384
385 or
386
387 int foo (int __bar)
388 {
389 return __bar;
390 }
391 libc_hidden_weak (foo)
392
5536dfcb 393 Similarly for global data. If references to foo within libc.so should
c843e065
RM
394 always go to foo defined in libc.so, then in include/foo.h you add:
395
396 libc_hidden_proto (foo)
397
398 line and after foo's definition:
399
400 int foo = INITIAL_FOO_VALUE;
401 libc_hidden_data_def (foo)
402
403 or
404
405 int foo = INITIAL_FOO_VALUE;
406 libc_hidden_data_weak (foo)
407
5536dfcb 408 If foo is normally just an alias (strong or weak) to some other function,
37ba7d66
UD
409 you should use the normal strong_alias first, then add libc_hidden_def
410 or libc_hidden_weak:
411
412 int baz (int __bar)
413 {
414 return __bar;
415 }
416 strong_alias (baz, foo)
417 libc_hidden_weak (foo)
418
419 If the function should be internal to multiple objects, say ld.so and
420 libc.so, the best way is to use:
421
9cd47470 422 #if IS_IN (libc) || IS_IN (rtld)
37ba7d66
UD
423 hidden_proto (foo)
424 #endif
425
426 in include/foo.h and the normal macros at all function definitions
427 depending on what DSO they belong to.
428
429 If versioned_symbol macro is used to define foo,
430 libc_hidden_ver macro should be used, as in:
431
432 int __real_foo (int __bar)
433 {
434 return __bar;
435 }
436 versioned_symbol (libc, __real_foo, foo, GLIBC_2_1);
437 libc_hidden_ver (__real_foo, foo) */
438
3f2e46a4 439#if defined SHARED && !defined NO_HIDDEN
37ba7d66 440# ifndef __ASSEMBLER__
11bf311e 441# define __hidden_proto_hiddenattr(attrs...) \
81cb0d82 442 __attribute__ ((visibility ("hidden"), ##attrs))
81cb0d82 443# define hidden_proto(name, attrs...) \
699df45b 444 __hidden_proto (name, , __GI_##name, ##attrs)
baf2a265
AZ
445# define hidden_proto_alias(name, alias, attrs...) \
446 __hidden_proto_alias (name, , alias, ##attrs)
699df45b
JM
447# define hidden_tls_proto(name, attrs...) \
448 __hidden_proto (name, __thread, __GI_##name, ##attrs)
449# define __hidden_proto(name, thread, internal, attrs...) \
450 extern thread __typeof (name) name __asm__ (__hidden_asmname (#internal)) \
81cb0d82 451 __hidden_proto_hiddenattr (attrs);
baf2a265
AZ
452# define __hidden_proto_alias(name, thread, internal, attrs...) \
453 extern thread __typeof (name) internal __hidden_proto_hiddenattr (attrs);
37ba7d66
UD
454# define __hidden_asmname(name) \
455 __hidden_asmname1 (__USER_LABEL_PREFIX__, name)
456# define __hidden_asmname1(prefix, name) __hidden_asmname2(prefix, name)
457# define __hidden_asmname2(prefix, name) #prefix name
61995d3e 458# define __hidden_ver1(local, internal, name) \
9c4b457e
JM
459 __hidden_ver2 (, local, internal, name)
460# define __hidden_ver2(thread, local, internal, name) \
461 extern thread __typeof (name) __EI_##name \
462 __asm__(__hidden_asmname (#internal)); \
463 extern thread __typeof (name) __EI_##name \
1626a1cf
MS
464 __attribute__((alias (__hidden_asmname (#local)))) \
465 __attribute_copy__ (name)
61995d3e 466# define hidden_ver(local, name) __hidden_ver1(local, __GI_##name, name);
61995d3e 467# define hidden_def(name) __hidden_ver1(__GI_##name, name, name);
baf2a265
AZ
468# define hidden_def_alias(name, internal) \
469 strong_alias (name, internal)
61995d3e 470# define hidden_data_def(name) hidden_def(name)
baf2a265 471# define hidden_data_def_alias(name, alias) hidden_def_alias(name, alias)
9c4b457e
JM
472# define hidden_tls_def(name) \
473 __hidden_ver2 (__thread, __GI_##name, name, name);
61995d3e
RM
474# define hidden_weak(name) \
475 __hidden_ver1(__GI_##name, name, name) __attribute__((weak));
476# define hidden_data_weak(name) hidden_weak(name)
7b57bfe5
UD
477# define hidden_nolink(name, lib, version) \
478 __hidden_nolink1 (__GI_##name, __EI_##name, name, VERSION_##lib##_##version)
479# define __hidden_nolink1(local, internal, name, version) \
480 __hidden_nolink2 (local, internal, name, version)
481# define __hidden_nolink2(local, internal, name, version) \
1626a1cf
MS
482 extern __typeof (name) internal __attribute__ ((alias (#local))) \
483 __attribute_copy__ (name); \
7b57bfe5
UD
484 __hidden_nolink3 (local, internal, #name "@" #version)
485# define __hidden_nolink3(local, internal, vername) \
486 __asm__ (".symver " #internal ", " vername);
37ba7d66
UD
487# else
488/* For assembly, we need to do the opposite of what we do in C:
489 in assembly gcc __REDIRECT stuff is not in place, so functions
490 are defined by its normal name and we need to create the
491 __GI_* alias to it, in C __REDIRECT causes the function definition
492 to use __GI_* name and we need to add alias to the real name.
4547dee3
RM
493 There is no reason to use hidden_weak over hidden_def in assembly,
494 but we provide it for consistency with the C usage.
495 hidden_proto doesn't make sense for assembly but the equivalent
dce8f2b6 496 is to call via the HIDDEN_JUMPTARGET macro instead of JUMPTARGET. */
4547dee3 497# define hidden_def(name) strong_alias (name, __GI_##name)
baf2a265 498# define hidden_def_alias(name, alias) strong_alias (name, alias)
4547dee3 499# define hidden_weak(name) hidden_def (name)
37ba7d66 500# define hidden_ver(local, name) strong_alias (local, __GI_##name)
c843e065 501# define hidden_data_def(name) strong_data_alias (name, __GI_##name)
baf2a265 502# define hidden_data_def_alias(name, alias) strong_data_alias (name, alias)
9c4b457e 503# define hidden_tls_def(name) hidden_data_def (name)
c843e065 504# define hidden_data_weak(name) hidden_data_def (name)
5ca10a0c 505# define HIDDEN_JUMPTARGET(name) __GI_##name
37ba7d66
UD
506# endif
507#else
4547dee3 508# ifndef __ASSEMBLER__
8d2ec553 509# if !defined SHARED && IS_IN (libc) && !defined LIBC_NONSHARED \
ee417882 510 && (!defined PIC || !defined NO_HIDDEN_EXTERN_FUNC_IN_PIE) \
8d2ec553
L
511 && !defined NO_HIDDEN
512# define __hidden_proto_hiddenattr(attrs...) \
513 __attribute__ ((visibility ("hidden"), ##attrs))
514# define hidden_proto(name, attrs...) \
515 __hidden_proto (name, , name, ##attrs)
baf2a265
AZ
516# define hidden_proto_alias(name, alias, attrs...) \
517 __hidden_proto_alias (name, , alias, ##attrs)
8d2ec553
L
518# define hidden_tls_proto(name, attrs...) \
519 __hidden_proto (name, __thread, name, ##attrs)
520# define __hidden_proto(name, thread, internal, attrs...) \
521 extern thread __typeof (name) name __hidden_proto_hiddenattr (attrs);
baf2a265
AZ
522# define __hidden_proto_alias(name, thread, internal, attrs...) \
523 extern thread __typeof (name) internal __hidden_proto_hiddenattr (attrs);
8d2ec553
L
524# else
525# define hidden_proto(name, attrs...)
baf2a265 526# define hidden_proto_alias(name, alias, attrs...)
8d2ec553
L
527# define hidden_tls_proto(name, attrs...)
528# endif
4547dee3
RM
529# else
530# define HIDDEN_JUMPTARGET(name) JUMPTARGET(name)
531# endif /* Not __ASSEMBLER__ */
532# define hidden_weak(name)
37ba7d66 533# define hidden_def(name)
baf2a265 534# define hidden_def_alias(name, alias)
37ba7d66 535# define hidden_ver(local, name)
c843e065
RM
536# define hidden_data_weak(name)
537# define hidden_data_def(name)
baf2a265 538# define hidden_data_def_alias(name, alias)
9c4b457e 539# define hidden_tls_def(name)
1792c087 540# define hidden_nolink(name, lib, version)
37ba7d66
UD
541#endif
542
4f41c682 543#if IS_IN (libc)
81cb0d82 544# define libc_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
baf2a265
AZ
545# define libc_hidden_proto_alias(name, alias, attrs...) \
546 hidden_proto_alias (name, alias, ##attrs)
699df45b 547# define libc_hidden_tls_proto(name, attrs...) hidden_tls_proto (name, ##attrs)
37ba7d66
UD
548# define libc_hidden_def(name) hidden_def (name)
549# define libc_hidden_weak(name) hidden_weak (name)
5500cdba 550# define libc_hidden_nolink_sunrpc(name, version) hidden_nolink (name, libc, version)
37ba7d66 551# define libc_hidden_ver(local, name) hidden_ver (local, name)
c843e065 552# define libc_hidden_data_def(name) hidden_data_def (name)
baf2a265 553# define libc_hidden_data_def_alias(name, alias) hidden_data_def_alias (name, alias)
9c4b457e 554# define libc_hidden_tls_def(name) hidden_tls_def (name)
c843e065 555# define libc_hidden_data_weak(name) hidden_data_weak (name)
37ba7d66 556#else
81cb0d82 557# define libc_hidden_proto(name, attrs...)
baf2a265 558# define libc_hidden_proto_alias(name, alias, attrs...)
699df45b 559# define libc_hidden_tls_proto(name, attrs...)
37ba7d66
UD
560# define libc_hidden_def(name)
561# define libc_hidden_weak(name)
562# define libc_hidden_ver(local, name)
c843e065 563# define libc_hidden_data_def(name)
baf2a265 564# define libc_hidden_data_def_alias(name, alias)
9c4b457e 565# define libc_hidden_tls_def(name)
c843e065 566# define libc_hidden_data_weak(name)
37ba7d66
UD
567#endif
568
3d3316b1 569#if IS_IN (rtld)
81cb0d82 570# define rtld_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
37ba7d66
UD
571# define rtld_hidden_def(name) hidden_def (name)
572# define rtld_hidden_weak(name) hidden_weak (name)
c843e065 573# define rtld_hidden_data_def(name) hidden_data_def (name)
37ba7d66 574#else
81cb0d82 575# define rtld_hidden_proto(name, attrs...)
37ba7d66
UD
576# define rtld_hidden_def(name)
577# define rtld_hidden_weak(name)
c843e065 578# define rtld_hidden_data_def(name)
37ba7d66
UD
579#endif
580
9cd47470 581#if IS_IN (libm)
81cb0d82 582# define libm_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
37ba7d66
UD
583# define libm_hidden_def(name) hidden_def (name)
584# define libm_hidden_weak(name) hidden_weak (name)
585# define libm_hidden_ver(local, name) hidden_ver (local, name)
586#else
81cb0d82 587# define libm_hidden_proto(name, attrs...)
37ba7d66
UD
588# define libm_hidden_def(name)
589# define libm_hidden_weak(name)
590# define libm_hidden_ver(local, name)
591#endif
592
829a679f 593#if IS_IN (libmvec)
cc0d77ba 594# define libmvec_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
829a679f 595# define libmvec_hidden_def(name) hidden_def (name)
829a679f 596#else
cc0d77ba 597# define libmvec_hidden_proto(name, attrs...)
829a679f 598# define libmvec_hidden_def(name)
829a679f
AS
599#endif
600
9cd47470 601#if IS_IN (libresolv)
6f9d8e68
UD
602# define libresolv_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
603# define libresolv_hidden_def(name) hidden_def (name)
6f9d8e68 604# define libresolv_hidden_data_def(name) hidden_data_def (name)
6f9d8e68
UD
605#else
606# define libresolv_hidden_proto(name, attrs...)
607# define libresolv_hidden_def(name)
6f9d8e68 608# define libresolv_hidden_data_def(name)
6f9d8e68
UD
609#endif
610
e3022f4b
FW
611#if IS_IN (libpthread)
612# define libpthread_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
e3022f4b 613# define libpthread_hidden_def(name) hidden_def (name)
e3022f4b
FW
614#else
615# define libpthread_hidden_proto(name, attrs...)
e3022f4b 616# define libpthread_hidden_def(name)
e3022f4b
FW
617#endif
618
9cd47470 619#if IS_IN (librt)
a9564ae9 620# define librt_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
a9564ae9 621# define librt_hidden_ver(local, name) hidden_ver (local, name)
a9564ae9
UD
622#else
623# define librt_hidden_proto(name, attrs...)
a9564ae9 624# define librt_hidden_ver(local, name)
5f21997b
UD
625#endif
626
9cd47470 627#if IS_IN (libnsl)
1d5cee23 628# define libnsl_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
ae7a94e5 629# define libnsl_hidden_nolink_def(name, version) hidden_nolink (name, libnsl, version)
1d5cee23
UD
630#else
631# define libnsl_hidden_proto(name, attrs...)
1d5cee23
UD
632#endif
633
3ce1f295
UD
634#define libc_hidden_builtin_proto(name, attrs...) libc_hidden_proto (name, ##attrs)
635#define libc_hidden_builtin_def(name) libc_hidden_def (name)
45ae17dd
PM
636
637#define libc_hidden_ldbl_proto(name, attrs...) libc_hidden_proto (name, ##attrs)
3ce1f295
UD
638#ifdef __ASSEMBLER__
639# define HIDDEN_BUILTIN_JUMPTARGET(name) HIDDEN_JUMPTARGET(name)
85dd1003
UD
640#endif
641
94551be9
LM
642#if IS_IN (libanl)
643# define libanl_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
94551be9
LM
644#else
645# define libanl_hidden_proto(name, attrs...)
94551be9
LM
646#endif
647
b30542fb
UD
648/* Get some dirty hacks. */
649#include <symbol-hacks.h>
650
4a381a81
UD
651/* Move compatibility symbols out of the way by placing them all in a
652 special section. */
d3a4a571
UD
653#ifndef __ASSEMBLER__
654# define attribute_compat_text_section \
4a381a81 655 __attribute__ ((section (".text.compat")))
d3a4a571
UD
656#else
657# define compat_text_section .section ".text.compat", "ax";
d3a4a571 658#endif
4a381a81 659
00980d84 660/* Helper / base macros for indirect function symbols. */
a29bb320 661#define __ifunc_resolver(type_name, name, expr, init, classifier, ...) \
ee4e992e 662 classifier inhibit_stack_protector \
a29bb320 663 __typeof (type_name) *name##_ifunc (__VA_ARGS__) \
425ce2ed 664 { \
00980d84
SL
665 init (); \
666 __typeof (type_name) *res = expr; \
425ce2ed 667 return res; \
00980d84
SL
668 }
669
670#ifdef HAVE_GCC_IFUNC
a29bb320 671# define __ifunc_args(type_name, name, expr, init, ...) \
00980d84
SL
672 extern __typeof (type_name) name __attribute__ \
673 ((ifunc (#name "_ifunc"))); \
a29bb320 674 __ifunc_resolver (type_name, name, expr, init, static, __VA_ARGS__)
00980d84 675
a29bb320
EG
676# define __ifunc_args_hidden(type_name, name, expr, init, ...) \
677 __ifunc_args (type_name, name, expr, init, __VA_ARGS__)
00980d84
SL
678#else
679/* Gcc does not support __attribute__ ((ifunc (...))). Use the old behaviour
680 as fallback. But keep in mind that the debug information for the ifunc
681 resolver functions is not correct. It contains the ifunc'ed function as
682 DW_AT_linkage_name. E.g. lldb uses this field and an inferior function
683 call of the ifunc'ed function will fail due to "no matching function for
684 call to ..." because the ifunc'ed function and the resolver function have
685 different signatures. (Gcc support is disabled at least on a ppc64le
686 Ubuntu 14.04 system.) */
687
a29bb320 688# define __ifunc_args(type_name, name, expr, init, ...) \
00980d84 689 extern __typeof (type_name) name; \
a29bb320
EG
690 __typeof (type_name) *name##_ifunc (__VA_ARGS__) __asm__ (#name); \
691 __ifunc_resolver (type_name, name, expr, init, , __VA_ARGS__) \
00980d84
SL
692 __asm__ (".type " #name ", %gnu_indirect_function");
693
a29bb320 694# define __ifunc_args_hidden(type_name, name, expr, init, ...) \
00980d84 695 extern __typeof (type_name) __libc_##name; \
a29bb320 696 __ifunc (type_name, __libc_##name, expr, __VA_ARGS__, init) \
00980d84
SL
697 strong_alias (__libc_##name, name);
698#endif /* !HAVE_GCC_IFUNC */
699
a29bb320
EG
700#define __ifunc(type_name, name, expr, arg, init) \
701 __ifunc_args (type_name, name, expr, init, arg)
702
703#define __ifunc_hidden(type_name, name, expr, arg, init) \
704 __ifunc_args_hidden (type_name, name, expr, init, arg)
705
00980d84
SL
706/* The following macros are used for indirect function symbols in libc.so.
707 First of all, you need to have the function prototyped somewhere,
708 say in foo.h:
709
710 int foo (int __bar);
711
712 If you have an implementation for foo which e.g. uses a special hardware
713 feature which isn't available on all machines where this libc.so will be
7f0d9e61 714 used but decidable if available at runtime e.g. via hwcaps, you can provide
00980d84
SL
715 two or multiple implementations of foo:
716
717 int __foo_default (int __bar)
718 {
719 return __bar;
720 }
721
722 int __foo_special (int __bar)
723 {
724 return __bar;
725 }
726
727 If your function foo has no libc_hidden_proto (foo) defined for PLT
728 bypassing, you can use:
729
730 #define INIT_ARCH() unsigned long int hwcap = __GLRO(dl_hwcap);
731
732 libc_ifunc (foo, (hwcap & HWCAP_SPECIAL) ? __foo_special : __foo_default);
733
734 This will define a resolver function for foo which returns __foo_special or
735 __foo_default depending on your specified expression. Please note that you
736 have to define a macro function INIT_ARCH before using libc_ifunc macro as
737 it is called by the resolver function before evaluating the specified
738 expression. In this example it is used to prepare the hwcap variable.
739 The resolver function is assigned to an ifunc'ed symbol foo. Calls to foo
740 from inside or outside of libc.so will be indirected by a PLT call.
741
742 If your function foo has a libc_hidden_proto (foo) defined for PLT bypassing
743 and calls to foo within libc.so should always go to one specific
744 implementation of foo e.g. __foo_default then you have to add:
745
746 __hidden_ver1 (__foo_default, __GI_foo, __foo_default);
747
748 or a tweaked definition of libc_hidden_def macro after the __foo_default
749 function definition. Calls to foo within libc.so will always go directly to
750 __foo_default. Calls to foo from outside libc.so will be indirected by a
751 PLT call to ifunc'ed symbol foo which you have to define in a separate
752 compile unit:
753
754 #define foo __redirect_foo
755 #include <foo.h>
756 #undef foo
757
758 extern __typeof (__redirect_foo) __foo_default attribute_hidden;
759 extern __typeof (__redirect_foo) __foo_special attribute_hidden;
760
761 libc_ifunc_redirected (__redirect_foo, foo,
762 (hwcap & HWCAP_SPECIAL)
763 ? __foo_special
764 : __foo_default);
765
766 This will define the ifunc'ed symbol foo like above. The redirection of foo
7f0d9e61 767 in header file is needed to omit an additional definition of __GI_foo which
00980d84
SL
768 would end in a linker error while linking libc.so. You have to specify
769 __redirect_foo as first parameter which is used within libc_ifunc_redirected
770 macro in conjunction with typeof to define the ifunc'ed symbol foo.
771
772 If your function foo has a libc_hidden_proto (foo) defined and calls to foo
773 within or from outside libc.so should go via ifunc'ed symbol, then you have
774 to use:
775
776 libc_ifunc_hidden (foo, foo,
777 (hwcap & HWCAP_SPECIAL)
778 ? __foo_special
779 : __foo_default);
780 libc_hidden_def (foo)
781
782 The first parameter foo of libc_ifunc_hidden macro is used in the same way
783 as for libc_ifunc_redirected macro. */
784
785#define libc_ifunc(name, expr) __ifunc (name, name, expr, void, INIT_ARCH)
786
787#define libc_ifunc_redirected(redirected_name, name, expr) \
788 __ifunc (redirected_name, name, expr, void, INIT_ARCH)
789
790#define libc_ifunc_hidden(redirected_name, name, expr) \
791 __ifunc_hidden (redirected_name, name, expr, void, INIT_ARCH)
425ce2ed 792
9a1d2d45
UD
793/* The body of the function is supposed to use __get_cpu_features
794 which will, if necessary, initialize the data first. */
00980d84
SL
795#define libm_ifunc_init()
796#define libm_ifunc(name, expr) \
797 __ifunc (name, name, expr, void, libm_ifunc_init)
0f3be872
ZW
798\f
799/* These macros facilitate sharing source files with gnulib.
800
801 They are here instead of sys/cdefs.h because they should not be
802 used in public header files.
803
804 Their definitions should be kept consistent with the definitions in
805 gnulib-common.m4, but it is not necessary to cater to old non-GCC
806 compilers, since they will only be used while building glibc itself.
807 (Note that _GNUC_PREREQ cannot be used in this file.) */
808
809/* Define as a marker that can be attached to declarations that might not
810 be used. This helps to reduce warnings, such as from
811 GCC -Wunused-parameter. */
812#if __GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
813# define _GL_UNUSED __attribute__ ((__unused__))
814#else
815# define _GL_UNUSED
816#endif
817
818/* gcc supports the "unused" attribute on possibly unused labels, and
819 g++ has since version 4.5. Note to support C++ as well as C,
820 _GL_UNUSED_LABEL should be used with a trailing ; */
821#if !defined __cplusplus || __GNUC__ > 4 \
822 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
823# define _GL_UNUSED_LABEL _GL_UNUSED
824#else
825# define _GL_UNUSED_LABEL
826#endif
827
828/* The __pure__ attribute was added in gcc 2.96. */
829#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
830# define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
831#else
832# define _GL_ATTRIBUTE_PURE /* empty */
833#endif
834
835/* The __const__ attribute was added in gcc 2.95. */
836#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)
837# define _GL_ATTRIBUTE_CONST __attribute__ ((__const__))
838#else
839# define _GL_ATTRIBUTE_CONST /* empty */
840#endif
85c2e611 841
7c3018f9 842#endif /* !_ISOMAC */
28f540f4 843#endif /* libc-symbols.h */