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