i386: Do not set internal_function
[glibc.git] / include / libc-symbols.h
blobfe3ab81c51ec2711da88dc60478416b8be056cb9
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-2017 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
20 #ifndef _LIBC_SYMBOLS_H
21 #define _LIBC_SYMBOLS_H 1
23 /* This file is included implicitly in the compilation of every source file,
24 using -include. It includes config.h. */
26 /* Enable declarations of GNU extensions, since we are compiling them. */
27 #define _GNU_SOURCE 1
29 #ifdef MODULE_NAME
31 /* Use `#if IS_IN (module)` to detect what component is being compiled. */
32 #define PASTE_NAME1(a,b) a##b
33 #define PASTE_NAME(a,b) PASTE_NAME1 (a,b)
34 #define IN_MODULE PASTE_NAME (MODULE_, MODULE_NAME)
35 #define IS_IN(lib) (IN_MODULE == MODULE_##lib)
37 /* True if the current module is a versioned library. Versioned
38 library names culled from shlib-versions files are assigned a
39 MODULE_* value greater than MODULE_LIBS_BEGIN. */
40 #define IS_IN_LIB (IN_MODULE > MODULE_LIBS_BEGIN)
42 /* The testsuite, and some other ancillary code, should be compiled against
43 as close an approximation to the installed headers as possible.
44 Defining this symbol disables most internal-use-only declarations
45 provided by this header, and all those provided by other internal
46 wrapper headers. */
47 #if IS_IN (testsuite) || defined IS_IN_build || defined __cplusplus
48 # define _ISOMAC 1
49 #endif
51 #else
52 /* The generation process for a few files created very early in the
53 build (notably libc-modules.h itself) involves preprocessing this
54 header without defining MODULE_NAME. Under these conditions,
55 internal declarations (especially from config.h) must be visible,
56 but IS_IN should always evaluate as false. */
57 # define IS_IN(lib) 0
58 # define IS_IN_LIB 0
59 # define IN_MODULE (-1)
60 #endif
62 #ifndef _ISOMAC
64 /* This is defined for the compilation of all C library code. features.h
65 tests this to avoid inclusion of stubs.h while compiling the library,
66 before stubs.h has been generated. Some library code that is shared
67 with other packages also tests this symbol to see if it is being
68 compiled as part of the C library. We must define this before including
69 config.h, because it makes some definitions conditional on whether libc
70 itself is being compiled, or just some generator program. */
71 #define _LIBC 1
73 /* Some files must be compiled with optimization on. */
74 #if !defined __ASSEMBLER__ && !defined __OPTIMIZE__
75 # error "glibc cannot be compiled without optimization"
76 #endif
78 /* -ffast-math cannot be applied to the C library, as it alters the ABI.
79 Some test components that use -ffast-math are currently not part of
80 IS_IN (testsuite) for technical reasons, so we have a secondary override. */
81 #if defined __FAST_MATH__ && !defined TEST_FAST_MATH
82 # error "glibc must not be compiled with -ffast-math"
83 #endif
85 #include <config.h>
87 /* 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
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
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
114 /* The symbols in all the user (non-_) macros are C symbols. */
116 #ifndef __SYMBOL_PREFIX
117 # define __SYMBOL_PREFIX
118 #endif
120 #ifndef C_SYMBOL_NAME
121 # define C_SYMBOL_NAME(name) name
122 #endif
124 #ifndef ASM_LINE_SEP
125 # define ASM_LINE_SEP ;
126 #endif
128 #ifndef __ASSEMBLER__
129 /* GCC understands weak symbols and aliases; use its interface where
130 possible, instead of embedded assembly language. */
132 /* Define ALIASNAME as a strong alias for NAME. */
133 # define strong_alias(name, aliasname) _strong_alias(name, aliasname)
134 # define _strong_alias(name, aliasname) \
135 extern __typeof (name) aliasname __attribute__ ((alias (#name)));
137 /* This comes between the return type and function name in
138 a function definition to make that definition weak. */
139 # define weak_function __attribute__ ((weak))
140 # define weak_const_function __attribute__ ((weak, __const__))
142 /* Define ALIASNAME as a weak alias for NAME.
143 If weak aliases are not available, this defines a strong alias. */
144 # define weak_alias(name, aliasname) _weak_alias (name, aliasname)
145 # define _weak_alias(name, aliasname) \
146 extern __typeof (name) aliasname __attribute__ ((weak, alias (#name)));
148 /* Same as WEAK_ALIAS, but mark symbol as hidden. */
149 # define weak_hidden_alias(name, aliasname) \
150 _weak_hidden_alias (name, aliasname)
151 # define _weak_hidden_alias(name, aliasname) \
152 extern __typeof (name) aliasname \
153 __attribute__ ((weak, alias (#name), __visibility__ ("hidden")));
155 /* Declare SYMBOL as weak undefined symbol (resolved to 0 if not defined). */
156 # define weak_extern(symbol) _weak_extern (weak symbol)
157 # define _weak_extern(expr) _Pragma (#expr)
159 /* In shared builds, the expression call_function_static_weak
160 (FUNCTION-SYMBOL, ARGUMENTS) invokes FUNCTION-SYMBOL (an
161 identifier) unconditionally, with the (potentially empty) argument
162 list ARGUMENTS. In static builds, if FUNCTION-SYMBOL has a
163 definition, the function is invoked as before; if FUNCTION-SYMBOL
164 is NULL, no call is performed. */
165 # ifdef SHARED
166 # define call_function_static_weak(func, ...) func (__VA_ARGS__)
167 # else /* !SHARED */
168 # define call_function_static_weak(func, ...) \
169 ({ \
170 extern __typeof__ (func) func weak_function; \
171 (func != NULL ? func (__VA_ARGS__) : (void)0); \
173 # endif
175 #else /* __ASSEMBLER__ */
177 # ifdef HAVE_ASM_SET_DIRECTIVE
178 # define strong_alias(original, alias) \
179 .globl C_SYMBOL_NAME (alias) ASM_LINE_SEP \
180 .set C_SYMBOL_NAME (alias),C_SYMBOL_NAME (original)
181 # define strong_data_alias(original, alias) strong_alias(original, alias)
182 # else
183 # define strong_alias(original, alias) \
184 .globl C_SYMBOL_NAME (alias) ASM_LINE_SEP \
185 C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original)
186 # define strong_data_alias(original, alias) strong_alias(original, alias)
187 # endif
189 # define weak_alias(original, alias) \
190 .weak C_SYMBOL_NAME (alias) ASM_LINE_SEP \
191 C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original)
193 # define weak_extern(symbol) \
194 .weak C_SYMBOL_NAME (symbol)
196 #endif /* __ASSEMBLER__ */
198 /* On some platforms we can make internal function calls (i.e., calls of
199 functions not exported) a bit faster by using a different calling
200 convention. */
201 #ifndef internal_function
202 # define internal_function /* empty */
203 #endif
205 /* Determine the return address. */
206 #define RETURN_ADDRESS(nr) \
207 __builtin_extract_return_addr (__builtin_return_address (nr))
209 /* When a reference to SYMBOL is encountered, the linker will emit a
210 warning message MSG. */
211 /* We want the .gnu.warning.SYMBOL section to be unallocated. */
212 #define __make_section_unallocated(section_string) \
213 asm (".section " section_string "\n\t.previous");
215 /* Tacking on "\n\t#" to the section name makes gcc put it's bogus
216 section attributes on what looks like a comment to the assembler. */
217 #ifdef HAVE_SECTION_QUOTES
218 # define __sec_comment "\"\n\t#\""
219 #else
220 # define __sec_comment "\n\t#"
221 #endif
222 #define link_warning(symbol, msg) \
223 __make_section_unallocated (".gnu.warning." #symbol) \
224 static const char __evoke_link_warning_##symbol[] \
225 __attribute__ ((used, section (".gnu.warning." #symbol __sec_comment))) \
226 = msg;
227 #define libc_freeres_ptr(decl) \
228 __make_section_unallocated ("__libc_freeres_ptrs, \"aw\", %nobits") \
229 decl __attribute__ ((section ("__libc_freeres_ptrs" __sec_comment)))
230 #define __libc_freeres_fn_section \
231 __attribute__ ((section ("__libc_freeres_fn")))
233 #define libc_freeres_fn(name) \
234 static void name (void) __attribute_used__ __libc_freeres_fn_section; \
235 text_set_element (__libc_subfreeres, name); \
236 static void name (void)
238 /* A canned warning for sysdeps/stub functions. */
239 #define stub_warning(name) \
240 __make_section_unallocated (".gnu.glibc-stub." #name) \
241 link_warning (name, #name " is not implemented and will always fail")
243 /* Warning for linking functions calling dlopen into static binaries. */
244 #ifdef SHARED
245 #define static_link_warning(name)
246 #else
247 #define static_link_warning(name) static_link_warning1(name)
248 #define static_link_warning1(name) \
249 link_warning(name, "Using '" #name "' in statically linked applications \
250 requires at runtime the shared libraries from the glibc version used \
251 for linking")
252 #endif
254 /* Declare SYMBOL to be TYPE (`function' or `object') of SIZE bytes
255 alias to ORIGINAL, when the assembler supports such declarations
256 (such as in ELF).
257 This is only necessary when defining something in assembly, or playing
258 funny alias games where the size should be other than what the compiler
259 thinks it is. */
260 #define declare_symbol_alias(symbol, original, type, size) \
261 declare_symbol_alias_1 (symbol, original, type, size)
262 #ifdef __ASSEMBLER__
263 # define declare_symbol_alias_1(symbol, original, type, size) \
264 strong_alias (original, symbol); \
265 .type C_SYMBOL_NAME (symbol), %##type; \
266 .size C_SYMBOL_NAME (symbol), size
267 #else /* Not __ASSEMBLER__. */
268 # define declare_symbol_alias_1(symbol, original, type, size) \
269 asm (".globl " __SYMBOL_PREFIX #symbol \
270 "\n\t" declare_symbol_alias_1_alias (symbol, original) \
271 "\n\t.type " __SYMBOL_PREFIX #symbol ", " \
272 "%" #type \
273 "\n\t.size " __SYMBOL_PREFIX #symbol ", " #size);
274 # ifdef HAVE_ASM_SET_DIRECTIVE
275 # define declare_symbol_alias_1_alias(symbol, original) \
276 ".set " __SYMBOL_PREFIX #symbol ", " __SYMBOL_PREFIX #original
277 # else
278 # define declare_symbol_alias_1_alias(symbol, original) \
279 __SYMBOL_PREFIX #symbol " = " __SYMBOL_PREFIX #original
280 # endif /* HAVE_ASM_SET_DIRECTIVE */
281 #endif /* __ASSEMBLER__ */
288 /* Symbol set support macros. */
290 /* Make SYMBOL, which is in the text segment, an element of SET. */
291 #define text_set_element(set, symbol) _elf_set_element(set, symbol)
292 /* Make SYMBOL, which is in the data segment, an element of SET. */
293 #define data_set_element(set, symbol) _elf_set_element(set, symbol)
294 /* Make SYMBOL, which is in the bss segment, an element of SET. */
295 #define bss_set_element(set, symbol) _elf_set_element(set, symbol)
297 /* These are all done the same way in ELF.
298 There is a new section created for each set. */
299 #ifdef SHARED
300 /* When building a shared library, make the set section writable,
301 because it will need to be relocated at run time anyway. */
302 # define _elf_set_element(set, symbol) \
303 static const void *__elf_set_##set##_element_##symbol##__ \
304 __attribute__ ((used, section (#set))) = &(symbol)
305 #else
306 # define _elf_set_element(set, symbol) \
307 static const void *const __elf_set_##set##_element_##symbol##__ \
308 __attribute__ ((used, section (#set))) = &(symbol)
309 #endif
311 /* Define SET as a symbol set. This may be required (it is in a.out) to
312 be able to use the set's contents. */
313 #define symbol_set_define(set) symbol_set_declare(set)
315 /* Declare SET for use in this module, if defined in another module.
316 In a shared library, this is always local to that shared object.
317 For static linking, the set might be wholly absent and so we use
318 weak references. */
319 #define symbol_set_declare(set) \
320 extern char const __start_##set[] __symbol_set_attribute; \
321 extern char const __stop_##set[] __symbol_set_attribute;
322 #ifdef SHARED
323 # define __symbol_set_attribute attribute_hidden
324 #else
325 # define __symbol_set_attribute __attribute__ ((weak))
326 #endif
328 /* Return a pointer (void *const *) to the first element of SET. */
329 #define symbol_set_first_element(set) ((void *const *) (&__start_##set))
331 /* Return true iff PTR (a void *const *) has been incremented
332 past the last element in SET. */
333 #define symbol_set_end_p(set, ptr) ((ptr) >= (void *const *) &__stop_##set)
335 /* Use symbol_version_reference to specify the version a symbol
336 reference should link to. Use symbol_version or
337 default_symbol_version for the definition of a versioned symbol.
338 The difference is that the latter is a no-op in non-shared
339 builds. */
340 #ifdef __ASSEMBLER__
341 # define symbol_version_reference(real, name, version) \
342 .symver real, name##@##version
343 #else /* !__ASSEMBLER__ */
344 # define symbol_version_reference(real, name, version) \
345 __asm__ (".symver " #real "," #name "@" #version)
346 #endif
348 #ifdef SHARED
349 # define symbol_version(real, name, version) \
350 symbol_version_reference(real, name, version)
351 # define default_symbol_version(real, name, version) \
352 _default_symbol_version(real, name, version)
353 # ifdef __ASSEMBLER__
354 # define _default_symbol_version(real, name, version) \
355 .symver real, name##@##@##version
356 # else
357 # define _default_symbol_version(real, name, version) \
358 __asm__ (".symver " #real "," #name "@@" #version)
359 # endif
360 #else
361 # define symbol_version(real, name, version)
362 # define default_symbol_version(real, name, version) \
363 strong_alias(real, name)
364 #endif
366 #if defined SHARED || defined LIBC_NONSHARED
367 # define attribute_hidden __attribute__ ((visibility ("hidden")))
368 #else
369 # define attribute_hidden
370 #endif
372 #define attribute_tls_model_ie __attribute__ ((tls_model ("initial-exec")))
374 #define attribute_relro __attribute__ ((section (".data.rel.ro")))
377 /* Used to disable stack protection in sensitive places, like ifunc
378 resolvers and early static TLS init. */
379 #ifdef HAVE_CC_NO_STACK_PROTECTOR
380 # define inhibit_stack_protector \
381 __attribute__ ((__optimize__ ("-fno-stack-protector")))
382 #else
383 # define inhibit_stack_protector
384 #endif
386 /* The following macros are used for PLT bypassing within libc.so
387 (and if needed other libraries similarly).
388 First of all, you need to have the function prototyped somewhere,
389 say in foo/foo.h:
391 int foo (int __bar);
393 If calls to foo within libc.so should always go to foo defined in libc.so,
394 then in include/foo.h you add:
396 libc_hidden_proto (foo)
398 line and after the foo function definition:
400 int foo (int __bar)
402 return __bar;
404 libc_hidden_def (foo)
408 int foo (int __bar)
410 return __bar;
412 libc_hidden_weak (foo)
414 Similarly for global data. If references to foo within libc.so should
415 always go to foo defined in libc.so, then in include/foo.h you add:
417 libc_hidden_proto (foo)
419 line and after foo's definition:
421 int foo = INITIAL_FOO_VALUE;
422 libc_hidden_data_def (foo)
426 int foo = INITIAL_FOO_VALUE;
427 libc_hidden_data_weak (foo)
429 If foo is normally just an alias (strong or weak) to some other function,
430 you should use the normal strong_alias first, then add libc_hidden_def
431 or libc_hidden_weak:
433 int baz (int __bar)
435 return __bar;
437 strong_alias (baz, foo)
438 libc_hidden_weak (foo)
440 If the function should be internal to multiple objects, say ld.so and
441 libc.so, the best way is to use:
443 #if IS_IN (libc) || IS_IN (rtld)
444 hidden_proto (foo)
445 #endif
447 in include/foo.h and the normal macros at all function definitions
448 depending on what DSO they belong to.
450 If versioned_symbol macro is used to define foo,
451 libc_hidden_ver macro should be used, as in:
453 int __real_foo (int __bar)
455 return __bar;
457 versioned_symbol (libc, __real_foo, foo, GLIBC_2_1);
458 libc_hidden_ver (__real_foo, foo) */
460 #if defined SHARED && !defined NO_HIDDEN
461 # ifndef __ASSEMBLER__
462 # define __hidden_proto_hiddenattr(attrs...) \
463 __attribute__ ((visibility ("hidden"), ##attrs))
464 # define hidden_proto(name, attrs...) \
465 __hidden_proto (name, , __GI_##name, ##attrs)
466 # define hidden_tls_proto(name, attrs...) \
467 __hidden_proto (name, __thread, __GI_##name, ##attrs)
468 # define __hidden_proto(name, thread, internal, attrs...) \
469 extern thread __typeof (name) name __asm__ (__hidden_asmname (#internal)) \
470 __hidden_proto_hiddenattr (attrs);
471 # define __hidden_asmname(name) \
472 __hidden_asmname1 (__USER_LABEL_PREFIX__, name)
473 # define __hidden_asmname1(prefix, name) __hidden_asmname2(prefix, name)
474 # define __hidden_asmname2(prefix, name) #prefix name
475 # define __hidden_ver1(local, internal, name) \
476 extern __typeof (name) __EI_##name __asm__(__hidden_asmname (#internal)); \
477 extern __typeof (name) __EI_##name \
478 __attribute__((alias (__hidden_asmname (#local))))
479 # define hidden_ver(local, name) __hidden_ver1(local, __GI_##name, name);
480 # define hidden_data_ver(local, name) hidden_ver(local, name)
481 # define hidden_def(name) __hidden_ver1(__GI_##name, name, name);
482 # define hidden_data_def(name) hidden_def(name)
483 # define hidden_weak(name) \
484 __hidden_ver1(__GI_##name, name, name) __attribute__((weak));
485 # define hidden_data_weak(name) hidden_weak(name)
486 # define hidden_nolink(name, lib, version) \
487 __hidden_nolink1 (__GI_##name, __EI_##name, name, VERSION_##lib##_##version)
488 # define __hidden_nolink1(local, internal, name, version) \
489 __hidden_nolink2 (local, internal, name, version)
490 # define __hidden_nolink2(local, internal, name, version) \
491 extern __typeof (name) internal __attribute__ ((alias (#local))); \
492 __hidden_nolink3 (local, internal, #name "@" #version)
493 # define __hidden_nolink3(local, internal, vername) \
494 __asm__ (".symver " #internal ", " vername);
495 # else
496 /* For assembly, we need to do the opposite of what we do in C:
497 in assembly gcc __REDIRECT stuff is not in place, so functions
498 are defined by its normal name and we need to create the
499 __GI_* alias to it, in C __REDIRECT causes the function definition
500 to use __GI_* name and we need to add alias to the real name.
501 There is no reason to use hidden_weak over hidden_def in assembly,
502 but we provide it for consistency with the C usage.
503 hidden_proto doesn't make sense for assembly but the equivalent
504 is to call via the HIDDEN_JUMPTARGET macro instead of JUMPTARGET. */
505 # define hidden_def(name) strong_alias (name, __GI_##name)
506 # define hidden_weak(name) hidden_def (name)
507 # define hidden_ver(local, name) strong_alias (local, __GI_##name)
508 # define hidden_data_def(name) strong_data_alias (name, __GI_##name)
509 # define hidden_data_weak(name) hidden_data_def (name)
510 # define hidden_data_ver(local, name) strong_data_alias (local, __GI_##name)
511 # define HIDDEN_JUMPTARGET(name) __GI_##name
512 # endif
513 #else
514 # ifndef __ASSEMBLER__
515 # define hidden_proto(name, attrs...)
516 # define hidden_tls_proto(name, attrs...)
517 # else
518 # define HIDDEN_JUMPTARGET(name) JUMPTARGET(name)
519 # endif /* Not __ASSEMBLER__ */
520 # define hidden_weak(name)
521 # define hidden_def(name)
522 # define hidden_ver(local, name)
523 # define hidden_data_weak(name)
524 # define hidden_data_def(name)
525 # define hidden_data_ver(local, name)
526 # define hidden_nolink(name, lib, version)
527 #endif
529 #if IS_IN (libc)
530 # define libc_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
531 # define libc_hidden_tls_proto(name, attrs...) hidden_tls_proto (name, ##attrs)
532 # define libc_hidden_def(name) hidden_def (name)
533 # define libc_hidden_weak(name) hidden_weak (name)
534 # ifdef LINK_OBSOLETE_RPC
535 /* libc_hidden_nolink_sunrpc should only get used in sunrpc code. */
536 # define libc_hidden_nolink_sunrpc(name, version) hidden_def (name)
537 # else
538 # define libc_hidden_nolink_sunrpc(name, version) hidden_nolink (name, libc, version)
539 # endif
540 # define libc_hidden_ver(local, name) hidden_ver (local, name)
541 # define libc_hidden_data_def(name) hidden_data_def (name)
542 # define libc_hidden_data_weak(name) hidden_data_weak (name)
543 # define libc_hidden_data_ver(local, name) hidden_data_ver (local, name)
544 #else
545 # define libc_hidden_proto(name, attrs...)
546 # define libc_hidden_tls_proto(name, attrs...)
547 # define libc_hidden_def(name)
548 # define libc_hidden_weak(name)
549 # define libc_hidden_ver(local, name)
550 # define libc_hidden_data_def(name)
551 # define libc_hidden_data_weak(name)
552 # define libc_hidden_data_ver(local, name)
553 #endif
555 #if IS_IN (rtld)
556 # define rtld_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
557 # define rtld_hidden_tls_proto(name, attrs...) hidden_tls_proto (name, ##attrs)
558 # define rtld_hidden_def(name) hidden_def (name)
559 # define rtld_hidden_weak(name) hidden_weak (name)
560 # define rtld_hidden_ver(local, name) hidden_ver (local, name)
561 # define rtld_hidden_data_def(name) hidden_data_def (name)
562 # define rtld_hidden_data_weak(name) hidden_data_weak (name)
563 # define rtld_hidden_data_ver(local, name) hidden_data_ver (local, name)
564 #else
565 # define rtld_hidden_proto(name, attrs...)
566 # define rtld_hidden_tls_proto(name, attrs...)
567 # define rtld_hidden_def(name)
568 # define rtld_hidden_weak(name)
569 # define rtld_hidden_ver(local, name)
570 # define rtld_hidden_data_def(name)
571 # define rtld_hidden_data_weak(name)
572 # define rtld_hidden_data_ver(local, name)
573 #endif
575 #if IS_IN (libm)
576 # define libm_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
577 # define libm_hidden_tls_proto(name, attrs...) hidden_tls_proto (name, ##attrs)
578 # define libm_hidden_def(name) hidden_def (name)
579 # define libm_hidden_weak(name) hidden_weak (name)
580 # define libm_hidden_ver(local, name) hidden_ver (local, name)
581 # define libm_hidden_data_def(name) hidden_data_def (name)
582 # define libm_hidden_data_weak(name) hidden_data_weak (name)
583 # define libm_hidden_data_ver(local, name) hidden_data_ver (local, name)
584 #else
585 # define libm_hidden_proto(name, attrs...)
586 # define libm_hidden_tls_proto(name, attrs...)
587 # define libm_hidden_def(name)
588 # define libm_hidden_weak(name)
589 # define libm_hidden_ver(local, name)
590 # define libm_hidden_data_def(name)
591 # define libm_hidden_data_weak(name)
592 # define libm_hidden_data_ver(local, name)
593 #endif
595 #if IS_IN (libmvec)
596 # define libmvec_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
597 # define libmvec_hidden_tls_proto(name, attrs...) hidden_tls_proto (name, ##attrs)
598 # define libmvec_hidden_def(name) hidden_def (name)
599 # define libmvec_hidden_weak(name) hidden_weak (name)
600 # define libmvec_hidden_ver(local, name) hidden_ver (local, name)
601 # define libmvec_hidden_data_def(name) hidden_data_def (name)
602 # define libmvec_hidden_data_weak(name) hidden_data_weak (name)
603 # define libmvec_hidden_data_ver(local, name) hidden_data_ver (local, name)
604 #else
605 # define libmvec_hidden_proto(name, attrs...)
606 # define libmvec_hidden_tls_proto(name, attrs...)
607 # define libmvec_hidden_def(name)
608 # define libmvec_hidden_weak(name)
609 # define libmvec_hidden_ver(local, name)
610 # define libmvec_hidden_data_def(name)
611 # define libmvec_hidden_data_weak(name)
612 # define libmvec_hidden_data_ver(local, name)
613 #endif
615 #if IS_IN (libresolv)
616 # define libresolv_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
617 # define libresolv_hidden_tls_proto(name, attrs...) \
618 hidden_tls_proto (name, ##attrs)
619 # define libresolv_hidden_def(name) hidden_def (name)
620 # define libresolv_hidden_weak(name) hidden_weak (name)
621 # define libresolv_hidden_ver(local, name) hidden_ver (local, name)
622 # define libresolv_hidden_data_def(name) hidden_data_def (name)
623 # define libresolv_hidden_data_weak(name) hidden_data_weak (name)
624 # define libresolv_hidden_data_ver(local, name) hidden_data_ver (local, name)
625 #else
626 # define libresolv_hidden_proto(name, attrs...)
627 # define libresolv_hidden_tls_proto(name, attrs...)
628 # define libresolv_hidden_def(name)
629 # define libresolv_hidden_weak(name)
630 # define libresolv_hidden_ver(local, name)
631 # define libresolv_hidden_data_def(name)
632 # define libresolv_hidden_data_weak(name)
633 # define libresolv_hidden_data_ver(local, name)
634 #endif
636 #if IS_IN (librt)
637 # define librt_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
638 # define librt_hidden_tls_proto(name, attrs...) \
639 hidden_tls_proto (name, ##attrs)
640 # define librt_hidden_def(name) hidden_def (name)
641 # define librt_hidden_weak(name) hidden_weak (name)
642 # define librt_hidden_ver(local, name) hidden_ver (local, name)
643 # define librt_hidden_data_def(name) hidden_data_def (name)
644 # define librt_hidden_data_weak(name) hidden_data_weak (name)
645 # define librt_hidden_data_ver(local, name) hidden_data_ver (local, name)
646 #else
647 # define librt_hidden_proto(name, attrs...)
648 # define librt_hidden_tls_proto(name, attrs...)
649 # define librt_hidden_def(name)
650 # define librt_hidden_weak(name)
651 # define librt_hidden_ver(local, name)
652 # define librt_hidden_data_def(name)
653 # define librt_hidden_data_weak(name)
654 # define librt_hidden_data_ver(local, name)
655 #endif
657 #if IS_IN (libdl)
658 # define libdl_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
659 # define libdl_hidden_tls_proto(name, attrs...) \
660 hidden_tls_proto (name, ##attrs)
661 # define libdl_hidden_def(name) hidden_def (name)
662 # define libdl_hidden_weak(name) hidden_weak (name)
663 # define libdl_hidden_ver(local, name) hidden_ver (local, name)
664 # define libdl_hidden_data_def(name) hidden_data_def (name)
665 # define libdl_hidden_data_weak(name) hidden_data_weak (name)
666 # define libdl_hidden_data_ver(local, name) hidden_data_ver (local, name)
667 #else
668 # define libdl_hidden_proto(name, attrs...)
669 # define libdl_hidden_tls_proto(name, attrs...)
670 # define libdl_hidden_def(name)
671 # define libdl_hidden_weak(name)
672 # define libdl_hidden_ver(local, name)
673 # define libdl_hidden_data_def(name)
674 # define libdl_hidden_data_weak(name)
675 # define libdl_hidden_data_ver(local, name)
676 #endif
678 #if IS_IN (libnss_files)
679 # define libnss_files_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
680 # define libnss_files_hidden_tls_proto(name, attrs...) \
681 hidden_tls_proto (name, ##attrs)
682 # define libnss_files_hidden_def(name) hidden_def (name)
683 # define libnss_files_hidden_weak(name) hidden_weak (name)
684 # define libnss_files_hidden_ver(local, name) hidden_ver (local, name)
685 # define libnss_files_hidden_data_def(name) hidden_data_def (name)
686 # define libnss_files_hidden_data_weak(name) hidden_data_weak (name)
687 # define libnss_files_hidden_data_ver(local, name) hidden_data_ver(local, name)
688 #else
689 # define libnss_files_hidden_proto(name, attrs...)
690 # define libnss_files_hidden_tls_proto(name, attrs...)
691 # define libnss_files_hidden_def(name)
692 # define libnss_files_hidden_weak(name)
693 # define libnss_files_hidden_ver(local, name)
694 # define libnss_files_hidden_data_def(name)
695 # define libnss_files_hidden_data_weak(name)
696 # define libnss_files_hidden_data_ver(local, name)
697 #endif
699 #if IS_IN (libnsl)
700 # define libnsl_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
701 # define libnsl_hidden_tls_proto(name, attrs...) \
702 hidden_tls_proto (name, ##attrs)
703 # ifdef LINK_OBSOLETE_NSL
704 /* libnsl_hidden_nolink should only get used in libnsl code. */
705 # define libnsl_hidden_nolink_def(name, version) libnsl_hidden_def (name)
706 # else
707 # define libnsl_hidden_nolink_def(name, version) hidden_nolink (name, libnsl, version)
708 # endif
709 # define libnsl_hidden_def(name) hidden_def (name)
710 # define libnsl_hidden_weak(name) hidden_weak (name)
711 # define libnsl_hidden_ver(local, name) hidden_ver (local, name)
712 # define libnsl_hidden_data_def(name) hidden_data_def (name)
713 # define libnsl_hidden_data_weak(name) hidden_data_weak (name)
714 # define libnsl_hidden_data_ver(local, name) hidden_data_ver (local, name)
715 #else
716 # define libnsl_hidden_proto(name, attrs...)
717 # define libnsl_hidden_tls_proto(name, attrs...)
718 # define libnsl_hidden_def(name)
719 # define libnsl_hidden_weak(name)
720 # define libnsl_hidden_ver(local, name)
721 # define libnsl_hidden_data_def(name)
722 # define libnsl_hidden_data_weak(name)
723 # define libnsl_hidden_data_ver(local, name)
724 #endif
726 #if IS_IN (libnss_nisplus)
727 # define libnss_nisplus_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
728 # define libnss_nisplus_hidden_tls_proto(name, attrs...) \
729 hidden_tls_proto (name, ##attrs)
730 # define libnss_nisplus_hidden_def(name) hidden_def (name)
731 # define libnss_nisplus_hidden_weak(name) hidden_weak (name)
732 # define libnss_nisplus_hidden_ver(local, name) hidden_ver (local, name)
733 # define libnss_nisplus_hidden_data_def(name) hidden_data_def (name)
734 # define libnss_nisplus_hidden_data_weak(name) hidden_data_weak (name)
735 # define libnss_nisplus_hidden_data_ver(local, name) hidden_data_ver (local, name)
736 #else
737 # define libnss_nisplus_hidden_proto(name, attrs...)
738 # define libnss_nisplus_hidden_tls_proto(name, attrs...)
739 # define libnss_nisplus_hidden_def(name)
740 # define libnss_nisplus_hidden_weak(name)
741 # define libnss_nisplus_hidden_ver(local, name)
742 # define libnss_nisplus_hidden_data_def(name)
743 # define libnss_nisplus_hidden_data_weak(name)
744 # define libnss_nisplus_hidden_data_ver(local, name)
745 #endif
747 #define libc_hidden_builtin_proto(name, attrs...) libc_hidden_proto (name, ##attrs)
748 #define libc_hidden_builtin_def(name) libc_hidden_def (name)
749 #define libc_hidden_builtin_weak(name) libc_hidden_weak (name)
750 #define libc_hidden_builtin_ver(local, name) libc_hidden_ver (local, name)
751 #ifdef __ASSEMBLER__
752 # define HIDDEN_BUILTIN_JUMPTARGET(name) HIDDEN_JUMPTARGET(name)
753 #endif
755 #if IS_IN (libutil)
756 # define libutil_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
757 # define libutil_hidden_tls_proto(name, attrs...) \
758 hidden_tls_proto (name, ##attrs)
759 # define libutil_hidden_def(name) hidden_def (name)
760 # define libutil_hidden_weak(name) hidden_weak (name)
761 # define libutil_hidden_ver(local, name) hidden_ver (local, name)
762 # define libutil_hidden_data_def(name) hidden_data_def (name)
763 # define libutil_hidden_data_weak(name) hidden_data_weak (name)
764 # define libutil_hidden_data_ver(local, name) hidden_data_ver (local, name)
765 #else
766 # define libutil_hidden_proto(name, attrs...)
767 # define libutil_hidden_tls_proto(name, attrs...)
768 # define libutil_hidden_def(name)
769 # define libutil_hidden_weak(name)
770 # define libutil_hidden_ver(local, name)
771 # define libutil_hidden_data_def(name)
772 # define libutil_hidden_data_weak(name)
773 # define libutil_hidden_data_ver(local, name)
774 #endif
776 /* Get some dirty hacks. */
777 #include <symbol-hacks.h>
779 /* Move compatibility symbols out of the way by placing them all in a
780 special section. */
781 #ifndef __ASSEMBLER__
782 # define attribute_compat_text_section \
783 __attribute__ ((section (".text.compat")))
784 # define attribute_compat_data_section \
785 __attribute__ ((section (".data.compat")))
786 #else
787 # define compat_text_section .section ".text.compat", "ax";
788 # define compat_data_section .section ".data.compat", "aw";
789 #endif
791 /* Helper / base macros for indirect function symbols. */
792 #define __ifunc_resolver(type_name, name, expr, arg, init, classifier) \
793 classifier inhibit_stack_protector void *name##_ifunc (arg) \
795 init (); \
796 __typeof (type_name) *res = expr; \
797 return res; \
800 #ifdef HAVE_GCC_IFUNC
801 # define __ifunc(type_name, name, expr, arg, init) \
802 extern __typeof (type_name) name __attribute__ \
803 ((ifunc (#name "_ifunc"))); \
804 __ifunc_resolver (type_name, name, expr, arg, init, static)
806 # define __ifunc_hidden(type_name, name, expr, arg, init) \
807 __ifunc (type_name, name, expr, arg, init)
808 #else
809 /* Gcc does not support __attribute__ ((ifunc (...))). Use the old behaviour
810 as fallback. But keep in mind that the debug information for the ifunc
811 resolver functions is not correct. It contains the ifunc'ed function as
812 DW_AT_linkage_name. E.g. lldb uses this field and an inferior function
813 call of the ifunc'ed function will fail due to "no matching function for
814 call to ..." because the ifunc'ed function and the resolver function have
815 different signatures. (Gcc support is disabled at least on a ppc64le
816 Ubuntu 14.04 system.) */
818 # define __ifunc(type_name, name, expr, arg, init) \
819 extern __typeof (type_name) name; \
820 void *name##_ifunc (arg) __asm__ (#name); \
821 __ifunc_resolver (type_name, name, expr, arg, init,) \
822 __asm__ (".type " #name ", %gnu_indirect_function");
824 # define __ifunc_hidden(type_name, name, expr, arg, init) \
825 extern __typeof (type_name) __libc_##name; \
826 __ifunc (type_name, __libc_##name, expr, arg, init) \
827 strong_alias (__libc_##name, name);
828 #endif /* !HAVE_GCC_IFUNC */
830 /* The following macros are used for indirect function symbols in libc.so.
831 First of all, you need to have the function prototyped somewhere,
832 say in foo.h:
834 int foo (int __bar);
836 If you have an implementation for foo which e.g. uses a special hardware
837 feature which isn't available on all machines where this libc.so will be
838 used but decideable if available at runtime e.g. via hwcaps, you can provide
839 two or multiple implementations of foo:
841 int __foo_default (int __bar)
843 return __bar;
846 int __foo_special (int __bar)
848 return __bar;
851 If your function foo has no libc_hidden_proto (foo) defined for PLT
852 bypassing, you can use:
854 #define INIT_ARCH() unsigned long int hwcap = __GLRO(dl_hwcap);
856 libc_ifunc (foo, (hwcap & HWCAP_SPECIAL) ? __foo_special : __foo_default);
858 This will define a resolver function for foo which returns __foo_special or
859 __foo_default depending on your specified expression. Please note that you
860 have to define a macro function INIT_ARCH before using libc_ifunc macro as
861 it is called by the resolver function before evaluating the specified
862 expression. In this example it is used to prepare the hwcap variable.
863 The resolver function is assigned to an ifunc'ed symbol foo. Calls to foo
864 from inside or outside of libc.so will be indirected by a PLT call.
866 If your function foo has a libc_hidden_proto (foo) defined for PLT bypassing
867 and calls to foo within libc.so should always go to one specific
868 implementation of foo e.g. __foo_default then you have to add:
870 __hidden_ver1 (__foo_default, __GI_foo, __foo_default);
872 or a tweaked definition of libc_hidden_def macro after the __foo_default
873 function definition. Calls to foo within libc.so will always go directly to
874 __foo_default. Calls to foo from outside libc.so will be indirected by a
875 PLT call to ifunc'ed symbol foo which you have to define in a separate
876 compile unit:
878 #define foo __redirect_foo
879 #include <foo.h>
880 #undef foo
882 extern __typeof (__redirect_foo) __foo_default attribute_hidden;
883 extern __typeof (__redirect_foo) __foo_special attribute_hidden;
885 libc_ifunc_redirected (__redirect_foo, foo,
886 (hwcap & HWCAP_SPECIAL)
887 ? __foo_special
888 : __foo_default);
890 This will define the ifunc'ed symbol foo like above. The redirection of foo
891 in header file is needed to omit an additional defintion of __GI_foo which
892 would end in a linker error while linking libc.so. You have to specify
893 __redirect_foo as first parameter which is used within libc_ifunc_redirected
894 macro in conjunction with typeof to define the ifunc'ed symbol foo.
896 If your function foo has a libc_hidden_proto (foo) defined and calls to foo
897 within or from outside libc.so should go via ifunc'ed symbol, then you have
898 to use:
900 libc_ifunc_hidden (foo, foo,
901 (hwcap & HWCAP_SPECIAL)
902 ? __foo_special
903 : __foo_default);
904 libc_hidden_def (foo)
906 The first parameter foo of libc_ifunc_hidden macro is used in the same way
907 as for libc_ifunc_redirected macro. */
909 #define libc_ifunc(name, expr) __ifunc (name, name, expr, void, INIT_ARCH)
911 #define libc_ifunc_redirected(redirected_name, name, expr) \
912 __ifunc (redirected_name, name, expr, void, INIT_ARCH)
914 #define libc_ifunc_hidden(redirected_name, name, expr) \
915 __ifunc_hidden (redirected_name, name, expr, void, INIT_ARCH)
917 /* The body of the function is supposed to use __get_cpu_features
918 which will, if necessary, initialize the data first. */
919 #define libm_ifunc_init()
920 #define libm_ifunc(name, expr) \
921 __ifunc (name, name, expr, void, libm_ifunc_init)
923 /* Add the compiler optimization to inhibit loop transformation to library
924 calls. This is used to avoid recursive calls in memset and memmove
925 default implementations. */
926 #ifdef HAVE_CC_INHIBIT_LOOP_TO_LIBCALL
927 # define inhibit_loop_to_libcall \
928 __attribute__ ((__optimize__ ("-fno-tree-loop-distribute-patterns")))
929 #else
930 # define inhibit_loop_to_libcall
931 #endif
933 /* These macros facilitate sharing source files with gnulib.
935 They are here instead of sys/cdefs.h because they should not be
936 used in public header files.
938 Their definitions should be kept consistent with the definitions in
939 gnulib-common.m4, but it is not necessary to cater to old non-GCC
940 compilers, since they will only be used while building glibc itself.
941 (Note that _GNUC_PREREQ cannot be used in this file.) */
943 /* Define as a marker that can be attached to declarations that might not
944 be used. This helps to reduce warnings, such as from
945 GCC -Wunused-parameter. */
946 #if __GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
947 # define _GL_UNUSED __attribute__ ((__unused__))
948 #else
949 # define _GL_UNUSED
950 #endif
952 /* gcc supports the "unused" attribute on possibly unused labels, and
953 g++ has since version 4.5. Note to support C++ as well as C,
954 _GL_UNUSED_LABEL should be used with a trailing ; */
955 #if !defined __cplusplus || __GNUC__ > 4 \
956 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
957 # define _GL_UNUSED_LABEL _GL_UNUSED
958 #else
959 # define _GL_UNUSED_LABEL
960 #endif
962 /* The __pure__ attribute was added in gcc 2.96. */
963 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
964 # define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
965 #else
966 # define _GL_ATTRIBUTE_PURE /* empty */
967 #endif
969 /* The __const__ attribute was added in gcc 2.95. */
970 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)
971 # define _GL_ATTRIBUTE_CONST __attribute__ ((__const__))
972 #else
973 # define _GL_ATTRIBUTE_CONST /* empty */
974 #endif
976 #endif /* !_ISOMAC */
977 #endif /* libc-symbols.h */