S390: Use C11-like atomics instead of plain memory accesses in lock elision code.
[glibc.git] / include / libc-symbols.h
blob4238d7930b7e2c40629318d6380ea14c97205a30
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-2016 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 #define IN_MODULE PASTE_NAME (MODULE_, MODULE_NAME)
24 #define IS_IN(lib) (IN_MODULE == MODULE_##lib)
26 /* Returns true if the current module is a versioned library. Versioned
27 library names culled from shlib-versions files are assigned a MODULE_*
28 value lower than MODULE_LIBS_BEGIN. */
29 #define IS_IN_LIB (IN_MODULE > MODULE_LIBS_BEGIN)
31 #define PASTE_NAME(a,b) PASTE_NAME1 (a,b)
32 #define PASTE_NAME1(a,b) a##b
34 /* This file's macros are included implicitly in the compilation of every
35 file in the C library by -imacros.
37 We include config.h which is generated by configure.
38 It should define for us the following symbol:
40 * HAVE_ASM_SET_DIRECTIVE if we have `.set B, A' instead of `A = B'.
44 /* This is defined for the compilation of all C library code. features.h
45 tests this to avoid inclusion of stubs.h while compiling the library,
46 before stubs.h has been generated. Some library code that is shared
47 with other packages also tests this symbol to see if it is being
48 compiled as part of the C library. We must define this before including
49 config.h, because it makes some definitions conditional on whether libc
50 itself is being compiled, or just some generator program. */
51 #define _LIBC 1
53 /* Enable declarations of GNU extensions, since we are compiling them. */
54 #define _GNU_SOURCE 1
56 #include <config.h>
58 /* Define this for the benefit of portable GNU code that wants to check it.
59 Code that checks with #if will not #include <config.h> again, since we've
60 already done it (and this file is implicitly included in every compile,
61 via -include). Code that checks with #ifdef will #include <config.h>,
62 but that file should always be idempotent (i.e., it's just #define/#undef
63 and nothing else anywhere should be changing the macro state it touches),
64 so it's harmless. */
65 #define HAVE_CONFIG_H 0
67 /* Define these macros for the benefit of portable GNU code that wants to check
68 them. Of course, STDC_HEADERS is never false when building libc! */
69 #define STDC_HEADERS 1
70 #define HAVE_MBSTATE_T 1
71 #define HAVE_MBSRTOWCS 1
72 #define HAVE_LIBINTL_H 1
73 #define HAVE_WCTYPE_H 1
74 #define HAVE_ISWCTYPE 1
75 #define ENABLE_NLS 1
77 /* The symbols in all the user (non-_) macros are C symbols. */
79 #ifndef __SYMBOL_PREFIX
80 # define __SYMBOL_PREFIX
81 #endif
83 #ifndef C_SYMBOL_NAME
84 # define C_SYMBOL_NAME(name) name
85 #endif
87 #ifndef ASM_LINE_SEP
88 # define ASM_LINE_SEP ;
89 #endif
91 #ifndef __ASSEMBLER__
92 /* GCC understands weak symbols and aliases; use its interface where
93 possible, instead of embedded assembly language. */
95 /* Define ALIASNAME as a strong alias for NAME. */
96 # define strong_alias(name, aliasname) _strong_alias(name, aliasname)
97 # define _strong_alias(name, aliasname) \
98 extern __typeof (name) aliasname __attribute__ ((alias (#name)));
100 /* This comes between the return type and function name in
101 a function definition to make that definition weak. */
102 # define weak_function __attribute__ ((weak))
103 # define weak_const_function __attribute__ ((weak, __const__))
105 /* Define ALIASNAME as a weak alias for NAME.
106 If weak aliases are not available, this defines a strong alias. */
107 # define weak_alias(name, aliasname) _weak_alias (name, aliasname)
108 # define _weak_alias(name, aliasname) \
109 extern __typeof (name) aliasname __attribute__ ((weak, alias (#name)));
111 /* Same as WEAK_ALIAS, but mark symbol as hidden. */
112 # define weak_hidden_alias(name, aliasname) \
113 _weak_hidden_alias (name, aliasname)
114 # define _weak_hidden_alias(name, aliasname) \
115 extern __typeof (name) aliasname \
116 __attribute__ ((weak, alias (#name), __visibility__ ("hidden")));
118 /* Declare SYMBOL as weak undefined symbol (resolved to 0 if not defined). */
119 # define weak_extern(symbol) _weak_extern (weak symbol)
120 # define _weak_extern(expr) _Pragma (#expr)
122 /* In shared builds, the expression call_function_static_weak
123 (FUNCTION-SYMBOL, ARGUMENTS) invokes FUNCTION-SYMBOL (an
124 identifier) unconditionally, with the (potentially empty) argument
125 list ARGUMENTS. In static builds, if FUNCTION-SYMBOL has a
126 definition, the function is invoked as before; if FUNCTION-SYMBOL
127 is NULL, no call is performed. */
128 # ifdef SHARED
129 # define call_function_static_weak(func, ...) func (__VA_ARGS__)
130 # else /* !SHARED */
131 # define call_function_static_weak(func, ...) \
132 ({ \
133 extern __typeof__ (func) func weak_function; \
134 (func != NULL ? func (__VA_ARGS__) : (void)0); \
136 # endif
138 #else /* __ASSEMBLER__ */
140 # ifdef HAVE_ASM_SET_DIRECTIVE
141 # define strong_alias(original, alias) \
142 .globl C_SYMBOL_NAME (alias) ASM_LINE_SEP \
143 .set C_SYMBOL_NAME (alias),C_SYMBOL_NAME (original)
144 # define strong_data_alias(original, alias) strong_alias(original, alias)
145 # else
146 # define strong_alias(original, alias) \
147 .globl C_SYMBOL_NAME (alias) ASM_LINE_SEP \
148 C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original)
149 # define strong_data_alias(original, alias) strong_alias(original, alias)
150 # endif
152 # define weak_alias(original, alias) \
153 .weak C_SYMBOL_NAME (alias) ASM_LINE_SEP \
154 C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original)
156 # define weak_extern(symbol) \
157 .weak C_SYMBOL_NAME (symbol)
159 #endif /* __ASSEMBLER__ */
161 /* On some platforms we can make internal function calls (i.e., calls of
162 functions not exported) a bit faster by using a different calling
163 convention. */
164 #ifndef internal_function
165 # define internal_function /* empty */
166 #endif
168 /* Determine the return address. */
169 #define RETURN_ADDRESS(nr) \
170 __builtin_extract_return_addr (__builtin_return_address (nr))
172 /* When a reference to SYMBOL is encountered, the linker will emit a
173 warning message MSG. */
174 /* We want the .gnu.warning.SYMBOL section to be unallocated. */
175 #define __make_section_unallocated(section_string) \
176 asm (".section " section_string "\n\t.previous");
178 /* Tacking on "\n\t#" to the section name makes gcc put it's bogus
179 section attributes on what looks like a comment to the assembler. */
180 #ifdef HAVE_SECTION_QUOTES
181 # define __sec_comment "\"\n\t#\""
182 #else
183 # define __sec_comment "\n\t#"
184 #endif
185 #define link_warning(symbol, msg) \
186 __make_section_unallocated (".gnu.warning." #symbol) \
187 static const char __evoke_link_warning_##symbol[] \
188 __attribute__ ((used, section (".gnu.warning." #symbol __sec_comment))) \
189 = msg;
190 #define libc_freeres_ptr(decl) \
191 __make_section_unallocated ("__libc_freeres_ptrs, \"aw\", %nobits") \
192 decl __attribute__ ((section ("__libc_freeres_ptrs" __sec_comment)))
193 #define __libc_freeres_fn_section \
194 __attribute__ ((section ("__libc_freeres_fn")))
196 #define libc_freeres_fn(name) \
197 static void name (void) __attribute_used__ __libc_freeres_fn_section; \
198 text_set_element (__libc_subfreeres, name); \
199 static void name (void)
201 /* A canned warning for sysdeps/stub functions. */
202 #define stub_warning(name) \
203 __make_section_unallocated (".gnu.glibc-stub." #name) \
204 link_warning (name, #name " is not implemented and will always fail")
206 /* Warning for linking functions calling dlopen into static binaries. */
207 #ifdef SHARED
208 #define static_link_warning(name)
209 #else
210 #define static_link_warning(name) static_link_warning1(name)
211 #define static_link_warning1(name) \
212 link_warning(name, "Using '" #name "' in statically linked applications \
213 requires at runtime the shared libraries from the glibc version used \
214 for linking")
215 #endif
217 /* Declare SYMBOL to be TYPE (`function' or `object') of SIZE bytes
218 alias to ORIGINAL, when the assembler supports such declarations
219 (such as in ELF).
220 This is only necessary when defining something in assembly, or playing
221 funny alias games where the size should be other than what the compiler
222 thinks it is. */
223 #define declare_symbol_alias(symbol, original, type, size) \
224 declare_symbol_alias_1 (symbol, original, type, size)
225 #ifdef __ASSEMBLER__
226 # define declare_symbol_alias_1(symbol, original, type, size) \
227 strong_alias (original, symbol); \
228 .type C_SYMBOL_NAME (symbol), %##type; \
229 .size C_SYMBOL_NAME (symbol), size
230 #else /* Not __ASSEMBLER__. */
231 # define declare_symbol_alias_1(symbol, original, type, size) \
232 asm (".globl " __SYMBOL_PREFIX #symbol \
233 "\n\t" declare_symbol_alias_1_alias (symbol, original) \
234 "\n\t.type " __SYMBOL_PREFIX #symbol ", " \
235 "%" #type \
236 "\n\t.size " __SYMBOL_PREFIX #symbol ", " #size);
237 # ifdef HAVE_ASM_SET_DIRECTIVE
238 # define declare_symbol_alias_1_alias(symbol, original) \
239 ".set " __SYMBOL_PREFIX #symbol ", " __SYMBOL_PREFIX #original
240 # else
241 # define declare_symbol_alias_1_alias(symbol, original) \
242 __SYMBOL_PREFIX #symbol " = " __SYMBOL_PREFIX #original
243 # endif /* HAVE_ASM_SET_DIRECTIVE */
244 #endif /* __ASSEMBLER__ */
251 /* Symbol set support macros. */
253 /* Make SYMBOL, which is in the text segment, an element of SET. */
254 #define text_set_element(set, symbol) _elf_set_element(set, symbol)
255 /* Make SYMBOL, which is in the data segment, an element of SET. */
256 #define data_set_element(set, symbol) _elf_set_element(set, symbol)
257 /* Make SYMBOL, which is in the bss segment, an element of SET. */
258 #define bss_set_element(set, symbol) _elf_set_element(set, symbol)
260 /* These are all done the same way in ELF.
261 There is a new section created for each set. */
262 #ifdef SHARED
263 /* When building a shared library, make the set section writable,
264 because it will need to be relocated at run time anyway. */
265 # define _elf_set_element(set, symbol) \
266 static const void *__elf_set_##set##_element_##symbol##__ \
267 __attribute__ ((used, section (#set))) = &(symbol)
268 #else
269 # define _elf_set_element(set, symbol) \
270 static const void *const __elf_set_##set##_element_##symbol##__ \
271 __attribute__ ((used, section (#set))) = &(symbol)
272 #endif
274 /* Define SET as a symbol set. This may be required (it is in a.out) to
275 be able to use the set's contents. */
276 #define symbol_set_define(set) symbol_set_declare(set)
278 /* Declare SET for use in this module, if defined in another module.
279 In a shared library, this is always local to that shared object.
280 For static linking, the set might be wholly absent and so we use
281 weak references. */
282 #define symbol_set_declare(set) \
283 extern char const __start_##set[] __symbol_set_attribute; \
284 extern char const __stop_##set[] __symbol_set_attribute;
285 #ifdef SHARED
286 # define __symbol_set_attribute attribute_hidden
287 #else
288 # define __symbol_set_attribute __attribute__ ((weak))
289 #endif
291 /* Return a pointer (void *const *) to the first element of SET. */
292 #define symbol_set_first_element(set) ((void *const *) (&__start_##set))
294 /* Return true iff PTR (a void *const *) has been incremented
295 past the last element in SET. */
296 #define symbol_set_end_p(set, ptr) ((ptr) >= (void *const *) &__stop_##set)
298 /* Use symbol_version_reference to specify the version a symbol
299 reference should link to. Use symbol_version or
300 default_symbol_version for the definition of a versioned symbol.
301 The difference is that the latter is a no-op in non-shared
302 builds. */
303 #ifdef __ASSEMBLER__
304 # define symbol_version_reference(real, name, version) \
305 .symver real, name##@##version
306 #else /* !__ASSEMBLER__ */
307 # define symbol_version_reference(real, name, version) \
308 __asm__ (".symver " #real "," #name "@" #version)
309 #endif
311 #ifdef SHARED
312 # define symbol_version(real, name, version) \
313 symbol_version_reference(real, name, version)
314 # define default_symbol_version(real, name, version) \
315 _default_symbol_version(real, name, version)
316 # ifdef __ASSEMBLER__
317 # define _default_symbol_version(real, name, version) \
318 .symver real, name##@##@##version
319 # else
320 # define _default_symbol_version(real, name, version) \
321 __asm__ (".symver " #real "," #name "@@" #version)
322 # endif
323 #else
324 # define symbol_version(real, name, version)
325 # define default_symbol_version(real, name, version) \
326 strong_alias(real, name)
327 #endif
329 #if defined SHARED || defined LIBC_NONSHARED
330 # define attribute_hidden __attribute__ ((visibility ("hidden")))
331 #else
332 # define attribute_hidden
333 #endif
335 #define attribute_tls_model_ie __attribute__ ((tls_model ("initial-exec")))
337 #define attribute_relro __attribute__ ((section (".data.rel.ro")))
339 /* The following macros are used for PLT bypassing within libc.so
340 (and if needed other libraries similarly).
341 First of all, you need to have the function prototyped somewhere,
342 say in foo/foo.h:
344 int foo (int __bar);
346 If calls to foo within libc.so should always go to foo defined in libc.so,
347 then in include/foo.h you add:
349 libc_hidden_proto (foo)
351 line and after the foo function definition:
353 int foo (int __bar)
355 return __bar;
357 libc_hidden_def (foo)
361 int foo (int __bar)
363 return __bar;
365 libc_hidden_weak (foo)
367 Similarly for global data. If references to foo within libc.so should
368 always go to foo defined in libc.so, then in include/foo.h you add:
370 libc_hidden_proto (foo)
372 line and after foo's definition:
374 int foo = INITIAL_FOO_VALUE;
375 libc_hidden_data_def (foo)
379 int foo = INITIAL_FOO_VALUE;
380 libc_hidden_data_weak (foo)
382 If foo is normally just an alias (strong or weak) to some other function,
383 you should use the normal strong_alias first, then add libc_hidden_def
384 or libc_hidden_weak:
386 int baz (int __bar)
388 return __bar;
390 strong_alias (baz, foo)
391 libc_hidden_weak (foo)
393 If the function should be internal to multiple objects, say ld.so and
394 libc.so, the best way is to use:
396 #if IS_IN (libc) || IS_IN (rtld)
397 hidden_proto (foo)
398 #endif
400 in include/foo.h and the normal macros at all function definitions
401 depending on what DSO they belong to.
403 If versioned_symbol macro is used to define foo,
404 libc_hidden_ver macro should be used, as in:
406 int __real_foo (int __bar)
408 return __bar;
410 versioned_symbol (libc, __real_foo, foo, GLIBC_2_1);
411 libc_hidden_ver (__real_foo, foo) */
413 #if defined SHARED && !defined NO_HIDDEN
414 # ifndef __ASSEMBLER__
415 # define __hidden_proto_hiddenattr(attrs...) \
416 __attribute__ ((visibility ("hidden"), ##attrs))
417 # define hidden_proto(name, attrs...) \
418 __hidden_proto (name, , __GI_##name, ##attrs)
419 # define hidden_tls_proto(name, attrs...) \
420 __hidden_proto (name, __thread, __GI_##name, ##attrs)
421 # define __hidden_proto(name, thread, internal, attrs...) \
422 extern thread __typeof (name) name __asm__ (__hidden_asmname (#internal)) \
423 __hidden_proto_hiddenattr (attrs);
424 # define __hidden_asmname(name) \
425 __hidden_asmname1 (__USER_LABEL_PREFIX__, name)
426 # define __hidden_asmname1(prefix, name) __hidden_asmname2(prefix, name)
427 # define __hidden_asmname2(prefix, name) #prefix name
428 # define __hidden_ver1(local, internal, name) \
429 extern __typeof (name) __EI_##name __asm__(__hidden_asmname (#internal)); \
430 extern __typeof (name) __EI_##name \
431 __attribute__((alias (__hidden_asmname (#local))))
432 # define hidden_ver(local, name) __hidden_ver1(local, __GI_##name, name);
433 # define hidden_data_ver(local, name) hidden_ver(local, name)
434 # define hidden_def(name) __hidden_ver1(__GI_##name, name, name);
435 # define hidden_data_def(name) hidden_def(name)
436 # define hidden_weak(name) \
437 __hidden_ver1(__GI_##name, name, name) __attribute__((weak));
438 # define hidden_data_weak(name) hidden_weak(name)
439 # define hidden_nolink(name, lib, version) \
440 __hidden_nolink1 (__GI_##name, __EI_##name, name, VERSION_##lib##_##version)
441 # define __hidden_nolink1(local, internal, name, version) \
442 __hidden_nolink2 (local, internal, name, version)
443 # define __hidden_nolink2(local, internal, name, version) \
444 extern __typeof (name) internal __attribute__ ((alias (#local))); \
445 __hidden_nolink3 (local, internal, #name "@" #version)
446 # define __hidden_nolink3(local, internal, vername) \
447 __asm__ (".symver " #internal ", " vername);
448 # else
449 /* For assembly, we need to do the opposite of what we do in C:
450 in assembly gcc __REDIRECT stuff is not in place, so functions
451 are defined by its normal name and we need to create the
452 __GI_* alias to it, in C __REDIRECT causes the function definition
453 to use __GI_* name and we need to add alias to the real name.
454 There is no reason to use hidden_weak over hidden_def in assembly,
455 but we provide it for consistency with the C usage.
456 hidden_proto doesn't make sense for assembly but the equivalent
457 is to call via the HIDDEN_JUMPTARGET macro instead of JUMPTARGET. */
458 # define hidden_def(name) strong_alias (name, __GI_##name)
459 # define hidden_weak(name) hidden_def (name)
460 # define hidden_ver(local, name) strong_alias (local, __GI_##name)
461 # define hidden_data_def(name) strong_data_alias (name, __GI_##name)
462 # define hidden_data_weak(name) hidden_data_def (name)
463 # define hidden_data_ver(local, name) strong_data_alias (local, __GI_##name)
464 # define HIDDEN_JUMPTARGET(name) __GI_##name
465 # endif
466 #else
467 # ifndef __ASSEMBLER__
468 # define hidden_proto(name, attrs...)
469 # define hidden_tls_proto(name, attrs...)
470 # else
471 # define HIDDEN_JUMPTARGET(name) JUMPTARGET(name)
472 # endif /* Not __ASSEMBLER__ */
473 # define hidden_weak(name)
474 # define hidden_def(name)
475 # define hidden_ver(local, name)
476 # define hidden_data_weak(name)
477 # define hidden_data_def(name)
478 # define hidden_data_ver(local, name)
479 # define hidden_nolink(name, lib, version)
480 #endif
482 #if IS_IN (libc)
483 # define libc_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
484 # define libc_hidden_tls_proto(name, attrs...) hidden_tls_proto (name, ##attrs)
485 # define libc_hidden_def(name) hidden_def (name)
486 # define libc_hidden_weak(name) hidden_weak (name)
487 # ifdef LINK_OBSOLETE_RPC
488 /* libc_hidden_nolink_sunrpc should only get used in sunrpc code. */
489 # define libc_hidden_nolink_sunrpc(name, version) hidden_def (name)
490 # else
491 # define libc_hidden_nolink_sunrpc(name, version) hidden_nolink (name, libc, version)
492 # endif
493 # define libc_hidden_ver(local, name) hidden_ver (local, name)
494 # define libc_hidden_data_def(name) hidden_data_def (name)
495 # define libc_hidden_data_weak(name) hidden_data_weak (name)
496 # define libc_hidden_data_ver(local, name) hidden_data_ver (local, name)
497 #else
498 # define libc_hidden_proto(name, attrs...)
499 # define libc_hidden_tls_proto(name, attrs...)
500 # define libc_hidden_def(name)
501 # define libc_hidden_weak(name)
502 # define libc_hidden_ver(local, name)
503 # define libc_hidden_data_def(name)
504 # define libc_hidden_data_weak(name)
505 # define libc_hidden_data_ver(local, name)
506 #endif
508 #if IS_IN (rtld)
509 # define rtld_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
510 # define rtld_hidden_tls_proto(name, attrs...) hidden_tls_proto (name, ##attrs)
511 # define rtld_hidden_def(name) hidden_def (name)
512 # define rtld_hidden_weak(name) hidden_weak (name)
513 # define rtld_hidden_ver(local, name) hidden_ver (local, name)
514 # define rtld_hidden_data_def(name) hidden_data_def (name)
515 # define rtld_hidden_data_weak(name) hidden_data_weak (name)
516 # define rtld_hidden_data_ver(local, name) hidden_data_ver (local, name)
517 #else
518 # define rtld_hidden_proto(name, attrs...)
519 # define rtld_hidden_tls_proto(name, attrs...)
520 # define rtld_hidden_def(name)
521 # define rtld_hidden_weak(name)
522 # define rtld_hidden_ver(local, name)
523 # define rtld_hidden_data_def(name)
524 # define rtld_hidden_data_weak(name)
525 # define rtld_hidden_data_ver(local, name)
526 #endif
528 #if IS_IN (libm)
529 # define libm_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
530 # define libm_hidden_tls_proto(name, attrs...) hidden_tls_proto (name, ##attrs)
531 # define libm_hidden_def(name) hidden_def (name)
532 # define libm_hidden_weak(name) hidden_weak (name)
533 # define libm_hidden_ver(local, name) hidden_ver (local, name)
534 # define libm_hidden_data_def(name) hidden_data_def (name)
535 # define libm_hidden_data_weak(name) hidden_data_weak (name)
536 # define libm_hidden_data_ver(local, name) hidden_data_ver (local, name)
537 #else
538 # define libm_hidden_proto(name, attrs...)
539 # define libm_hidden_tls_proto(name, attrs...)
540 # define libm_hidden_def(name)
541 # define libm_hidden_weak(name)
542 # define libm_hidden_ver(local, name)
543 # define libm_hidden_data_def(name)
544 # define libm_hidden_data_weak(name)
545 # define libm_hidden_data_ver(local, name)
546 #endif
548 #if IS_IN (libmvec)
549 # define libmvec_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
550 # define libmvec_hidden_tls_proto(name, attrs...) hidden_tls_proto (name, ##attrs)
551 # define libmvec_hidden_def(name) hidden_def (name)
552 # define libmvec_hidden_weak(name) hidden_weak (name)
553 # define libmvec_hidden_ver(local, name) hidden_ver (local, name)
554 # define libmvec_hidden_data_def(name) hidden_data_def (name)
555 # define libmvec_hidden_data_weak(name) hidden_data_weak (name)
556 # define libmvec_hidden_data_ver(local, name) hidden_data_ver (local, name)
557 #else
558 # define libmvec_hidden_proto(name, attrs...)
559 # define libmvec_hidden_tls_proto(name, attrs...)
560 # define libmvec_hidden_def(name)
561 # define libmvec_hidden_weak(name)
562 # define libmvec_hidden_ver(local, name)
563 # define libmvec_hidden_data_def(name)
564 # define libmvec_hidden_data_weak(name)
565 # define libmvec_hidden_data_ver(local, name)
566 #endif
568 #if IS_IN (libresolv)
569 # define libresolv_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
570 # define libresolv_hidden_tls_proto(name, attrs...) \
571 hidden_tls_proto (name, ##attrs)
572 # define libresolv_hidden_def(name) hidden_def (name)
573 # define libresolv_hidden_weak(name) hidden_weak (name)
574 # define libresolv_hidden_ver(local, name) hidden_ver (local, name)
575 # define libresolv_hidden_data_def(name) hidden_data_def (name)
576 # define libresolv_hidden_data_weak(name) hidden_data_weak (name)
577 # define libresolv_hidden_data_ver(local, name) hidden_data_ver (local, name)
578 #else
579 # define libresolv_hidden_proto(name, attrs...)
580 # define libresolv_hidden_tls_proto(name, attrs...)
581 # define libresolv_hidden_def(name)
582 # define libresolv_hidden_weak(name)
583 # define libresolv_hidden_ver(local, name)
584 # define libresolv_hidden_data_def(name)
585 # define libresolv_hidden_data_weak(name)
586 # define libresolv_hidden_data_ver(local, name)
587 #endif
589 #if IS_IN (librt)
590 # define librt_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
591 # define librt_hidden_tls_proto(name, attrs...) \
592 hidden_tls_proto (name, ##attrs)
593 # define librt_hidden_def(name) hidden_def (name)
594 # define librt_hidden_weak(name) hidden_weak (name)
595 # define librt_hidden_ver(local, name) hidden_ver (local, name)
596 # define librt_hidden_data_def(name) hidden_data_def (name)
597 # define librt_hidden_data_weak(name) hidden_data_weak (name)
598 # define librt_hidden_data_ver(local, name) hidden_data_ver (local, name)
599 #else
600 # define librt_hidden_proto(name, attrs...)
601 # define librt_hidden_tls_proto(name, attrs...)
602 # define librt_hidden_def(name)
603 # define librt_hidden_weak(name)
604 # define librt_hidden_ver(local, name)
605 # define librt_hidden_data_def(name)
606 # define librt_hidden_data_weak(name)
607 # define librt_hidden_data_ver(local, name)
608 #endif
610 #if IS_IN (libdl)
611 # define libdl_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
612 # define libdl_hidden_tls_proto(name, attrs...) \
613 hidden_tls_proto (name, ##attrs)
614 # define libdl_hidden_def(name) hidden_def (name)
615 # define libdl_hidden_weak(name) hidden_weak (name)
616 # define libdl_hidden_ver(local, name) hidden_ver (local, name)
617 # define libdl_hidden_data_def(name) hidden_data_def (name)
618 # define libdl_hidden_data_weak(name) hidden_data_weak (name)
619 # define libdl_hidden_data_ver(local, name) hidden_data_ver (local, name)
620 #else
621 # define libdl_hidden_proto(name, attrs...)
622 # define libdl_hidden_tls_proto(name, attrs...)
623 # define libdl_hidden_def(name)
624 # define libdl_hidden_weak(name)
625 # define libdl_hidden_ver(local, name)
626 # define libdl_hidden_data_def(name)
627 # define libdl_hidden_data_weak(name)
628 # define libdl_hidden_data_ver(local, name)
629 #endif
631 #if IS_IN (libnss_files)
632 # define libnss_files_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
633 # define libnss_files_hidden_tls_proto(name, attrs...) \
634 hidden_tls_proto (name, ##attrs)
635 # define libnss_files_hidden_def(name) hidden_def (name)
636 # define libnss_files_hidden_weak(name) hidden_weak (name)
637 # define libnss_files_hidden_ver(local, name) hidden_ver (local, name)
638 # define libnss_files_hidden_data_def(name) hidden_data_def (name)
639 # define libnss_files_hidden_data_weak(name) hidden_data_weak (name)
640 # define libnss_files_hidden_data_ver(local, name) hidden_data_ver(local, name)
641 #else
642 # define libnss_files_hidden_proto(name, attrs...)
643 # define libnss_files_hidden_tls_proto(name, attrs...)
644 # define libnss_files_hidden_def(name)
645 # define libnss_files_hidden_weak(name)
646 # define libnss_files_hidden_ver(local, name)
647 # define libnss_files_hidden_data_def(name)
648 # define libnss_files_hidden_data_weak(name)
649 # define libnss_files_hidden_data_ver(local, name)
650 #endif
652 #if IS_IN (libnsl)
653 # define libnsl_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
654 # define libnsl_hidden_tls_proto(name, attrs...) \
655 hidden_tls_proto (name, ##attrs)
656 # define libnsl_hidden_def(name) hidden_def (name)
657 # define libnsl_hidden_weak(name) hidden_weak (name)
658 # define libnsl_hidden_ver(local, name) hidden_ver (local, name)
659 # define libnsl_hidden_data_def(name) hidden_data_def (name)
660 # define libnsl_hidden_data_weak(name) hidden_data_weak (name)
661 # define libnsl_hidden_data_ver(local, name) hidden_data_ver (local, name)
662 #else
663 # define libnsl_hidden_proto(name, attrs...)
664 # define libnsl_hidden_tls_proto(name, attrs...)
665 # define libnsl_hidden_def(name)
666 # define libnsl_hidden_weak(name)
667 # define libnsl_hidden_ver(local, name)
668 # define libnsl_hidden_data_def(name)
669 # define libnsl_hidden_data_weak(name)
670 # define libnsl_hidden_data_ver(local, name)
671 #endif
673 #if IS_IN (libnss_nisplus)
674 # define libnss_nisplus_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
675 # define libnss_nisplus_hidden_tls_proto(name, attrs...) \
676 hidden_tls_proto (name, ##attrs)
677 # define libnss_nisplus_hidden_def(name) hidden_def (name)
678 # define libnss_nisplus_hidden_weak(name) hidden_weak (name)
679 # define libnss_nisplus_hidden_ver(local, name) hidden_ver (local, name)
680 # define libnss_nisplus_hidden_data_def(name) hidden_data_def (name)
681 # define libnss_nisplus_hidden_data_weak(name) hidden_data_weak (name)
682 # define libnss_nisplus_hidden_data_ver(local, name) hidden_data_ver (local, name)
683 #else
684 # define libnss_nisplus_hidden_proto(name, attrs...)
685 # define libnss_nisplus_hidden_tls_proto(name, attrs...)
686 # define libnss_nisplus_hidden_def(name)
687 # define libnss_nisplus_hidden_weak(name)
688 # define libnss_nisplus_hidden_ver(local, name)
689 # define libnss_nisplus_hidden_data_def(name)
690 # define libnss_nisplus_hidden_data_weak(name)
691 # define libnss_nisplus_hidden_data_ver(local, name)
692 #endif
694 #define libc_hidden_builtin_proto(name, attrs...) libc_hidden_proto (name, ##attrs)
695 #define libc_hidden_builtin_def(name) libc_hidden_def (name)
696 #define libc_hidden_builtin_weak(name) libc_hidden_weak (name)
697 #define libc_hidden_builtin_ver(local, name) libc_hidden_ver (local, name)
698 #ifdef __ASSEMBLER__
699 # define HIDDEN_BUILTIN_JUMPTARGET(name) HIDDEN_JUMPTARGET(name)
700 #endif
702 #if IS_IN (libutil)
703 # define libutil_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
704 # define libutil_hidden_tls_proto(name, attrs...) \
705 hidden_tls_proto (name, ##attrs)
706 # define libutil_hidden_def(name) hidden_def (name)
707 # define libutil_hidden_weak(name) hidden_weak (name)
708 # define libutil_hidden_ver(local, name) hidden_ver (local, name)
709 # define libutil_hidden_data_def(name) hidden_data_def (name)
710 # define libutil_hidden_data_weak(name) hidden_data_weak (name)
711 # define libutil_hidden_data_ver(local, name) hidden_data_ver (local, name)
712 #else
713 # define libutil_hidden_proto(name, attrs...)
714 # define libutil_hidden_tls_proto(name, attrs...)
715 # define libutil_hidden_def(name)
716 # define libutil_hidden_weak(name)
717 # define libutil_hidden_ver(local, name)
718 # define libutil_hidden_data_def(name)
719 # define libutil_hidden_data_weak(name)
720 # define libutil_hidden_data_ver(local, name)
721 #endif
723 /* Get some dirty hacks. */
724 #include <symbol-hacks.h>
726 /* Move compatibility symbols out of the way by placing them all in a
727 special section. */
728 #ifndef __ASSEMBLER__
729 # define attribute_compat_text_section \
730 __attribute__ ((section (".text.compat")))
731 # define attribute_compat_data_section \
732 __attribute__ ((section (".data.compat")))
733 #else
734 # define compat_text_section .section ".text.compat", "ax";
735 # define compat_data_section .section ".data.compat", "aw";
736 #endif
738 /* Helper / base macros for indirect function symbols. */
739 #define __ifunc_resolver(type_name, name, expr, arg, init, classifier) \
740 classifier void *name##_ifunc (arg) \
742 init (); \
743 __typeof (type_name) *res = expr; \
744 return res; \
747 #ifdef HAVE_GCC_IFUNC
748 # define __ifunc(type_name, name, expr, arg, init) \
749 extern __typeof (type_name) name __attribute__ \
750 ((ifunc (#name "_ifunc"))); \
751 __ifunc_resolver (type_name, name, expr, arg, init, static)
753 # define __ifunc_hidden(type_name, name, expr, arg, init) \
754 __ifunc (type_name, name, expr, arg, init)
755 #else
756 /* Gcc does not support __attribute__ ((ifunc (...))). Use the old behaviour
757 as fallback. But keep in mind that the debug information for the ifunc
758 resolver functions is not correct. It contains the ifunc'ed function as
759 DW_AT_linkage_name. E.g. lldb uses this field and an inferior function
760 call of the ifunc'ed function will fail due to "no matching function for
761 call to ..." because the ifunc'ed function and the resolver function have
762 different signatures. (Gcc support is disabled at least on a ppc64le
763 Ubuntu 14.04 system.) */
765 # define __ifunc(type_name, name, expr, arg, init) \
766 extern __typeof (type_name) name; \
767 void *name##_ifunc (arg) __asm__ (#name); \
768 __ifunc_resolver (type_name, name, expr, arg, init,) \
769 __asm__ (".type " #name ", %gnu_indirect_function");
771 # define __ifunc_hidden(type_name, name, expr, arg, init) \
772 extern __typeof (type_name) __libc_##name; \
773 __ifunc (type_name, __libc_##name, expr, arg, init) \
774 strong_alias (__libc_##name, name);
775 #endif /* !HAVE_GCC_IFUNC */
777 /* The following macros are used for indirect function symbols in libc.so.
778 First of all, you need to have the function prototyped somewhere,
779 say in foo.h:
781 int foo (int __bar);
783 If you have an implementation for foo which e.g. uses a special hardware
784 feature which isn't available on all machines where this libc.so will be
785 used but decideable if available at runtime e.g. via hwcaps, you can provide
786 two or multiple implementations of foo:
788 int __foo_default (int __bar)
790 return __bar;
793 int __foo_special (int __bar)
795 return __bar;
798 If your function foo has no libc_hidden_proto (foo) defined for PLT
799 bypassing, you can use:
801 #define INIT_ARCH() unsigned long int hwcap = __GLRO(dl_hwcap);
803 libc_ifunc (foo, (hwcap & HWCAP_SPECIAL) ? __foo_special : __foo_default);
805 This will define a resolver function for foo which returns __foo_special or
806 __foo_default depending on your specified expression. Please note that you
807 have to define a macro function INIT_ARCH before using libc_ifunc macro as
808 it is called by the resolver function before evaluating the specified
809 expression. In this example it is used to prepare the hwcap variable.
810 The resolver function is assigned to an ifunc'ed symbol foo. Calls to foo
811 from inside or outside of libc.so will be indirected by a PLT call.
813 If your function foo has a libc_hidden_proto (foo) defined for PLT bypassing
814 and calls to foo within libc.so should always go to one specific
815 implementation of foo e.g. __foo_default then you have to add:
817 __hidden_ver1 (__foo_default, __GI_foo, __foo_default);
819 or a tweaked definition of libc_hidden_def macro after the __foo_default
820 function definition. Calls to foo within libc.so will always go directly to
821 __foo_default. Calls to foo from outside libc.so will be indirected by a
822 PLT call to ifunc'ed symbol foo which you have to define in a separate
823 compile unit:
825 #define foo __redirect_foo
826 #include <foo.h>
827 #undef foo
829 extern __typeof (__redirect_foo) __foo_default attribute_hidden;
830 extern __typeof (__redirect_foo) __foo_special attribute_hidden;
832 libc_ifunc_redirected (__redirect_foo, foo,
833 (hwcap & HWCAP_SPECIAL)
834 ? __foo_special
835 : __foo_default);
837 This will define the ifunc'ed symbol foo like above. The redirection of foo
838 in header file is needed to omit an additional defintion of __GI_foo which
839 would end in a linker error while linking libc.so. You have to specify
840 __redirect_foo as first parameter which is used within libc_ifunc_redirected
841 macro in conjunction with typeof to define the ifunc'ed symbol foo.
843 If your function foo has a libc_hidden_proto (foo) defined and calls to foo
844 within or from outside libc.so should go via ifunc'ed symbol, then you have
845 to use:
847 libc_ifunc_hidden (foo, foo,
848 (hwcap & HWCAP_SPECIAL)
849 ? __foo_special
850 : __foo_default);
851 libc_hidden_def (foo)
853 The first parameter foo of libc_ifunc_hidden macro is used in the same way
854 as for libc_ifunc_redirected macro. */
856 #define libc_ifunc(name, expr) __ifunc (name, name, expr, void, INIT_ARCH)
858 #define libc_ifunc_redirected(redirected_name, name, expr) \
859 __ifunc (redirected_name, name, expr, void, INIT_ARCH)
861 #define libc_ifunc_hidden(redirected_name, name, expr) \
862 __ifunc_hidden (redirected_name, name, expr, void, INIT_ARCH)
864 /* The body of the function is supposed to use __get_cpu_features
865 which will, if necessary, initialize the data first. */
866 #define libm_ifunc_init()
867 #define libm_ifunc(name, expr) \
868 __ifunc (name, name, expr, void, libm_ifunc_init)
870 /* Add the compiler optimization to inhibit loop transformation to library
871 calls. This is used to avoid recursive calls in memset and memmove
872 default implementations. */
873 #ifdef HAVE_CC_INHIBIT_LOOP_TO_LIBCALL
874 # define inhibit_loop_to_libcall \
875 __attribute__ ((__optimize__ ("-fno-tree-loop-distribute-patterns")))
876 #else
877 # define inhibit_loop_to_libcall
878 #endif
880 #endif /* libc-symbols.h */