]> git.ipfire.org Git - thirdparty/glibc.git/blame - include/libc-symbols.h
conformtest: Add x32 XFAILs for mq_attr element types (bug 21279).
[thirdparty/glibc.git] / include / libc-symbols.h
CommitLineData
28f540f4
RM
1/* Support macros for making weak and strong aliases for symbols,
2 and for using symbol sets and linker warnings with GNU ld.
bfff8b1b 3 Copyright (C) 1995-2017 Free Software Foundation, Inc.
5290baf0 4 This file is part of the GNU C Library.
28f540f4 5
5290baf0 6 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
28f540f4 10
5290baf0
UD
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41bdb6e2 14 Lesser General Public License for more details.
28f540f4 15
41bdb6e2 16 You should have received a copy of the GNU Lesser General Public
59ba27a6
PE
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
28f540f4
RM
19
20#ifndef _LIBC_SYMBOLS_H
5290baf0 21#define _LIBC_SYMBOLS_H 1
28f540f4 22
279bc5b3 23#define IN_MODULE PASTE_NAME (MODULE_, MODULE_NAME)
9cd47470
SP
24#define IS_IN(lib) (IN_MODULE == MODULE_##lib)
25
a10178bd
SP
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)
30
279bc5b3
SP
31#define PASTE_NAME(a,b) PASTE_NAME1 (a,b)
32#define PASTE_NAME1(a,b) a##b
33
28f540f4
RM
34/* This file's macros are included implicitly in the compilation of every
35 file in the C library by -imacros.
36
37 We include config.h which is generated by configure.
210dd782 38 It should define for us the following symbol:
28f540f4 39
c224a18a 40 * HAVE_ASM_SET_DIRECTIVE if we have `.set B, A' instead of `A = B'.
28f540f4
RM
41
42 */
28f540f4 43
92777700
RM
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. */
c709e372 51#define _LIBC 1
92777700 52
d3669add
RM
53/* Enable declarations of GNU extensions, since we are compiling them. */
54#define _GNU_SOURCE 1
55
92777700 56#include <config.h>
28f540f4 57
26ffd5e6
RM
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
66
3f3dd810
SP
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! */
26ffd5e6 69#define STDC_HEADERS 1
3f3dd810
SP
70#define HAVE_MBSTATE_T 1
71#define HAVE_MBSRTOWCS 1
a476ac4b
SP
72#define HAVE_LIBINTL_H 1
73#define HAVE_WCTYPE_H 1
74#define HAVE_ISWCTYPE 1
75#define ENABLE_NLS 1
26ffd5e6 76
0269750c 77/* The symbols in all the user (non-_) macros are C symbols. */
28f540f4 78
28f540f4 79#ifndef __SYMBOL_PREFIX
a0da5fe1 80# define __SYMBOL_PREFIX
28f540f4
RM
81#endif
82
83#ifndef C_SYMBOL_NAME
a0da5fe1 84# define C_SYMBOL_NAME(name) name
28f540f4
RM
85#endif
86
b15cb495
UD
87#ifndef ASM_LINE_SEP
88# define ASM_LINE_SEP ;
89#endif
90
428383e8
UD
91#ifndef __ASSEMBLER__
92/* GCC understands weak symbols and aliases; use its interface where
93 possible, instead of embedded assembly language. */
d02907df 94
428383e8 95/* Define ALIASNAME as a strong alias for NAME. */
c62f5cab
GM
96# define strong_alias(name, aliasname) _strong_alias(name, aliasname)
97# define _strong_alias(name, aliasname) \
428383e8
UD
98 extern __typeof (name) aliasname __attribute__ ((alias (#name)));
99
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__))
104
428383e8
UD
105/* Define ALIASNAME as a weak alias for NAME.
106 If weak aliases are not available, this defines a strong alias. */
a0da5fe1
UD
107# define weak_alias(name, aliasname) _weak_alias (name, aliasname)
108# define _weak_alias(name, aliasname) \
428383e8
UD
109 extern __typeof (name) aliasname __attribute__ ((weak, alias (#name)));
110
11bf311e 111/* Same as WEAK_ALIAS, but mark symbol as hidden. */
a0da5fe1 112# define weak_hidden_alias(name, aliasname) \
11bf311e 113 _weak_hidden_alias (name, aliasname)
a0da5fe1 114# define _weak_hidden_alias(name, aliasname) \
11bf311e
UD
115 extern __typeof (name) aliasname \
116 __attribute__ ((weak, alias (#name), __visibility__ ("hidden")));
117
428383e8 118/* Declare SYMBOL as weak undefined symbol (resolved to 0 if not defined). */
a0da5fe1
UD
119# define weak_extern(symbol) _weak_extern (weak symbol)
120# define _weak_extern(expr) _Pragma (#expr)
428383e8 121
ef4f9764
FW
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); \
135 })
136# endif
428383e8
UD
137
138#else /* __ASSEMBLER__ */
139
140# ifdef HAVE_ASM_SET_DIRECTIVE
5ca10a0c 141# define strong_alias(original, alias) \
7b8e0d49 142 .globl C_SYMBOL_NAME (alias) ASM_LINE_SEP \
c843e065 143 .set C_SYMBOL_NAME (alias),C_SYMBOL_NAME (original)
5ca10a0c 144# define strong_data_alias(original, alias) strong_alias(original, alias)
dfd2257a 145# else
5ca10a0c 146# define strong_alias(original, alias) \
7b8e0d49 147 .globl C_SYMBOL_NAME (alias) ASM_LINE_SEP \
c843e065 148 C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original)
5ca10a0c 149# define strong_data_alias(original, alias) strong_alias(original, alias)
dfd2257a 150# endif
d02907df 151
210dd782 152# define weak_alias(original, alias) \
c843e065 153 .weak C_SYMBOL_NAME (alias) ASM_LINE_SEP \
28f540f4 154 C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original)
e6964dd4 155
210dd782 156# define weak_extern(symbol) \
af5b3bc3 157 .weak C_SYMBOL_NAME (symbol)
d02907df 158
428383e8 159#endif /* __ASSEMBLER__ */
958f803f 160
dfd2257a
UD
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
28f540f4 167
e862aada
UD
168/* Determine the return address. */
169#define RETURN_ADDRESS(nr) \
170 __builtin_extract_return_addr (__builtin_return_address (nr))
171
44c8d1a2
RM
172/* When a reference to SYMBOL is encountered, the linker will emit a
173 warning message MSG. */
fd26970f 174/* We want the .gnu.warning.SYMBOL section to be unallocated. */
75b0964b 175#define __make_section_unallocated(section_string) \
b15cb495 176 asm (".section " section_string "\n\t.previous");
fd26970f 177
b15cb495
UD
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. */
0269750c
UD
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) \
e26dd47f 186 __make_section_unallocated (".gnu.warning." #symbol) \
44c8d1a2 187 static const char __evoke_link_warning_##symbol[] \
6c5775c3 188 __attribute__ ((used, section (".gnu.warning." #symbol __sec_comment))) \
c877418f 189 = msg;
0269750c 190#define libc_freeres_ptr(decl) \
362f5ae2 191 __make_section_unallocated ("__libc_freeres_ptrs, \"aw\", %nobits") \
c877418f 192 decl __attribute__ ((section ("__libc_freeres_ptrs" __sec_comment)))
0269750c 193#define __libc_freeres_fn_section \
c877418f 194 __attribute__ ((section ("__libc_freeres_fn")))
0269750c 195
c877418f
RM
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)
28f540f4
RM
200
201/* A canned warning for sysdeps/stub functions. */
202#define stub_warning(name) \
561bcb80 203 __make_section_unallocated (".gnu.glibc-stub." #name) \
cd525923 204 link_warning (name, #name " is not implemented and will always fail")
5f9e57ba 205
2f7f7bc6
UD
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 \
213requires at runtime the shared libraries from the glibc version used \
214for linking")
215#endif
b88ac073 216
11bf311e
UD
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).
b88ac073
RM
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. */
11bf311e
UD
223#define declare_symbol_alias(symbol, original, type, size) \
224 declare_symbol_alias_1 (symbol, original, type, size)
b67e9372
MP
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__ */
b88ac073
RM
245
246
5f9e57ba 247/*
28f540f4 248\f
5f9e57ba
RM
249*/
250
28f540f4
RM
251/* Symbol set support macros. */
252
28f540f4 253/* Make SYMBOL, which is in the text segment, an element of SET. */
0269750c 254#define text_set_element(set, symbol) _elf_set_element(set, symbol)
28f540f4 255/* Make SYMBOL, which is in the data segment, an element of SET. */
0269750c 256#define data_set_element(set, symbol) _elf_set_element(set, symbol)
28f540f4 257/* Make SYMBOL, which is in the bss segment, an element of SET. */
0269750c 258#define bss_set_element(set, symbol) _elf_set_element(set, symbol)
28f540f4
RM
259
260/* These are all done the same way in ELF.
261 There is a new section created for each set. */
0269750c 262#ifdef SHARED
53afa8d9
RM
263/* When building a shared library, make the set section writable,
264 because it will need to be relocated at run time anyway. */
0269750c 265# define _elf_set_element(set, symbol) \
53afa8d9 266 static const void *__elf_set_##set##_element_##symbol##__ \
6c5775c3 267 __attribute__ ((used, section (#set))) = &(symbol)
0269750c
UD
268#else
269# define _elf_set_element(set, symbol) \
28f540f4 270 static const void *const __elf_set_##set##_element_##symbol##__ \
6c5775c3 271 __attribute__ ((used, section (#set))) = &(symbol)
0269750c 272#endif
28f540f4
RM
273
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. */
0269750c 276#define symbol_set_define(set) symbol_set_declare(set)
28f540f4 277
20792f99
RM
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. */
0269750c 282#define symbol_set_declare(set) \
6f1e513d
RH
283 extern char const __start_##set[] __symbol_set_attribute; \
284 extern char const __stop_##set[] __symbol_set_attribute;
0269750c
UD
285#ifdef SHARED
286# define __symbol_set_attribute attribute_hidden
287#else
288# define __symbol_set_attribute __attribute__ ((weak))
289#endif
28f540f4
RM
290
291/* Return a pointer (void *const *) to the first element of SET. */
0269750c 292#define symbol_set_first_element(set) ((void *const *) (&__start_##set))
28f540f4
RM
293
294/* Return true iff PTR (a void *const *) has been incremented
295 past the last element in SET. */
0269750c 296#define symbol_set_end_p(set, ptr) ((ptr) >= (void *const *) &__stop_##set)
28f540f4 297
968dc26d
FW
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
310
3f2e46a4 311#ifdef SHARED
ebdf53a7 312# define symbol_version(real, name, version) \
968dc26d 313 symbol_version_reference(real, name, version)
ebdf53a7
GM
314# define default_symbol_version(real, name, version) \
315 _default_symbol_version(real, name, version)
316# ifdef __ASSEMBLER__
5ca10a0c 317# define _default_symbol_version(real, name, version) \
da2d1bc5
UD
318 .symver real, name##@##@##version
319# else
5ca10a0c 320# define _default_symbol_version(real, name, version) \
f2ea0f5b 321 __asm__ (".symver " #real "," #name "@@" #version)
da2d1bc5 322# endif
1ea89a40
UD
323#else
324# define symbol_version(real, name, version)
da2d1bc5
UD
325# define default_symbol_version(real, name, version) \
326 strong_alias(real, name)
1ea89a40
UD
327#endif
328
11bf311e 329#if defined SHARED || defined LIBC_NONSHARED
e6caf4e1
UD
330# define attribute_hidden __attribute__ ((visibility ("hidden")))
331#else
332# define attribute_hidden
333#endif
334
3ce1f295 335#define attribute_tls_model_ie __attribute__ ((tls_model ("initial-exec")))
9b21e6bc 336
11bf311e 337#define attribute_relro __attribute__ ((section (".data.rel.ro")))
392a6b52 338
de659123
NA
339
340/* Used to disable stack protection in sensitive places, like ifunc
341 resolvers and early static TLS init. */
342#ifdef HAVE_CC_NO_STACK_PROTECTOR
343# define inhibit_stack_protector \
344 __attribute__ ((__optimize__ ("-fno-stack-protector")))
345#else
346# define inhibit_stack_protector
347#endif
348
37ba7d66
UD
349/* The following macros are used for PLT bypassing within libc.so
350 (and if needed other libraries similarly).
351 First of all, you need to have the function prototyped somewhere,
352 say in foo/foo.h:
353
354 int foo (int __bar);
355
356 If calls to foo within libc.so should always go to foo defined in libc.so,
357 then in include/foo.h you add:
358
359 libc_hidden_proto (foo)
360
361 line and after the foo function definition:
362
363 int foo (int __bar)
364 {
365 return __bar;
366 }
367 libc_hidden_def (foo)
368
369 or
370
371 int foo (int __bar)
372 {
373 return __bar;
374 }
375 libc_hidden_weak (foo)
376
5536dfcb 377 Similarly for global data. If references to foo within libc.so should
c843e065
RM
378 always go to foo defined in libc.so, then in include/foo.h you add:
379
380 libc_hidden_proto (foo)
381
382 line and after foo's definition:
383
384 int foo = INITIAL_FOO_VALUE;
385 libc_hidden_data_def (foo)
386
387 or
388
389 int foo = INITIAL_FOO_VALUE;
390 libc_hidden_data_weak (foo)
391
5536dfcb 392 If foo is normally just an alias (strong or weak) to some other function,
37ba7d66
UD
393 you should use the normal strong_alias first, then add libc_hidden_def
394 or libc_hidden_weak:
395
396 int baz (int __bar)
397 {
398 return __bar;
399 }
400 strong_alias (baz, foo)
401 libc_hidden_weak (foo)
402
403 If the function should be internal to multiple objects, say ld.so and
404 libc.so, the best way is to use:
405
9cd47470 406 #if IS_IN (libc) || IS_IN (rtld)
37ba7d66
UD
407 hidden_proto (foo)
408 #endif
409
410 in include/foo.h and the normal macros at all function definitions
411 depending on what DSO they belong to.
412
413 If versioned_symbol macro is used to define foo,
414 libc_hidden_ver macro should be used, as in:
415
416 int __real_foo (int __bar)
417 {
418 return __bar;
419 }
420 versioned_symbol (libc, __real_foo, foo, GLIBC_2_1);
421 libc_hidden_ver (__real_foo, foo) */
422
3f2e46a4 423#if defined SHARED && !defined NO_HIDDEN
37ba7d66 424# ifndef __ASSEMBLER__
11bf311e 425# define __hidden_proto_hiddenattr(attrs...) \
81cb0d82 426 __attribute__ ((visibility ("hidden"), ##attrs))
81cb0d82 427# define hidden_proto(name, attrs...) \
699df45b
JM
428 __hidden_proto (name, , __GI_##name, ##attrs)
429# define hidden_tls_proto(name, attrs...) \
430 __hidden_proto (name, __thread, __GI_##name, ##attrs)
431# define __hidden_proto(name, thread, internal, attrs...) \
432 extern thread __typeof (name) name __asm__ (__hidden_asmname (#internal)) \
81cb0d82 433 __hidden_proto_hiddenattr (attrs);
37ba7d66
UD
434# define __hidden_asmname(name) \
435 __hidden_asmname1 (__USER_LABEL_PREFIX__, name)
436# define __hidden_asmname1(prefix, name) __hidden_asmname2(prefix, name)
437# define __hidden_asmname2(prefix, name) #prefix name
61995d3e
RM
438# define __hidden_ver1(local, internal, name) \
439 extern __typeof (name) __EI_##name __asm__(__hidden_asmname (#internal)); \
440 extern __typeof (name) __EI_##name \
441 __attribute__((alias (__hidden_asmname (#local))))
442# define hidden_ver(local, name) __hidden_ver1(local, __GI_##name, name);
443# define hidden_data_ver(local, name) hidden_ver(local, name)
444# define hidden_def(name) __hidden_ver1(__GI_##name, name, name);
445# define hidden_data_def(name) hidden_def(name)
446# define hidden_weak(name) \
447 __hidden_ver1(__GI_##name, name, name) __attribute__((weak));
448# define hidden_data_weak(name) hidden_weak(name)
7b57bfe5
UD
449# define hidden_nolink(name, lib, version) \
450 __hidden_nolink1 (__GI_##name, __EI_##name, name, VERSION_##lib##_##version)
451# define __hidden_nolink1(local, internal, name, version) \
452 __hidden_nolink2 (local, internal, name, version)
453# define __hidden_nolink2(local, internal, name, version) \
454 extern __typeof (name) internal __attribute__ ((alias (#local))); \
455 __hidden_nolink3 (local, internal, #name "@" #version)
456# define __hidden_nolink3(local, internal, vername) \
457 __asm__ (".symver " #internal ", " vername);
37ba7d66
UD
458# else
459/* For assembly, we need to do the opposite of what we do in C:
460 in assembly gcc __REDIRECT stuff is not in place, so functions
461 are defined by its normal name and we need to create the
462 __GI_* alias to it, in C __REDIRECT causes the function definition
463 to use __GI_* name and we need to add alias to the real name.
4547dee3
RM
464 There is no reason to use hidden_weak over hidden_def in assembly,
465 but we provide it for consistency with the C usage.
466 hidden_proto doesn't make sense for assembly but the equivalent
dce8f2b6 467 is to call via the HIDDEN_JUMPTARGET macro instead of JUMPTARGET. */
4547dee3
RM
468# define hidden_def(name) strong_alias (name, __GI_##name)
469# define hidden_weak(name) hidden_def (name)
37ba7d66 470# define hidden_ver(local, name) strong_alias (local, __GI_##name)
c843e065
RM
471# define hidden_data_def(name) strong_data_alias (name, __GI_##name)
472# define hidden_data_weak(name) hidden_data_def (name)
473# define hidden_data_ver(local, name) strong_data_alias (local, __GI_##name)
5ca10a0c 474# define HIDDEN_JUMPTARGET(name) __GI_##name
37ba7d66
UD
475# endif
476#else
4547dee3 477# ifndef __ASSEMBLER__
81cb0d82 478# define hidden_proto(name, attrs...)
699df45b 479# define hidden_tls_proto(name, attrs...)
4547dee3
RM
480# else
481# define HIDDEN_JUMPTARGET(name) JUMPTARGET(name)
482# endif /* Not __ASSEMBLER__ */
483# define hidden_weak(name)
37ba7d66
UD
484# define hidden_def(name)
485# define hidden_ver(local, name)
c843e065
RM
486# define hidden_data_weak(name)
487# define hidden_data_def(name)
488# define hidden_data_ver(local, name)
1792c087 489# define hidden_nolink(name, lib, version)
37ba7d66
UD
490#endif
491
4f41c682 492#if IS_IN (libc)
81cb0d82 493# define libc_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
699df45b 494# define libc_hidden_tls_proto(name, attrs...) hidden_tls_proto (name, ##attrs)
37ba7d66
UD
495# define libc_hidden_def(name) hidden_def (name)
496# define libc_hidden_weak(name) hidden_weak (name)
021db4be
AJ
497# ifdef LINK_OBSOLETE_RPC
498 /* libc_hidden_nolink_sunrpc should only get used in sunrpc code. */
499# define libc_hidden_nolink_sunrpc(name, version) hidden_def (name)
500# else
501# define libc_hidden_nolink_sunrpc(name, version) hidden_nolink (name, libc, version)
502# endif
37ba7d66 503# define libc_hidden_ver(local, name) hidden_ver (local, name)
c843e065
RM
504# define libc_hidden_data_def(name) hidden_data_def (name)
505# define libc_hidden_data_weak(name) hidden_data_weak (name)
506# define libc_hidden_data_ver(local, name) hidden_data_ver (local, name)
37ba7d66 507#else
81cb0d82 508# define libc_hidden_proto(name, attrs...)
699df45b 509# define libc_hidden_tls_proto(name, attrs...)
37ba7d66
UD
510# define libc_hidden_def(name)
511# define libc_hidden_weak(name)
512# define libc_hidden_ver(local, name)
c843e065
RM
513# define libc_hidden_data_def(name)
514# define libc_hidden_data_weak(name)
515# define libc_hidden_data_ver(local, name)
37ba7d66
UD
516#endif
517
9cd47470 518#if IS_IN (rtld)
81cb0d82 519# define rtld_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
699df45b 520# define rtld_hidden_tls_proto(name, attrs...) hidden_tls_proto (name, ##attrs)
37ba7d66
UD
521# define rtld_hidden_def(name) hidden_def (name)
522# define rtld_hidden_weak(name) hidden_weak (name)
523# define rtld_hidden_ver(local, name) hidden_ver (local, name)
c843e065
RM
524# define rtld_hidden_data_def(name) hidden_data_def (name)
525# define rtld_hidden_data_weak(name) hidden_data_weak (name)
526# define rtld_hidden_data_ver(local, name) hidden_data_ver (local, name)
37ba7d66 527#else
81cb0d82 528# define rtld_hidden_proto(name, attrs...)
699df45b 529# define rtld_hidden_tls_proto(name, attrs...)
37ba7d66
UD
530# define rtld_hidden_def(name)
531# define rtld_hidden_weak(name)
532# define rtld_hidden_ver(local, name)
c843e065
RM
533# define rtld_hidden_data_def(name)
534# define rtld_hidden_data_weak(name)
535# define rtld_hidden_data_ver(local, name)
37ba7d66
UD
536#endif
537
9cd47470 538#if IS_IN (libm)
81cb0d82 539# define libm_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
699df45b 540# define libm_hidden_tls_proto(name, attrs...) hidden_tls_proto (name, ##attrs)
37ba7d66
UD
541# define libm_hidden_def(name) hidden_def (name)
542# define libm_hidden_weak(name) hidden_weak (name)
543# define libm_hidden_ver(local, name) hidden_ver (local, name)
c843e065
RM
544# define libm_hidden_data_def(name) hidden_data_def (name)
545# define libm_hidden_data_weak(name) hidden_data_weak (name)
546# define libm_hidden_data_ver(local, name) hidden_data_ver (local, name)
37ba7d66 547#else
81cb0d82 548# define libm_hidden_proto(name, attrs...)
699df45b 549# define libm_hidden_tls_proto(name, attrs...)
37ba7d66
UD
550# define libm_hidden_def(name)
551# define libm_hidden_weak(name)
552# define libm_hidden_ver(local, name)
c843e065
RM
553# define libm_hidden_data_def(name)
554# define libm_hidden_data_weak(name)
555# define libm_hidden_data_ver(local, name)
37ba7d66
UD
556#endif
557
829a679f
AS
558#if IS_IN (libmvec)
559# define libmvec_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
560# define libmvec_hidden_tls_proto(name, attrs...) hidden_tls_proto (name, ##attrs)
561# define libmvec_hidden_def(name) hidden_def (name)
562# define libmvec_hidden_weak(name) hidden_weak (name)
563# define libmvec_hidden_ver(local, name) hidden_ver (local, name)
564# define libmvec_hidden_data_def(name) hidden_data_def (name)
565# define libmvec_hidden_data_weak(name) hidden_data_weak (name)
566# define libmvec_hidden_data_ver(local, name) hidden_data_ver (local, name)
567#else
568# define libmvec_hidden_proto(name, attrs...)
569# define libmvec_hidden_tls_proto(name, attrs...)
570# define libmvec_hidden_def(name)
571# define libmvec_hidden_weak(name)
572# define libmvec_hidden_ver(local, name)
573# define libmvec_hidden_data_def(name)
574# define libmvec_hidden_data_weak(name)
575# define libmvec_hidden_data_ver(local, name)
576#endif
577
9cd47470 578#if IS_IN (libresolv)
6f9d8e68 579# define libresolv_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
699df45b
JM
580# define libresolv_hidden_tls_proto(name, attrs...) \
581 hidden_tls_proto (name, ##attrs)
6f9d8e68
UD
582# define libresolv_hidden_def(name) hidden_def (name)
583# define libresolv_hidden_weak(name) hidden_weak (name)
584# define libresolv_hidden_ver(local, name) hidden_ver (local, name)
585# define libresolv_hidden_data_def(name) hidden_data_def (name)
586# define libresolv_hidden_data_weak(name) hidden_data_weak (name)
587# define libresolv_hidden_data_ver(local, name) hidden_data_ver (local, name)
588#else
589# define libresolv_hidden_proto(name, attrs...)
699df45b 590# define libresolv_hidden_tls_proto(name, attrs...)
6f9d8e68
UD
591# define libresolv_hidden_def(name)
592# define libresolv_hidden_weak(name)
593# define libresolv_hidden_ver(local, name)
594# define libresolv_hidden_data_def(name)
595# define libresolv_hidden_data_weak(name)
596# define libresolv_hidden_data_ver(local, name)
597#endif
598
9cd47470 599#if IS_IN (librt)
a9564ae9 600# define librt_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
699df45b
JM
601# define librt_hidden_tls_proto(name, attrs...) \
602 hidden_tls_proto (name, ##attrs)
a9564ae9
UD
603# define librt_hidden_def(name) hidden_def (name)
604# define librt_hidden_weak(name) hidden_weak (name)
605# define librt_hidden_ver(local, name) hidden_ver (local, name)
606# define librt_hidden_data_def(name) hidden_data_def (name)
607# define librt_hidden_data_weak(name) hidden_data_weak (name)
608# define librt_hidden_data_ver(local, name) hidden_data_ver (local, name)
609#else
610# define librt_hidden_proto(name, attrs...)
699df45b 611# define librt_hidden_tls_proto(name, attrs...)
a9564ae9
UD
612# define librt_hidden_def(name)
613# define librt_hidden_weak(name)
614# define librt_hidden_ver(local, name)
615# define librt_hidden_data_def(name)
616# define librt_hidden_data_weak(name)
617# define librt_hidden_data_ver(local, name)
618#endif
619
9cd47470 620#if IS_IN (libdl)
5f21997b 621# define libdl_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
699df45b
JM
622# define libdl_hidden_tls_proto(name, attrs...) \
623 hidden_tls_proto (name, ##attrs)
5f21997b
UD
624# define libdl_hidden_def(name) hidden_def (name)
625# define libdl_hidden_weak(name) hidden_weak (name)
626# define libdl_hidden_ver(local, name) hidden_ver (local, name)
627# define libdl_hidden_data_def(name) hidden_data_def (name)
628# define libdl_hidden_data_weak(name) hidden_data_weak (name)
629# define libdl_hidden_data_ver(local, name) hidden_data_ver (local, name)
630#else
631# define libdl_hidden_proto(name, attrs...)
699df45b 632# define libdl_hidden_tls_proto(name, attrs...)
5f21997b
UD
633# define libdl_hidden_def(name)
634# define libdl_hidden_weak(name)
635# define libdl_hidden_ver(local, name)
636# define libdl_hidden_data_def(name)
637# define libdl_hidden_data_weak(name)
638# define libdl_hidden_data_ver(local, name)
639#endif
640
9cd47470 641#if IS_IN (libnss_files)
44843eee 642# define libnss_files_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
699df45b
JM
643# define libnss_files_hidden_tls_proto(name, attrs...) \
644 hidden_tls_proto (name, ##attrs)
44843eee
UD
645# define libnss_files_hidden_def(name) hidden_def (name)
646# define libnss_files_hidden_weak(name) hidden_weak (name)
647# define libnss_files_hidden_ver(local, name) hidden_ver (local, name)
648# define libnss_files_hidden_data_def(name) hidden_data_def (name)
649# define libnss_files_hidden_data_weak(name) hidden_data_weak (name)
650# define libnss_files_hidden_data_ver(local, name) hidden_data_ver(local, name)
651#else
652# define libnss_files_hidden_proto(name, attrs...)
699df45b 653# define libnss_files_hidden_tls_proto(name, attrs...)
44843eee
UD
654# define libnss_files_hidden_def(name)
655# define libnss_files_hidden_weak(name)
656# define libnss_files_hidden_ver(local, name)
657# define libnss_files_hidden_data_def(name)
658# define libnss_files_hidden_data_weak(name)
659# define libnss_files_hidden_data_ver(local, name)
660#endif
661
9cd47470 662#if IS_IN (libnsl)
1d5cee23 663# define libnsl_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
699df45b
JM
664# define libnsl_hidden_tls_proto(name, attrs...) \
665 hidden_tls_proto (name, ##attrs)
1d5cee23
UD
666# define libnsl_hidden_def(name) hidden_def (name)
667# define libnsl_hidden_weak(name) hidden_weak (name)
668# define libnsl_hidden_ver(local, name) hidden_ver (local, name)
669# define libnsl_hidden_data_def(name) hidden_data_def (name)
670# define libnsl_hidden_data_weak(name) hidden_data_weak (name)
671# define libnsl_hidden_data_ver(local, name) hidden_data_ver (local, name)
672#else
673# define libnsl_hidden_proto(name, attrs...)
699df45b 674# define libnsl_hidden_tls_proto(name, attrs...)
1d5cee23
UD
675# define libnsl_hidden_def(name)
676# define libnsl_hidden_weak(name)
677# define libnsl_hidden_ver(local, name)
678# define libnsl_hidden_data_def(name)
679# define libnsl_hidden_data_weak(name)
680# define libnsl_hidden_data_ver(local, name)
681#endif
682
9cd47470 683#if IS_IN (libnss_nisplus)
b31b32b3 684# define libnss_nisplus_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
699df45b
JM
685# define libnss_nisplus_hidden_tls_proto(name, attrs...) \
686 hidden_tls_proto (name, ##attrs)
b31b32b3
UD
687# define libnss_nisplus_hidden_def(name) hidden_def (name)
688# define libnss_nisplus_hidden_weak(name) hidden_weak (name)
689# define libnss_nisplus_hidden_ver(local, name) hidden_ver (local, name)
690# define libnss_nisplus_hidden_data_def(name) hidden_data_def (name)
691# define libnss_nisplus_hidden_data_weak(name) hidden_data_weak (name)
692# define libnss_nisplus_hidden_data_ver(local, name) hidden_data_ver (local, name)
693#else
694# define libnss_nisplus_hidden_proto(name, attrs...)
699df45b 695# define libnss_nisplus_hidden_tls_proto(name, attrs...)
b31b32b3
UD
696# define libnss_nisplus_hidden_def(name)
697# define libnss_nisplus_hidden_weak(name)
698# define libnss_nisplus_hidden_ver(local, name)
699# define libnss_nisplus_hidden_data_def(name)
700# define libnss_nisplus_hidden_data_weak(name)
701# define libnss_nisplus_hidden_data_ver(local, name)
702#endif
703
3ce1f295
UD
704#define libc_hidden_builtin_proto(name, attrs...) libc_hidden_proto (name, ##attrs)
705#define libc_hidden_builtin_def(name) libc_hidden_def (name)
706#define libc_hidden_builtin_weak(name) libc_hidden_weak (name)
707#define libc_hidden_builtin_ver(local, name) libc_hidden_ver (local, name)
708#ifdef __ASSEMBLER__
709# define HIDDEN_BUILTIN_JUMPTARGET(name) HIDDEN_JUMPTARGET(name)
85dd1003
UD
710#endif
711
9cd47470 712#if IS_IN (libutil)
b31b32b3 713# define libutil_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
699df45b
JM
714# define libutil_hidden_tls_proto(name, attrs...) \
715 hidden_tls_proto (name, ##attrs)
b31b32b3
UD
716# define libutil_hidden_def(name) hidden_def (name)
717# define libutil_hidden_weak(name) hidden_weak (name)
718# define libutil_hidden_ver(local, name) hidden_ver (local, name)
719# define libutil_hidden_data_def(name) hidden_data_def (name)
720# define libutil_hidden_data_weak(name) hidden_data_weak (name)
721# define libutil_hidden_data_ver(local, name) hidden_data_ver (local, name)
722#else
723# define libutil_hidden_proto(name, attrs...)
699df45b 724# define libutil_hidden_tls_proto(name, attrs...)
b31b32b3
UD
725# define libutil_hidden_def(name)
726# define libutil_hidden_weak(name)
727# define libutil_hidden_ver(local, name)
728# define libutil_hidden_data_def(name)
729# define libutil_hidden_data_weak(name)
730# define libutil_hidden_data_ver(local, name)
731#endif
732
b30542fb
UD
733/* Get some dirty hacks. */
734#include <symbol-hacks.h>
735
4a381a81
UD
736/* Move compatibility symbols out of the way by placing them all in a
737 special section. */
d3a4a571
UD
738#ifndef __ASSEMBLER__
739# define attribute_compat_text_section \
4a381a81 740 __attribute__ ((section (".text.compat")))
d3a4a571 741# define attribute_compat_data_section \
4a381a81 742 __attribute__ ((section (".data.compat")))
d3a4a571
UD
743#else
744# define compat_text_section .section ".text.compat", "ax";
745# define compat_data_section .section ".data.compat", "aw";
746#endif
4a381a81 747
00980d84
SL
748/* Helper / base macros for indirect function symbols. */
749#define __ifunc_resolver(type_name, name, expr, arg, init, classifier) \
de659123 750 classifier inhibit_stack_protector void *name##_ifunc (arg) \
425ce2ed 751 { \
00980d84
SL
752 init (); \
753 __typeof (type_name) *res = expr; \
425ce2ed 754 return res; \
00980d84
SL
755 }
756
757#ifdef HAVE_GCC_IFUNC
758# define __ifunc(type_name, name, expr, arg, init) \
759 extern __typeof (type_name) name __attribute__ \
760 ((ifunc (#name "_ifunc"))); \
761 __ifunc_resolver (type_name, name, expr, arg, init, static)
762
763# define __ifunc_hidden(type_name, name, expr, arg, init) \
764 __ifunc (type_name, name, expr, arg, init)
765#else
766/* Gcc does not support __attribute__ ((ifunc (...))). Use the old behaviour
767 as fallback. But keep in mind that the debug information for the ifunc
768 resolver functions is not correct. It contains the ifunc'ed function as
769 DW_AT_linkage_name. E.g. lldb uses this field and an inferior function
770 call of the ifunc'ed function will fail due to "no matching function for
771 call to ..." because the ifunc'ed function and the resolver function have
772 different signatures. (Gcc support is disabled at least on a ppc64le
773 Ubuntu 14.04 system.) */
774
775# define __ifunc(type_name, name, expr, arg, init) \
776 extern __typeof (type_name) name; \
777 void *name##_ifunc (arg) __asm__ (#name); \
778 __ifunc_resolver (type_name, name, expr, arg, init,) \
779 __asm__ (".type " #name ", %gnu_indirect_function");
780
781# define __ifunc_hidden(type_name, name, expr, arg, init) \
782 extern __typeof (type_name) __libc_##name; \
783 __ifunc (type_name, __libc_##name, expr, arg, init) \
784 strong_alias (__libc_##name, name);
785#endif /* !HAVE_GCC_IFUNC */
786
787/* The following macros are used for indirect function symbols in libc.so.
788 First of all, you need to have the function prototyped somewhere,
789 say in foo.h:
790
791 int foo (int __bar);
792
793 If you have an implementation for foo which e.g. uses a special hardware
794 feature which isn't available on all machines where this libc.so will be
795 used but decideable if available at runtime e.g. via hwcaps, you can provide
796 two or multiple implementations of foo:
797
798 int __foo_default (int __bar)
799 {
800 return __bar;
801 }
802
803 int __foo_special (int __bar)
804 {
805 return __bar;
806 }
807
808 If your function foo has no libc_hidden_proto (foo) defined for PLT
809 bypassing, you can use:
810
811 #define INIT_ARCH() unsigned long int hwcap = __GLRO(dl_hwcap);
812
813 libc_ifunc (foo, (hwcap & HWCAP_SPECIAL) ? __foo_special : __foo_default);
814
815 This will define a resolver function for foo which returns __foo_special or
816 __foo_default depending on your specified expression. Please note that you
817 have to define a macro function INIT_ARCH before using libc_ifunc macro as
818 it is called by the resolver function before evaluating the specified
819 expression. In this example it is used to prepare the hwcap variable.
820 The resolver function is assigned to an ifunc'ed symbol foo. Calls to foo
821 from inside or outside of libc.so will be indirected by a PLT call.
822
823 If your function foo has a libc_hidden_proto (foo) defined for PLT bypassing
824 and calls to foo within libc.so should always go to one specific
825 implementation of foo e.g. __foo_default then you have to add:
826
827 __hidden_ver1 (__foo_default, __GI_foo, __foo_default);
828
829 or a tweaked definition of libc_hidden_def macro after the __foo_default
830 function definition. Calls to foo within libc.so will always go directly to
831 __foo_default. Calls to foo from outside libc.so will be indirected by a
832 PLT call to ifunc'ed symbol foo which you have to define in a separate
833 compile unit:
834
835 #define foo __redirect_foo
836 #include <foo.h>
837 #undef foo
838
839 extern __typeof (__redirect_foo) __foo_default attribute_hidden;
840 extern __typeof (__redirect_foo) __foo_special attribute_hidden;
841
842 libc_ifunc_redirected (__redirect_foo, foo,
843 (hwcap & HWCAP_SPECIAL)
844 ? __foo_special
845 : __foo_default);
846
847 This will define the ifunc'ed symbol foo like above. The redirection of foo
848 in header file is needed to omit an additional defintion of __GI_foo which
849 would end in a linker error while linking libc.so. You have to specify
850 __redirect_foo as first parameter which is used within libc_ifunc_redirected
851 macro in conjunction with typeof to define the ifunc'ed symbol foo.
852
853 If your function foo has a libc_hidden_proto (foo) defined and calls to foo
854 within or from outside libc.so should go via ifunc'ed symbol, then you have
855 to use:
856
857 libc_ifunc_hidden (foo, foo,
858 (hwcap & HWCAP_SPECIAL)
859 ? __foo_special
860 : __foo_default);
861 libc_hidden_def (foo)
862
863 The first parameter foo of libc_ifunc_hidden macro is used in the same way
864 as for libc_ifunc_redirected macro. */
865
866#define libc_ifunc(name, expr) __ifunc (name, name, expr, void, INIT_ARCH)
867
868#define libc_ifunc_redirected(redirected_name, name, expr) \
869 __ifunc (redirected_name, name, expr, void, INIT_ARCH)
870
871#define libc_ifunc_hidden(redirected_name, name, expr) \
872 __ifunc_hidden (redirected_name, name, expr, void, INIT_ARCH)
425ce2ed 873
9a1d2d45
UD
874/* The body of the function is supposed to use __get_cpu_features
875 which will, if necessary, initialize the data first. */
00980d84
SL
876#define libm_ifunc_init()
877#define libm_ifunc(name, expr) \
878 __ifunc (name, name, expr, void, libm_ifunc_init)
9a1d2d45 879
85c2e611
AZ
880/* Add the compiler optimization to inhibit loop transformation to library
881 calls. This is used to avoid recursive calls in memset and memmove
882 default implementations. */
883#ifdef HAVE_CC_INHIBIT_LOOP_TO_LIBCALL
884# define inhibit_loop_to_libcall \
885 __attribute__ ((__optimize__ ("-fno-tree-loop-distribute-patterns")))
886#else
887# define inhibit_loop_to_libcall
888#endif
889
28f540f4 890#endif /* libc-symbols.h */