[BZ #3427]
[glibc.git] / include / libc-symbols.h
bloba2faeafb32a707d075dedc5d7a858ed5e3da4da6
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-1998,2000-2003,2004,2005,2006
4 Free Software Foundation, Inc.
5 This file is part of the GNU C Library.
7 The GNU C Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 The GNU C Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with the GNU C Library; if not, write to the Free
19 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 02111-1307 USA. */
22 #ifndef _LIBC_SYMBOLS_H
23 #define _LIBC_SYMBOLS_H 1
25 /* This file's macros are included implicitly in the compilation of every
26 file in the C library by -imacros.
28 We include config.h which is generated by configure.
29 It should define for us the following symbols:
31 * HAVE_ASM_SET_DIRECTIVE if we have `.set B, A' instead of `A = B'.
32 * ASM_GLOBAL_DIRECTIVE with `.globl' or `.global'.
33 * ASM_TYPE_DIRECTIVE_PREFIX with `@' or `#' or whatever for .type,
34 or leave it undefined if there is no .type directive.
35 * HAVE_ELF if using ELF, which supports weak symbols using `.weak'.
36 * HAVE_ASM_WEAK_DIRECTIVE if we have weak symbols using `.weak'.
37 * HAVE_ASM_WEAKEXT_DIRECTIVE if we have weak symbols using `.weakext'.
41 /* This is defined for the compilation of all C library code. features.h
42 tests this to avoid inclusion of stubs.h while compiling the library,
43 before stubs.h has been generated. Some library code that is shared
44 with other packages also tests this symbol to see if it is being
45 compiled as part of the C library. We must define this before including
46 config.h, because it makes some definitions conditional on whether libc
47 itself is being compiled, or just some generator program. */
48 #define _LIBC 1
50 /* Enable declarations of GNU extensions, since we are compiling them. */
51 #define _GNU_SOURCE 1
52 /* And we also need the data for the reentrant functions. */
53 #define _REENTRANT 1
55 #include <config.h>
57 /* The symbols in all the user (non-_) macros are C symbols.
58 NO HAVE_ELF implies a.out. */
60 #if defined HAVE_ASM_WEAK_DIRECTIVE || defined HAVE_ASM_WEAKEXT_DIRECTIVE
61 # define HAVE_WEAK_SYMBOLS
62 #endif
64 #ifndef __SYMBOL_PREFIX
65 # ifdef NO_UNDERSCORES
66 # define __SYMBOL_PREFIX
67 # else
68 # define __SYMBOL_PREFIX "_"
69 # endif
70 #endif
72 #ifndef C_SYMBOL_NAME
73 # ifdef NO_UNDERSCORES
74 # define C_SYMBOL_NAME(name) name
75 # else
76 # define C_SYMBOL_NAME(name) _##name
77 # endif
78 #endif
80 #ifndef ASM_LINE_SEP
81 # define ASM_LINE_SEP ;
82 #endif
84 #ifdef HAVE_ASM_GLOBAL_DOT_NAME
85 # ifndef C_SYMBOL_DOT_NAME
86 # if defined __GNUC__ && defined __GNUC_MINOR__ \
87 && (__GNUC__ << 16) + __GNUC_MINOR__ >= (3 << 16) + 1
88 # define C_SYMBOL_DOT_NAME(name) .name
89 # else
90 # define C_SYMBOL_DOT_NAME(name) .##name
91 # endif
92 # endif
93 #endif
95 #ifndef __ASSEMBLER__
96 /* GCC understands weak symbols and aliases; use its interface where
97 possible, instead of embedded assembly language. */
99 /* Define ALIASNAME as a strong alias for NAME. */
100 # define strong_alias(name, aliasname) _strong_alias(name, aliasname)
101 # define _strong_alias(name, aliasname) \
102 extern __typeof (name) aliasname __attribute__ ((alias (#name)));
104 /* This comes between the return type and function name in
105 a function definition to make that definition weak. */
106 # define weak_function __attribute__ ((weak))
107 # define weak_const_function __attribute__ ((weak, __const__))
109 # ifdef HAVE_WEAK_SYMBOLS
111 /* Define ALIASNAME as a weak alias for NAME.
112 If weak aliases are not available, this defines a strong alias. */
113 # define weak_alias(name, aliasname) _weak_alias (name, aliasname)
114 # define _weak_alias(name, aliasname) \
115 extern __typeof (name) aliasname __attribute__ ((weak, alias (#name)));
117 /* Same as WEAK_ALIAS, but mark symbol as hidden. */
118 # define weak_hidden_alias(name, aliasname) \
119 _weak_hidden_alias (name, aliasname)
120 # define _weak_hidden_alias(name, aliasname) \
121 extern __typeof (name) aliasname \
122 __attribute__ ((weak, alias (#name), __visibility__ ("hidden")));
124 /* Declare SYMBOL as weak undefined symbol (resolved to 0 if not defined). */
125 # define weak_extern(symbol) _weak_extern (weak symbol)
126 # define _weak_extern(expr) _Pragma (#expr)
128 # else
130 # define weak_alias(name, aliasname) strong_alias(name, aliasname)
131 # define weak_hidden_alias(name, aliasname) strong_alias(name, aliasname)
132 # define weak_extern(symbol) /* Nothing. */
134 # endif
136 #else /* __ASSEMBLER__ */
138 # ifdef HAVE_ASM_SET_DIRECTIVE
139 # ifdef HAVE_ASM_GLOBAL_DOT_NAME
140 # define strong_alias(original, alias) \
141 ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME (alias) ASM_LINE_SEP \
142 .set C_SYMBOL_NAME (alias),C_SYMBOL_NAME (original) ASM_LINE_SEP \
143 ASM_GLOBAL_DIRECTIVE C_SYMBOL_DOT_NAME (alias) ASM_LINE_SEP \
144 .set C_SYMBOL_DOT_NAME (alias),C_SYMBOL_DOT_NAME (original)
145 # define strong_data_alias(original, alias) \
146 ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME (alias) ASM_LINE_SEP \
147 .set C_SYMBOL_NAME (alias),C_SYMBOL_NAME (original)
148 # else
149 # define strong_alias(original, alias) \
150 ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME (alias) ASM_LINE_SEP \
151 .set C_SYMBOL_NAME (alias),C_SYMBOL_NAME (original)
152 # define strong_data_alias(original, alias) strong_alias(original, alias)
153 # endif
154 # else
155 # ifdef HAVE_ASM_GLOBAL_DOT_NAME
156 # define strong_alias(original, alias) \
157 ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME (alias) ASM_LINE_SEP \
158 C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original) ASM_LINE_SEP \
159 ASM_GLOBAL_DIRECTIVE C_SYMBOL_DOT_NAME (alias) ASM_LINE_SEP \
160 C_SYMBOL_DOT_NAME (alias) = C_SYMBOL_DOT_NAME (original)
161 # define strong_data_alias(original, alias) \
162 ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME (alias) ASM_LINE_SEP \
163 C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original)
164 # else
165 # define strong_alias(original, alias) \
166 ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME (alias) ASM_LINE_SEP \
167 C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original)
168 # define strong_data_alias(original, alias) strong_alias(original, alias)
169 # endif
170 # endif
172 # ifdef HAVE_WEAK_SYMBOLS
173 # ifdef HAVE_ASM_WEAKEXT_DIRECTIVE
174 # ifdef HAVE_ASM_GLOBAL_DOT_NAME
175 # define weak_alias(original, alias) \
176 .weakext C_SYMBOL_NAME (alias), C_SYMBOL_NAME (original) ASM_LINE_SEP \
177 .weakext C_SYMBOL_DOT_NAME (alias), C_SYMBOL_DOT_NAME (original)
178 # else
179 # define weak_alias(original, alias) \
180 .weakext C_SYMBOL_NAME (alias), C_SYMBOL_NAME (original)
181 # endif
182 # define weak_extern(symbol) \
183 .weakext C_SYMBOL_NAME (symbol)
185 # else /* ! HAVE_ASM_WEAKEXT_DIRECTIVE */
187 # ifdef HAVE_ASM_GLOBAL_DOT_NAME
188 # define weak_alias(original, alias) \
189 .weak C_SYMBOL_NAME (alias) ASM_LINE_SEP \
190 C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original) ASM_LINE_SEP \
191 .weak C_SYMBOL_DOT_NAME (alias) ASM_LINE_SEP \
192 C_SYMBOL_DOT_NAME (alias) = C_SYMBOL_DOT_NAME (original)
193 # else
194 # define weak_alias(original, alias) \
195 .weak C_SYMBOL_NAME (alias) ASM_LINE_SEP \
196 C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original)
197 # endif
199 # define weak_extern(symbol) \
200 .weak C_SYMBOL_NAME (symbol)
202 # endif /* ! HAVE_ASM_WEAKEXT_DIRECTIVE */
204 # else /* ! HAVE_WEAK_SYMBOLS */
206 # define weak_alias(original, alias) strong_alias(original, alias)
207 # define weak_extern(symbol) /* Nothing */
208 # endif /* ! HAVE_WEAK_SYMBOLS */
210 #endif /* __ASSEMBLER__ */
212 /* On some platforms we can make internal function calls (i.e., calls of
213 functions not exported) a bit faster by using a different calling
214 convention. */
215 #ifndef internal_function
216 # define internal_function /* empty */
217 #endif
219 /* Prepare for the case that `__builtin_expect' is not available. */
220 #ifndef HAVE_BUILTIN_EXPECT
221 # define __builtin_expect(expr, val) (expr)
222 #endif
224 /* Determine the return address. */
225 #define RETURN_ADDRESS(nr) \
226 __builtin_extract_return_addr (__builtin_return_address (nr))
228 /* When a reference to SYMBOL is encountered, the linker will emit a
229 warning message MSG. */
230 #ifdef HAVE_ELF
232 /* We want the .gnu.warning.SYMBOL section to be unallocated. */
233 # ifdef HAVE_ASM_PREVIOUS_DIRECTIVE
234 # define __make_section_unallocated(section_string) \
235 asm (".section " section_string "\n\t.previous");
236 # elif defined HAVE_ASM_POPSECTION_DIRECTIVE
237 # define __make_section_unallocated(section_string) \
238 asm (".pushsection " section_string "\n\t.popsection");
239 # else
240 # define __make_section_unallocated(section_string)
241 # endif
243 /* Tacking on "\n\t#" to the section name makes gcc put it's bogus
244 section attributes on what looks like a comment to the assembler. */
245 # ifdef HAVE_SECTION_QUOTES
246 # define __sec_comment "\"\n\t#\""
247 # else
248 # define __sec_comment "\n\t#"
249 # endif
250 # define link_warning(symbol, msg) \
251 __make_section_unallocated (".gnu.warning." #symbol) \
252 static const char __evoke_link_warning_##symbol[] \
253 __attribute__ ((used, section (".gnu.warning." #symbol __sec_comment))) \
254 = msg;
255 # define libc_freeres_ptr(decl) \
256 __make_section_unallocated ("__libc_freeres_ptrs, \"aw\", %nobits") \
257 decl __attribute__ ((section ("__libc_freeres_ptrs" __sec_comment)))
258 # define __libc_freeres_fn_section \
259 __attribute__ ((section ("__libc_freeres_fn")))
260 #else /* Not ELF: a.out */
261 # ifdef HAVE_XCOFF
262 /* XCOFF does not support .stabs.
263 The native aix linker will remove the .stab and .stabstr sections
264 The gnu linker will have a fatal error if there is a relocation for
265 symbol in the .stab section. Silently disable this macro. */
266 # define link_warning(symbol, msg)
267 # else
268 # define link_warning(symbol, msg) \
269 asm (".stabs \"" msg "\",30,0,0,0\n\t" \
270 ".stabs \"" __SYMBOL_PREFIX #symbol "\",1,0,0,0\n");
271 # endif /* XCOFF */
272 # define libc_freeres_ptr(decl) decl
273 # define __libc_freeres_fn_section
274 #endif
275 #define libc_freeres_fn(name) \
276 static void name (void) __attribute_used__ __libc_freeres_fn_section; \
277 text_set_element (__libc_subfreeres, name); \
278 static void name (void)
280 /* A canned warning for sysdeps/stub functions. */
281 #define stub_warning(name) \
282 __make_section_unallocated (".gnu.glibc-stub." #name) \
283 link_warning (name, \
284 "warning: " #name " is not implemented and will always fail")
286 /* Warning for linking functions calling dlopen into static binaries. */
287 #ifdef SHARED
288 #define static_link_warning(name)
289 #else
290 #define static_link_warning(name) static_link_warning1(name)
291 #define static_link_warning1(name) \
292 link_warning(name, "Using '" #name "' in statically linked applications \
293 requires at runtime the shared libraries from the glibc version used \
294 for linking")
295 #endif
297 /* Declare SYMBOL to be TYPE (`function' or `object') of SIZE bytes
298 alias to ORIGINAL, when the assembler supports such declarations
299 (such as in ELF).
300 This is only necessary when defining something in assembly, or playing
301 funny alias games where the size should be other than what the compiler
302 thinks it is. */
303 #define declare_symbol_alias(symbol, original, type, size) \
304 declare_symbol_alias_1 (symbol, original, type, size)
305 #ifdef ASM_TYPE_DIRECTIVE_PREFIX
306 # ifdef __ASSEMBLER__
307 # define declare_symbol_alias_1(symbol, original, type, size) \
308 strong_alias (original, symbol); \
309 .type C_SYMBOL_NAME (symbol), \
310 declare_symbol_alias_1_paste (ASM_TYPE_DIRECTIVE_PREFIX, type); \
311 .size C_SYMBOL_NAME (symbol), size
312 # define declare_symbol_alias_1_paste(a, b) \
313 declare_symbol_alias_1_paste_1 (a,b)
314 # define declare_symbol_alias_1_paste_1(a,b) a##b
315 # else /* Not __ASSEMBLER__. */
316 # define declare_symbol_alias_1(symbol, original, type, size) \
317 asm (declare_symbol_alias_1_stringify (ASM_GLOBAL_DIRECTIVE) \
318 " " __SYMBOL_PREFIX #symbol \
319 "\n\t" declare_symbol_alias_1_alias (symbol, original) \
320 "\n\t.type " __SYMBOL_PREFIX #symbol ", " \
321 declare_symbol_alias_1_stringify (ASM_TYPE_DIRECTIVE_PREFIX) #type \
322 "\n\t.size " __SYMBOL_PREFIX #symbol ", " #size);
323 # define declare_symbol_alias_1_stringify(x) \
324 declare_symbol_alias_1_stringify_1 (x)
325 # define declare_symbol_alias_1_stringify_1(x) #x
326 # ifdef HAVE_ASM_SET_DIRECTIVE
327 # define declare_symbol_alias_1_alias(symbol, original) \
328 ".set " __SYMBOL_PREFIX #symbol ", " __SYMBOL_PREFIX #original
329 # else
330 # define declare_symbol_alias_1_alias(symbol, original) \
331 __SYMBOL_PREFIX #symbol " = " __SYMBOL_PREFIX #original
332 # endif /* HAVE_ASM_SET_DIRECTIVE */
333 # endif /* __ASSEMBLER__ */
334 #else
335 # define declare_symbol_1(symbol, type, size) /* Nothing. */
336 #endif
343 /* Symbol set support macros. */
345 #ifdef HAVE_ELF
347 /* Make SYMBOL, which is in the text segment, an element of SET. */
348 # define text_set_element(set, symbol) _elf_set_element(set, symbol)
349 /* Make SYMBOL, which is in the data segment, an element of SET. */
350 # define data_set_element(set, symbol) _elf_set_element(set, symbol)
351 /* Make SYMBOL, which is in the bss segment, an element of SET. */
352 # define bss_set_element(set, symbol) _elf_set_element(set, symbol)
354 /* These are all done the same way in ELF.
355 There is a new section created for each set. */
356 # ifdef SHARED
357 /* When building a shared library, make the set section writable,
358 because it will need to be relocated at run time anyway. */
359 # define _elf_set_element(set, symbol) \
360 static const void *__elf_set_##set##_element_##symbol##__ \
361 __attribute__ ((used, section (#set))) = &(symbol)
362 # else
363 # define _elf_set_element(set, symbol) \
364 static const void *const __elf_set_##set##_element_##symbol##__ \
365 __attribute__ ((used, section (#set))) = &(symbol)
366 # endif
368 /* Define SET as a symbol set. This may be required (it is in a.out) to
369 be able to use the set's contents. */
370 # define symbol_set_define(set) symbol_set_declare(set)
372 /* Declare SET for use in this module, if defined in another module.
373 In a shared library, this is always local to that shared object.
374 For static linking, the set might be wholly absent and so we use
375 weak references. */
376 # define symbol_set_declare(set) \
377 extern char const __start_##set[] __symbol_set_attribute; \
378 extern char const __stop_##set[] __symbol_set_attribute;
379 # ifdef SHARED
380 # define __symbol_set_attribute attribute_hidden
381 # else
382 # define __symbol_set_attribute __attribute__ ((weak))
383 # endif
385 /* Return a pointer (void *const *) to the first element of SET. */
386 # define symbol_set_first_element(set) ((void *const *) (&__start_##set))
388 /* Return true iff PTR (a void *const *) has been incremented
389 past the last element in SET. */
390 # define symbol_set_end_p(set, ptr) ((ptr) >= (void *const *) &__stop_##set)
392 #else /* Not ELF: a.out. */
394 # ifdef HAVE_XCOFF
395 /* XCOFF does not support .stabs.
396 The native aix linker will remove the .stab and .stabstr sections
397 The gnu linker will have a fatal error if there is a relocation for
398 symbol in the .stab section. Silently disable these macros. */
399 # define text_set_element(set, symbol)
400 # define data_set_element(set, symbol)
401 # define bss_set_element(set, symbol)
402 # else
403 # define text_set_element(set, symbol) \
404 asm (".stabs \"" __SYMBOL_PREFIX #set "\",23,0,0," __SYMBOL_PREFIX #symbol)
405 # define data_set_element(set, symbol) \
406 asm (".stabs \"" __SYMBOL_PREFIX #set "\",25,0,0," __SYMBOL_PREFIX #symbol)
407 # define bss_set_element(set, symbol) ?error Must use initialized data.
408 # endif /* XCOFF */
409 # define symbol_set_define(set) void *const (set)[1];
410 # define symbol_set_declare(set) extern void *const (set)[1];
412 # define symbol_set_first_element(set) &(set)[1]
413 # define symbol_set_end_p(set, ptr) (*(ptr) == 0)
415 #endif /* ELF. */
417 #if DO_VERSIONING
418 # define symbol_version(real, name, version) \
419 _symbol_version(real, name, version)
420 # define default_symbol_version(real, name, version) \
421 _default_symbol_version(real, name, version)
422 # ifdef __ASSEMBLER__
423 # ifdef HAVE_ASM_GLOBAL_DOT_NAME
424 # define _symbol_version(real, name, version) \
425 .symver real, name##@##version ASM_LINE_SEP \
426 .symver C_SYMBOL_DOT_NAME(real), C_SYMBOL_DOT_NAME(name##@##version)
427 # define _default_symbol_version(real, name, version) \
428 .symver real, name##@##@##version ASM_LINE_SEP \
429 .symver C_SYMBOL_DOT_NAME(real), C_SYMBOL_DOT_NAME(name##@##@##version)
430 # else
431 # define _symbol_version(real, name, version) \
432 .symver real, name##@##version
433 # define _default_symbol_version(real, name, version) \
434 .symver real, name##@##@##version
435 # endif
436 # else
437 # ifdef HAVE_ASM_GLOBAL_DOT_NAME
438 # define _symbol_version(real, name, version) \
439 __asm__ (".symver " #real "," #name "@" #version "\n\t" \
440 ".symver ." #real ",." #name "@" #version)
441 # define _default_symbol_version(real, name, version) \
442 __asm__ (".symver " #real "," #name "@@" #version "\n\t" \
443 ".symver ." #real ",." #name "@@" #version)
444 # else
445 # define _symbol_version(real, name, version) \
446 __asm__ (".symver " #real "," #name "@" #version)
447 # define _default_symbol_version(real, name, version) \
448 __asm__ (".symver " #real "," #name "@@" #version)
449 # endif
450 # endif
451 #else
452 # define symbol_version(real, name, version)
453 # define default_symbol_version(real, name, version) \
454 strong_alias(real, name)
455 #endif
457 #if defined SHARED || defined LIBC_NONSHARED
458 # define attribute_hidden __attribute__ ((visibility ("hidden")))
459 #else
460 # define attribute_hidden
461 #endif
463 #ifdef HAVE_TLS_MODEL_ATTRIBUTE
464 # define attribute_tls_model_ie __attribute__ ((tls_model ("initial-exec")))
465 #else
466 # define attribute_tls_model_ie
467 #endif
469 #define attribute_relro __attribute__ ((section (".data.rel.ro")))
471 /* Handling on non-exported internal names. We have to do this only
472 for shared code. */
473 #ifdef SHARED
474 # define INTUSE(name) name##_internal
475 # define INTDEF(name) strong_alias (name, name##_internal)
476 # define INTVARDEF(name) \
477 _INTVARDEF (name, name##_internal)
478 # define _INTVARDEF(name, aliasname) \
479 extern __typeof (name) aliasname __attribute__ ((alias (#name), \
480 visibility ("hidden")));
481 # define INTDEF2(name, newname) strong_alias (name, newname##_internal)
482 # define INTVARDEF2(name, newname) _INTVARDEF (name, newname##_internal)
483 #else
484 # define INTUSE(name) name
485 # define INTDEF(name)
486 # define INTVARDEF(name)
487 # define INTDEF2(name, newname)
488 # define INTVARDEF2(name, newname)
489 #endif
491 /* The following macros are used for PLT bypassing within libc.so
492 (and if needed other libraries similarly).
493 First of all, you need to have the function prototyped somewhere,
494 say in foo/foo.h:
496 int foo (int __bar);
498 If calls to foo within libc.so should always go to foo defined in libc.so,
499 then in include/foo.h you add:
501 libc_hidden_proto (foo)
503 line and after the foo function definition:
505 int foo (int __bar)
507 return __bar;
509 libc_hidden_def (foo)
513 int foo (int __bar)
515 return __bar;
517 libc_hidden_weak (foo)
519 Similarly for global data. If references to foo within libc.so should
520 always go to foo defined in libc.so, then in include/foo.h you add:
522 libc_hidden_proto (foo)
524 line and after foo's definition:
526 int foo = INITIAL_FOO_VALUE;
527 libc_hidden_data_def (foo)
531 int foo = INITIAL_FOO_VALUE;
532 libc_hidden_data_weak (foo)
534 If foo is normally just an alias (strong or weak) to some other function,
535 you should use the normal strong_alias first, then add libc_hidden_def
536 or libc_hidden_weak:
538 int baz (int __bar)
540 return __bar;
542 strong_alias (baz, foo)
543 libc_hidden_weak (foo)
545 If the function should be internal to multiple objects, say ld.so and
546 libc.so, the best way is to use:
548 #if !defined NOT_IN_libc || defined IS_IN_rtld
549 hidden_proto (foo)
550 #endif
552 in include/foo.h and the normal macros at all function definitions
553 depending on what DSO they belong to.
555 If versioned_symbol macro is used to define foo,
556 libc_hidden_ver macro should be used, as in:
558 int __real_foo (int __bar)
560 return __bar;
562 versioned_symbol (libc, __real_foo, foo, GLIBC_2_1);
563 libc_hidden_ver (__real_foo, foo) */
565 #if defined SHARED && defined DO_VERSIONING && !defined NO_HIDDEN
566 # ifndef __ASSEMBLER__
567 # define __hidden_proto_hiddenattr(attrs...) \
568 __attribute__ ((visibility ("hidden"), ##attrs))
569 # define hidden_proto(name, attrs...) \
570 __hidden_proto (name, __GI_##name, ##attrs)
571 # define __hidden_proto(name, internal, attrs...) \
572 extern __typeof (name) name __asm__ (__hidden_asmname (#internal)) \
573 __hidden_proto_hiddenattr (attrs);
574 # define __hidden_asmname(name) \
575 __hidden_asmname1 (__USER_LABEL_PREFIX__, name)
576 # define __hidden_asmname1(prefix, name) __hidden_asmname2(prefix, name)
577 # define __hidden_asmname2(prefix, name) #prefix name
578 # define __hidden_ver1(local, internal, name) \
579 extern __typeof (name) __EI_##name __asm__(__hidden_asmname (#internal)); \
580 extern __typeof (name) __EI_##name \
581 __attribute__((alias (__hidden_asmname (#local))))
582 # define hidden_ver(local, name) __hidden_ver1(local, __GI_##name, name);
583 # define hidden_data_ver(local, name) hidden_ver(local, name)
584 # define hidden_def(name) __hidden_ver1(__GI_##name, name, name);
585 # define hidden_data_def(name) hidden_def(name)
586 # define hidden_weak(name) \
587 __hidden_ver1(__GI_##name, name, name) __attribute__((weak));
588 # define hidden_data_weak(name) hidden_weak(name)
589 # else
590 /* For assembly, we need to do the opposite of what we do in C:
591 in assembly gcc __REDIRECT stuff is not in place, so functions
592 are defined by its normal name and we need to create the
593 __GI_* alias to it, in C __REDIRECT causes the function definition
594 to use __GI_* name and we need to add alias to the real name.
595 There is no reason to use hidden_weak over hidden_def in assembly,
596 but we provide it for consistency with the C usage.
597 hidden_proto doesn't make sense for assembly but the equivalent
598 is to call via the HIDDEN_JUMPTARGET macro instead of JUMPTARGET. */
599 # define hidden_def(name) strong_alias (name, __GI_##name)
600 # define hidden_weak(name) hidden_def (name)
601 # define hidden_ver(local, name) strong_alias (local, __GI_##name)
602 # define hidden_data_def(name) strong_data_alias (name, __GI_##name)
603 # define hidden_data_weak(name) hidden_data_def (name)
604 # define hidden_data_ver(local, name) strong_data_alias (local, __GI_##name)
605 # ifdef HAVE_ASM_GLOBAL_DOT_NAME
606 # define HIDDEN_JUMPTARGET(name) .__GI_##name
607 # else
608 # define HIDDEN_JUMPTARGET(name) __GI_##name
609 # endif
610 # endif
611 #else
612 # ifndef __ASSEMBLER__
613 # define hidden_proto(name, attrs...)
614 # else
615 # define HIDDEN_JUMPTARGET(name) JUMPTARGET(name)
616 # endif /* Not __ASSEMBLER__ */
617 # define hidden_weak(name)
618 # define hidden_def(name)
619 # define hidden_ver(local, name)
620 # define hidden_data_weak(name)
621 # define hidden_data_def(name)
622 # define hidden_data_ver(local, name)
623 #endif
625 #if !defined NOT_IN_libc
626 # define libc_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
627 # define libc_hidden_def(name) hidden_def (name)
628 # define libc_hidden_weak(name) hidden_weak (name)
629 # define libc_hidden_ver(local, name) hidden_ver (local, name)
630 # define libc_hidden_data_def(name) hidden_data_def (name)
631 # define libc_hidden_data_weak(name) hidden_data_weak (name)
632 # define libc_hidden_data_ver(local, name) hidden_data_ver (local, name)
633 #else
634 # define libc_hidden_proto(name, attrs...)
635 # define libc_hidden_def(name)
636 # define libc_hidden_weak(name)
637 # define libc_hidden_ver(local, name)
638 # define libc_hidden_data_def(name)
639 # define libc_hidden_data_weak(name)
640 # define libc_hidden_data_ver(local, name)
641 #endif
643 #if defined NOT_IN_libc && defined IS_IN_rtld
644 # define rtld_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
645 # define rtld_hidden_def(name) hidden_def (name)
646 # define rtld_hidden_weak(name) hidden_weak (name)
647 # define rtld_hidden_ver(local, name) hidden_ver (local, name)
648 # define rtld_hidden_data_def(name) hidden_data_def (name)
649 # define rtld_hidden_data_weak(name) hidden_data_weak (name)
650 # define rtld_hidden_data_ver(local, name) hidden_data_ver (local, name)
651 #else
652 # define rtld_hidden_proto(name, attrs...)
653 # define rtld_hidden_def(name)
654 # define rtld_hidden_weak(name)
655 # define rtld_hidden_ver(local, name)
656 # define rtld_hidden_data_def(name)
657 # define rtld_hidden_data_weak(name)
658 # define rtld_hidden_data_ver(local, name)
659 #endif
661 #if defined NOT_IN_libc && defined IS_IN_libm
662 # define libm_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
663 # define libm_hidden_def(name) hidden_def (name)
664 # define libm_hidden_weak(name) hidden_weak (name)
665 # define libm_hidden_ver(local, name) hidden_ver (local, name)
666 # define libm_hidden_data_def(name) hidden_data_def (name)
667 # define libm_hidden_data_weak(name) hidden_data_weak (name)
668 # define libm_hidden_data_ver(local, name) hidden_data_ver (local, name)
669 #else
670 # define libm_hidden_proto(name, attrs...)
671 # define libm_hidden_def(name)
672 # define libm_hidden_weak(name)
673 # define libm_hidden_ver(local, name)
674 # define libm_hidden_data_def(name)
675 # define libm_hidden_data_weak(name)
676 # define libm_hidden_data_ver(local, name)
677 #endif
679 #if defined NOT_IN_libc && defined IS_IN_libresolv
680 # define libresolv_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
681 # define libresolv_hidden_def(name) hidden_def (name)
682 # define libresolv_hidden_weak(name) hidden_weak (name)
683 # define libresolv_hidden_ver(local, name) hidden_ver (local, name)
684 # define libresolv_hidden_data_def(name) hidden_data_def (name)
685 # define libresolv_hidden_data_weak(name) hidden_data_weak (name)
686 # define libresolv_hidden_data_ver(local, name) hidden_data_ver (local, name)
687 #else
688 # define libresolv_hidden_proto(name, attrs...)
689 # define libresolv_hidden_def(name)
690 # define libresolv_hidden_weak(name)
691 # define libresolv_hidden_ver(local, name)
692 # define libresolv_hidden_data_def(name)
693 # define libresolv_hidden_data_weak(name)
694 # define libresolv_hidden_data_ver(local, name)
695 #endif
697 #if defined NOT_IN_libc && defined IS_IN_librt
698 # define librt_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
699 # define librt_hidden_def(name) hidden_def (name)
700 # define librt_hidden_weak(name) hidden_weak (name)
701 # define librt_hidden_ver(local, name) hidden_ver (local, name)
702 # define librt_hidden_data_def(name) hidden_data_def (name)
703 # define librt_hidden_data_weak(name) hidden_data_weak (name)
704 # define librt_hidden_data_ver(local, name) hidden_data_ver (local, name)
705 #else
706 # define librt_hidden_proto(name, attrs...)
707 # define librt_hidden_def(name)
708 # define librt_hidden_weak(name)
709 # define librt_hidden_ver(local, name)
710 # define librt_hidden_data_def(name)
711 # define librt_hidden_data_weak(name)
712 # define librt_hidden_data_ver(local, name)
713 #endif
715 #if defined NOT_IN_libc && defined IS_IN_libdl
716 # define libdl_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
717 # define libdl_hidden_def(name) hidden_def (name)
718 # define libdl_hidden_weak(name) hidden_weak (name)
719 # define libdl_hidden_ver(local, name) hidden_ver (local, name)
720 # define libdl_hidden_data_def(name) hidden_data_def (name)
721 # define libdl_hidden_data_weak(name) hidden_data_weak (name)
722 # define libdl_hidden_data_ver(local, name) hidden_data_ver (local, name)
723 #else
724 # define libdl_hidden_proto(name, attrs...)
725 # define libdl_hidden_def(name)
726 # define libdl_hidden_weak(name)
727 # define libdl_hidden_ver(local, name)
728 # define libdl_hidden_data_def(name)
729 # define libdl_hidden_data_weak(name)
730 # define libdl_hidden_data_ver(local, name)
731 #endif
733 #if defined NOT_IN_libc && defined IS_IN_libnss_files
734 # define libnss_files_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
735 # define libnss_files_hidden_def(name) hidden_def (name)
736 # define libnss_files_hidden_weak(name) hidden_weak (name)
737 # define libnss_files_hidden_ver(local, name) hidden_ver (local, name)
738 # define libnss_files_hidden_data_def(name) hidden_data_def (name)
739 # define libnss_files_hidden_data_weak(name) hidden_data_weak (name)
740 # define libnss_files_hidden_data_ver(local, name) hidden_data_ver(local, name)
741 #else
742 # define libnss_files_hidden_proto(name, attrs...)
743 # define libnss_files_hidden_def(name)
744 # define libnss_files_hidden_weak(name)
745 # define libnss_files_hidden_ver(local, name)
746 # define libnss_files_hidden_data_def(name)
747 # define libnss_files_hidden_data_weak(name)
748 # define libnss_files_hidden_data_ver(local, name)
749 #endif
751 #if defined NOT_IN_libc && defined IS_IN_libnsl
752 # define libnsl_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
753 # define libnsl_hidden_def(name) hidden_def (name)
754 # define libnsl_hidden_weak(name) hidden_weak (name)
755 # define libnsl_hidden_ver(local, name) hidden_ver (local, name)
756 # define libnsl_hidden_data_def(name) hidden_data_def (name)
757 # define libnsl_hidden_data_weak(name) hidden_data_weak (name)
758 # define libnsl_hidden_data_ver(local, name) hidden_data_ver (local, name)
759 #else
760 # define libnsl_hidden_proto(name, attrs...)
761 # define libnsl_hidden_def(name)
762 # define libnsl_hidden_weak(name)
763 # define libnsl_hidden_ver(local, name)
764 # define libnsl_hidden_data_def(name)
765 # define libnsl_hidden_data_weak(name)
766 # define libnsl_hidden_data_ver(local, name)
767 #endif
769 #if defined NOT_IN_libc && defined IS_IN_libnss_nisplus
770 # define libnss_nisplus_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
771 # define libnss_nisplus_hidden_def(name) hidden_def (name)
772 # define libnss_nisplus_hidden_weak(name) hidden_weak (name)
773 # define libnss_nisplus_hidden_ver(local, name) hidden_ver (local, name)
774 # define libnss_nisplus_hidden_data_def(name) hidden_data_def (name)
775 # define libnss_nisplus_hidden_data_weak(name) hidden_data_weak (name)
776 # define libnss_nisplus_hidden_data_ver(local, name) hidden_data_ver (local, name)
777 #else
778 # define libnss_nisplus_hidden_proto(name, attrs...)
779 # define libnss_nisplus_hidden_def(name)
780 # define libnss_nisplus_hidden_weak(name)
781 # define libnss_nisplus_hidden_ver(local, name)
782 # define libnss_nisplus_hidden_data_def(name)
783 # define libnss_nisplus_hidden_data_weak(name)
784 # define libnss_nisplus_hidden_data_ver(local, name)
785 #endif
787 #ifdef HAVE_BUILTIN_REDIRECTION
788 # define libc_hidden_builtin_proto(name, attrs...) libc_hidden_proto (name, ##attrs)
789 # define libc_hidden_builtin_def(name) libc_hidden_def (name)
790 # define libc_hidden_builtin_weak(name) libc_hidden_weak (name)
791 # define libc_hidden_builtin_ver(local, name) libc_hidden_ver (local, name)
792 # ifdef __ASSEMBLER__
793 # define HIDDEN_BUILTIN_JUMPTARGET(name) HIDDEN_JUMPTARGET(name)
794 # endif
795 #else
796 # define libc_hidden_builtin_proto(name, attrs...)
797 # define libc_hidden_builtin_def(name)
798 # define libc_hidden_builtin_weak(name)
799 # define libc_hidden_builtin_ver(local, name)
800 # ifdef __ASSEMBLER__
801 # define HIDDEN_BUILTIN_JUMPTARGET(name) JUMPTARGET(name)
802 # endif
803 #endif
805 #if defined NOT_IN_libc && defined IS_IN_libutil
806 # define libutil_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
807 # define libutil_hidden_def(name) hidden_def (name)
808 # define libutil_hidden_weak(name) hidden_weak (name)
809 # define libutil_hidden_ver(local, name) hidden_ver (local, name)
810 # define libutil_hidden_data_def(name) hidden_data_def (name)
811 # define libutil_hidden_data_weak(name) hidden_data_weak (name)
812 # define libutil_hidden_data_ver(local, name) hidden_data_ver (local, name)
813 #else
814 # define libutil_hidden_proto(name, attrs...)
815 # define libutil_hidden_def(name)
816 # define libutil_hidden_weak(name)
817 # define libutil_hidden_ver(local, name)
818 # define libutil_hidden_data_def(name)
819 # define libutil_hidden_data_weak(name)
820 # define libutil_hidden_data_ver(local, name)
821 #endif
823 /* Get some dirty hacks. */
824 #include <symbol-hacks.h>
826 /* Move compatibility symbols out of the way by placing them all in a
827 special section. */
828 #ifndef __ASSEMBLER__
829 # define attribute_compat_text_section \
830 __attribute__ ((section (".text.compat")))
831 # define attribute_compat_data_section \
832 __attribute__ ((section (".data.compat")))
833 #else
834 # define compat_text_section .section ".text.compat", "ax";
835 # define compat_data_section .section ".data.compat", "aw";
836 #endif
838 #endif /* libc-symbols.h */