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