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