xref: /haiku/src/system/libroot/posix/glibc/include/libc-symbols.h (revision 8bdd63fe5d3a5048b2a81eb8f545b1c47528e320)
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,2001,2002,2003 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, write to the Free
18    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19    02111-1307 USA.  */
20 
21 #ifndef _LIBC_SYMBOLS_H
22 #define _LIBC_SYMBOLS_H	1
23 
24 /* This file's macros are included implicitly in the compilation of every
25    file in the C library by -imacros.
26 
27    We include config.h which is generated by configure.
28    It should define for us the following symbols:
29 
30    * HAVE_ASM_SET_DIRECTIVE if we have `.set B, A' instead of `A = B'.
31    * ASM_GLOBAL_DIRECTIVE with `.globl' or `.global'.
32    * ASM_TYPE_DIRECTIVE_PREFIX with `@' or `#' or whatever for .type,
33      or leave it undefined if there is no .type directive.
34    * HAVE_GNU_LD if using GNU ld, with support for weak symbols in a.out,
35    and for symbol set and warning messages extensions in a.out and ELF.
36    * HAVE_ELF if using ELF, which supports weak symbols using `.weak'.
37    * HAVE_ASM_WEAK_DIRECTIVE if we have weak symbols using `.weak'.
38    * HAVE_ASM_WEAKEXT_DIRECTIVE if we have weak symbols using `.weakext'.
39 
40    */
41 
42 /* This is defined for the compilation of all C library code.  features.h
43    tests this to avoid inclusion of stubs.h while compiling the library,
44    before stubs.h has been generated.  Some library code that is shared
45    with other packages also tests this symbol to see if it is being
46    compiled as part of the C library.  We must define this before including
47    config.h, because it makes some definitions conditional on whether libc
48    itself is being compiled, or just some generator program.  */
49 #define _LIBC	1
50 
51 /* Enable declarations of GNU extensions, since we are compiling them.  */
52 #define _GNU_SOURCE	1
53 /* And we also need the data for the reentrant functions.  */
54 #define _REENTRANT	1
55 
56 #include <config.h>
57 
58 /* The symbols in all the user (non-_) macros are C symbols.
59    HAVE_GNU_LD without HAVE_ELF implies a.out.  */
60 
61 #if defined HAVE_ASM_WEAK_DIRECTIVE || defined HAVE_ASM_WEAKEXT_DIRECTIVE
62 # define HAVE_WEAK_SYMBOLS
63 #endif
64 
65 #ifndef __SYMBOL_PREFIX
66 #  define __SYMBOL_PREFIX
67 #endif
68 
69 #ifndef C_SYMBOL_NAME
70 #  define C_SYMBOL_NAME(name) name
71 #endif
72 
73 #ifndef ASM_LINE_SEP
74 # define ASM_LINE_SEP ;
75 #endif
76 
77 #ifdef HAVE_ASM_GLOBAL_DOT_NAME
78 # ifndef C_SYMBOL_DOT_NAME
79 #  if defined __GNUC__ && defined __GNUC_MINOR__ \
80       && (__GNUC__ << 16) + __GNUC_MINOR__ >= (3 << 16) + 1
81 #   define C_SYMBOL_DOT_NAME(name) .name
82 #  else
83 #   define C_SYMBOL_DOT_NAME(name) .##name
84 #  endif
85 # endif
86 #endif
87 
88 #ifndef __ASSEMBLER__
89 /* GCC understands weak symbols and aliases; use its interface where
90    possible, instead of embedded assembly language.  */
91 
92 /* Define ALIASNAME as a strong alias for NAME.  */
93 # define strong_alias(name, aliasname) _strong_alias(name, aliasname)
94 # define _strong_alias(name, aliasname) \
95   extern __typeof (name) aliasname __attribute__ ((alias (#name)));
96 
97 /* This comes between the return type and function name in
98    a function definition to make that definition weak.  */
99 # define weak_function __attribute__ ((weak))
100 # define weak_const_function __attribute__ ((weak, __const__))
101 
102 # ifdef HAVE_WEAK_SYMBOLS
103 
104 /* Define ALIASNAME as a weak alias for NAME.
105    If weak aliases are not available, this defines a strong alias.  */
106 #  define weak_alias(name, aliasname) _weak_alias (name, aliasname)
107 #  define _weak_alias(name, aliasname) \
108   extern __typeof (name) aliasname __attribute__ ((weak, alias (#name)));
109 
110 /* Declare SYMBOL as weak undefined symbol (resolved to 0 if not defined).  */
111 #  define weak_extern(symbol) _weak_extern (weak symbol)
112 #  define _weak_extern(expr) _Pragma (#expr)
113 
114 # else
115 
116 #  define weak_alias(name, aliasname) strong_alias(name, aliasname)
117 #  define weak_extern(symbol) /* Nothing. */
118 
119 # endif
120 
121 #else /* __ASSEMBLER__ */
122 
123 # ifdef HAVE_ASM_SET_DIRECTIVE
124 #  ifdef HAVE_ASM_GLOBAL_DOT_NAME
125 #   define strong_alias(original, alias)				\
126   ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME (alias) ASM_LINE_SEP		\
127   .set C_SYMBOL_NAME (alias),C_SYMBOL_NAME (original) ASM_LINE_SEP	\
128   ASM_GLOBAL_DIRECTIVE C_SYMBOL_DOT_NAME (alias) ASM_LINE_SEP		\
129   .set C_SYMBOL_DOT_NAME (alias),C_SYMBOL_DOT_NAME (original)
130 #   define strong_data_alias(original, alias)				\
131   ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME (alias) ASM_LINE_SEP		\
132   .set C_SYMBOL_NAME (alias),C_SYMBOL_NAME (original)
133 #  else
134 #   define strong_alias(original, alias)				\
135   ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME (alias) ASM_LINE_SEP		\
136   .set C_SYMBOL_NAME (alias),C_SYMBOL_NAME (original)
137 #   define strong_data_alias(original, alias) strong_alias(original, alias)
138 #  endif
139 # else
140 #  ifdef HAVE_ASM_GLOBAL_DOT_NAME
141 #   define strong_alias(original, alias)				\
142   ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME (alias) ASM_LINE_SEP		\
143   C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original) ASM_LINE_SEP		\
144   ASM_GLOBAL_DIRECTIVE C_SYMBOL_DOT_NAME (alias) ASM_LINE_SEP		\
145   C_SYMBOL_DOT_NAME (alias) = C_SYMBOL_DOT_NAME (original)
146 #   define strong_data_alias(original, alias)				\
147   ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME (alias) ASM_LINE_SEP		\
148   C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original)
149 #  else
150 #   define strong_alias(original, alias)				\
151   ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME (alias) ASM_LINE_SEP		\
152   C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original)
153 #   define strong_data_alias(original, alias) strong_alias(original, alias)
154 #  endif
155 # endif
156 
157 # ifdef HAVE_WEAK_SYMBOLS
158 #  ifdef HAVE_ASM_WEAKEXT_DIRECTIVE
159 #   ifdef HAVE_ASM_GLOBAL_DOT_NAME
160 #    define weak_alias(original, alias)					\
161   .weakext C_SYMBOL_NAME (alias), C_SYMBOL_NAME (original) ASM_LINE_SEP \
162   .weakext C_SYMBOL_DOT_NAME (alias), C_SYMBOL_DOT_NAME (original)
163 #   else
164 #    define weak_alias(original, alias)					\
165   .weakext C_SYMBOL_NAME (alias), C_SYMBOL_NAME (original)
166 #   endif
167 #   define weak_extern(symbol)						\
168   .weakext C_SYMBOL_NAME (symbol)
169 
170 #  else /* ! HAVE_ASM_WEAKEXT_DIRECTIVE */
171 
172 #   ifdef HAVE_ASM_GLOBAL_DOT_NAME
173 #    define weak_alias(original, alias)					\
174   .weak C_SYMBOL_NAME (alias) ASM_LINE_SEP				\
175   C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original) ASM_LINE_SEP		\
176   .weak C_SYMBOL_DOT_NAME (alias) ASM_LINE_SEP				\
177   C_SYMBOL_DOT_NAME (alias) = C_SYMBOL_DOT_NAME (original)
178 #   else
179 #    define weak_alias(original, alias)					\
180   .weak C_SYMBOL_NAME (alias) ASM_LINE_SEP				\
181   C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original)
182 #   endif
183 
184 #   define weak_extern(symbol)						\
185   .weak C_SYMBOL_NAME (symbol)
186 
187 #  endif /* ! HAVE_ASM_WEAKEXT_DIRECTIVE */
188 
189 # else /* ! HAVE_WEAK_SYMBOLS */
190 
191 #  define weak_alias(original, alias) strong_alias(original, alias)
192 #  define weak_extern(symbol) /* Nothing */
193 # endif /* ! HAVE_WEAK_SYMBOLS */
194 
195 #endif /* __ASSEMBLER__ */
196 
197 /* On some platforms we can make internal function calls (i.e., calls of
198    functions not exported) a bit faster by using a different calling
199    convention.  */
200 #ifndef internal_function
201 # define internal_function	/* empty */
202 #endif
203 
204 /* Prepare for the case that `__builtin_expect' is not available.  */
205 #ifndef HAVE_BUILTIN_EXPECT
206 # define __builtin_expect(expr, val) (expr)
207 #endif
208 
209 /* Determine the return address.  */
210 #define RETURN_ADDRESS(nr) \
211   __builtin_extract_return_addr (__builtin_return_address (nr))
212 
213 /* When a reference to SYMBOL is encountered, the linker will emit a
214    warning message MSG.  */
215 #ifdef HAVE_GNU_LD
216 # ifdef HAVE_ELF
217 
218 /* We want the .gnu.warning.SYMBOL section to be unallocated.  */
219 #  ifdef HAVE_ASM_PREVIOUS_DIRECTIVE
220 #   define __make_section_unallocated(section_string)	\
221   asm (".section " section_string "\n\t.previous");
222 #  elif defined HAVE_ASM_POPSECTION_DIRECTIVE
223 #   define __make_section_unallocated(section_string)	\
224   asm (".pushsection " section_string "\n\t.popsection");
225 #  else
226 #   define __make_section_unallocated(section_string)
227 #  endif
228 
229 /* Tacking on "\n\t#" to the section name makes gcc put it's bogus
230    section attributes on what looks like a comment to the assembler.  */
231 #  ifdef HAVE_SECTION_QUOTES
232 #   define __sec_comment "\"\n\t#\""
233 #  else
234 #   define __sec_comment "\n\t#"
235 #  endif
236 #  define link_warning(symbol, msg) \
237   __make_section_unallocated (".gnu.warning." #symbol) \
238   static const char __evoke_link_warning_##symbol[]	\
239     __attribute__ ((unused, section (".gnu.warning." #symbol __sec_comment))) \
240     = msg;
241 #  define libc_freeres_ptr(decl) \
242   __make_section_unallocated ("__libc_freeres_ptrs, \"aw\", %nobits") \
243   decl __attribute__ ((section ("__libc_freeres_ptrs" __sec_comment)))
244 #  define __libc_freeres_fn_section \
245   __attribute__ ((section ("__libc_freeres_fn")))
246 # else /* Not ELF: a.out */
247 #  ifdef HAVE_XCOFF
248 /* XCOFF does not support .stabs.
249    The native aix linker will remove the .stab and .stabstr sections
250    The gnu linker will have a fatal error if there is a relocation for
251    symbol in the .stab section.  Silently disable this macro.  */
252 #   define link_warning(symbol, msg)
253 #  else
254 #   define link_warning(symbol, msg)		\
255      asm (".stabs \"" msg "\",30,0,0,0\n\t"	\
256           ".stabs \"" __SYMBOL_PREFIX #symbol "\",1,0,0,0\n");
257 #  endif /* XCOFF */
258 #  define libc_freeres_ptr(decl) decl
259 #  define __libc_freeres_fn_section
260 # endif
261 #else
262 /* We will never be heard; they will all die horribly.  */
263 # define link_warning(symbol, msg)
264 # define libc_freeres_ptr(decl) decl
265 # define __libc_freeres_fn_section
266 #endif
267 #define libc_freeres_fn(name)	\
268   static void name (void) __attribute_used__ __libc_freeres_fn_section;	\
269   text_set_element (__libc_subfreeres, name);				\
270   static void name (void)
271 
272 /* A canned warning for sysdeps/stub functions.  */
273 #define	stub_warning(name) \
274   link_warning (name, \
275 		"warning: " #name " is not implemented and will always fail")
276 
277 
278 /* Declare SYMBOL to be TYPE (`function' or `object') and of SIZE bytes,
279    when the assembler supports such declarations (such as in ELF).
280    This is only necessary when defining something in assembly, or playing
281    funny alias games where the size should be other than what the compiler
282    thinks it is.  */
283 #define declare_symbol(symbol, type, size) \
284   declare_symbol_1 (symbol, type, size)
285 #ifdef ASM_TYPE_DIRECTIVE_PREFIX
286 # ifdef __ASSEMBLER__
287 #  define declare_symbol_1(symbol, type, size) \
288     .type C_SYMBOL_NAME (symbol), \
289 	  declare_symbol_1_paste (ASM_TYPE_DIRECTIVE_PREFIX, type), size
290 #  define declare_symbol_1_paste(a, b)	declare_symbol_1_paste_1 (a,b)
291 #  define declare_symbol_1_paste_1(a,b)	a##b
292 # else /* Not __ASSEMBLER__.  */
293 #  define declare_symbol_1(symbol, type, size) \
294     asm (".type " __SYMBOL_PREFIX #symbol ", " \
295 	 declare_symbol_1_stringify (ASM_TYPE_DIRECTIVE_PREFIX) #type \
296 	 "\n\t.size " __SYMBOL_PREFIX #symbol ", " #size);
297 #  define declare_symbol_1_stringify(x) declare_symbol_1_stringify_1 (x)
298 #  define declare_symbol_1_stringify_1(x) #x
299 # endif /* __ASSEMBLER__ */
300 #else
301 # define declare_symbol_1(symbol, type, size) /* Nothing.  */
302 #endif
303 
304 
305 /*
306 
307 */
308 
309 #ifdef HAVE_GNU_LD
310 
311 /* Symbol set support macros.  */
312 
313 # ifdef HAVE_ELF
314 
315 /* Make SYMBOL, which is in the text segment, an element of SET.  */
316 #  define text_set_element(set, symbol)	_elf_set_element(set, symbol)
317 /* Make SYMBOL, which is in the data segment, an element of SET.  */
318 #  define data_set_element(set, symbol)	_elf_set_element(set, symbol)
319 /* Make SYMBOL, which is in the bss segment, an element of SET.  */
320 #  define bss_set_element(set, symbol)	_elf_set_element(set, symbol)
321 
322 /* These are all done the same way in ELF.
323    There is a new section created for each set.  */
324 #  ifdef SHARED
325 /* When building a shared library, make the set section writable,
326    because it will need to be relocated at run time anyway.  */
327 #   define _elf_set_element(set, symbol) \
328   static const void *__elf_set_##set##_element_##symbol##__ \
329     __attribute__ ((unused, section (#set))) = &(symbol)
330 #  else
331 #   define _elf_set_element(set, symbol) \
332   static const void *const __elf_set_##set##_element_##symbol##__ \
333     __attribute__ ((unused, section (#set))) = &(symbol)
334 #  endif
335 
336 /* Define SET as a symbol set.  This may be required (it is in a.out) to
337    be able to use the set's contents.  */
338 #  define symbol_set_define(set)	symbol_set_declare(set)
339 
340 /* Declare SET for use in this module, if defined in another module.  */
341 #  define symbol_set_declare(set) \
342   extern void *const __start_##set __attribute__ ((__weak__));		\
343   extern void *const __stop_##set __attribute__ ((__weak__));		\
344   weak_extern (__start_##set) weak_extern (__stop_##set)
345 
346 /* Return a pointer (void *const *) to the first element of SET.  */
347 #  define symbol_set_first_element(set)	(&__start_##set)
348 
349 /* Return true iff PTR (a void *const *) has been incremented
350    past the last element in SET.  */
351 #  define symbol_set_end_p(set, ptr)	((ptr) >= &__stop_##set)
352 
353 # else	/* Not ELF: a.out.  */
354 
355 #  ifdef HAVE_XCOFF
356 /* XCOFF does not support .stabs.
357    The native aix linker will remove the .stab and .stabstr sections
358    The gnu linker will have a fatal error if there is a relocation for
359    symbol in the .stab section.  Silently disable these macros.  */
360 #   define text_set_element(set, symbol)
361 #   define data_set_element(set, symbol)
362 #   define bss_set_element(set, symbol)
363 #  else
364 #   define text_set_element(set, symbol)	\
365     asm (".stabs \"" __SYMBOL_PREFIX #set "\",23,0,0," __SYMBOL_PREFIX #symbol)
366 #   define data_set_element(set, symbol)	\
367     asm (".stabs \"" __SYMBOL_PREFIX #set "\",25,0,0," __SYMBOL_PREFIX #symbol)
368 #   define bss_set_element(set, symbol)	?error Must use initialized data.
369 #  endif /* XCOFF */
370 #  define symbol_set_define(set)	void *const (set)[1];
371 #  define symbol_set_declare(set)	extern void *const (set)[1];
372 
373 #  define symbol_set_first_element(set)	&(set)[1]
374 #  define symbol_set_end_p(set, ptr)	(*(ptr) == 0)
375 
376 # endif	/* ELF.  */
377 #else
378 /* We cannot do anything in generial.  */
379 # define text_set_element(set, symbol) asm ("")
380 # define data_set_element(set, symbol) asm ("")
381 # define bss_set_element(set, symbol) asm ("")
382 # define symbol_set_define(set)		void *const (set)[1];
383 # define symbol_set_declare(set)	extern void *const (set)[1];
384 
385 # define symbol_set_first_element(set)	&(set)[1]
386 # define symbol_set_end_p(set, ptr)	(*(ptr) == 0)
387 #endif	/* Have GNU ld.  */
388 
389 #if DO_VERSIONING
390 # define symbol_version(real, name, version) \
391      _symbol_version(real, name, version)
392 # define default_symbol_version(real, name, version) \
393      _default_symbol_version(real, name, version)
394 # ifdef __ASSEMBLER__
395 #  ifdef HAVE_ASM_GLOBAL_DOT_NAME
396 #   define _symbol_version(real, name, version) \
397      .symver real, name##@##version ASM_LINE_SEP			\
398      .symver .##real, .##name##@##version
399 #   define _default_symbol_version(real, name, version) \
400      .symver real, name##@##@##version ASM_LINE_SEP			\
401      .symver .##real, .##name##@##@##version
402 #  else
403 #   define _symbol_version(real, name, version) \
404      .symver real, name##@##version
405 #   define _default_symbol_version(real, name, version) \
406      .symver real, name##@##@##version
407 #  endif
408 # else
409 #  ifdef HAVE_ASM_GLOBAL_DOT_NAME
410 #   define _symbol_version(real, name, version) \
411      __asm__ (".symver " #real "," #name "@" #version "\n\t"	\
412 	      ".symver ." #real ",." #name "@" #version)
413 #   define _default_symbol_version(real, name, version) \
414      __asm__ (".symver " #real "," #name "@@" #version "\n\t"	\
415 	      ".symver ." #real ",." #name "@@" #version)
416 #  else
417 #   define _symbol_version(real, name, version) \
418      __asm__ (".symver " #real "," #name "@" #version)
419 #   define _default_symbol_version(real, name, version) \
420      __asm__ (".symver " #real "," #name "@@" #version)
421 #  endif
422 # endif
423 #else
424 # define symbol_version(real, name, version)
425 # define default_symbol_version(real, name, version) \
426   strong_alias(real, name)
427 #endif
428 
429 #if defined HAVE_VISIBILITY_ATTRIBUTE && defined SHARED
430 # define attribute_hidden __attribute__ ((visibility ("hidden")))
431 #else
432 # define attribute_hidden
433 #endif
434 
435 #if defined HAVE_TLS_MODEL_ATTRIBUTE
436 # define attribute_tls_model_ie __attribute__ ((tls_model ("initial-exec")))
437 #else
438 # define attribute_tls_model_ie
439 #endif
440 
441 /* Handling on non-exported internal names.  We have to do this only
442    for shared code.  */
443 #ifdef SHARED
444 # define INTUSE(name) name##_internal
445 # define INTDEF(name) strong_alias (name, name##_internal)
446 # define INTVARDEF(name) \
447   _INTVARDEF (name, name##_internal)
448 # if defined HAVE_VISIBILITY_ATTRIBUTE
449 #  define _INTVARDEF(name, aliasname) \
450   extern __typeof (name) aliasname __attribute__ ((alias (#name), \
451 						   visibility ("hidden")));
452 # else
453 #  define _INTVARDEF(name, aliasname) \
454   extern __typeof (name) aliasname __attribute__ ((alias (#name)));
455 # endif
456 # define INTDEF2(name, newname) strong_alias (name, newname##_internal)
457 # define INTVARDEF2(name, newname) _INTVARDEF (name, newname##_internal)
458 #else
459 # define INTUSE(name) name
460 # define INTDEF(name)
461 # define INTVARDEF(name)
462 # define INTDEF2(name, newname)
463 # define INTVARDEF2(name, newname)
464 #endif
465 
466 /* The following macros are used for PLT bypassing within libc.so
467    (and if needed other libraries similarly).
468    First of all, you need to have the function prototyped somewhere,
469    say in foo/foo.h:
470 
471    int foo (int __bar);
472 
473    If calls to foo within libc.so should always go to foo defined in libc.so,
474    then in include/foo.h you add:
475 
476    libc_hidden_proto (foo)
477 
478    line and after the foo function definition:
479 
480    int foo (int __bar)
481    {
482      return __bar;
483    }
484    libc_hidden_def (foo)
485 
486    or
487 
488    int foo (int __bar)
489    {
490      return __bar;
491    }
492    libc_hidden_weak (foo)
493 
494    Simularly for global data. If references to foo within libc.so should
495    always go to foo defined in libc.so, then in include/foo.h you add:
496 
497    libc_hidden_proto (foo)
498 
499    line and after foo's definition:
500 
501    int foo = INITIAL_FOO_VALUE;
502    libc_hidden_data_def (foo)
503 
504    or
505 
506    int foo = INITIAL_FOO_VALUE;
507    libc_hidden_data_weak (foo)
508 
509    If foo is normally just an alias (strong or weak) of some other function,
510    you should use the normal strong_alias first, then add libc_hidden_def
511    or libc_hidden_weak:
512 
513    int baz (int __bar)
514    {
515      return __bar;
516    }
517    strong_alias (baz, foo)
518    libc_hidden_weak (foo)
519 
520    If the function should be internal to multiple objects, say ld.so and
521    libc.so, the best way is to use:
522 
523    #if !defined NOT_IN_libc || defined IS_IN_rtld
524    hidden_proto (foo)
525    #endif
526 
527    in include/foo.h and the normal macros at all function definitions
528    depending on what DSO they belong to.
529 
530    If versioned_symbol macro is used to define foo,
531    libc_hidden_ver macro should be used, as in:
532 
533    int __real_foo (int __bar)
534    {
535      return __bar;
536    }
537    versioned_symbol (libc, __real_foo, foo, GLIBC_2_1);
538    libc_hidden_ver (__real_foo, foo)  */
539 
540 #if defined SHARED && defined DO_VERSIONING \
541     && !defined HAVE_BROKEN_ALIAS_ATTRIBUTE && !defined NO_HIDDEN
542 # ifndef __ASSEMBLER__
543 #  if !defined HAVE_VISIBILITY_ATTRIBUTE \
544       || defined HAVE_BROKEN_VISIBILITY_ATTRIBUTE
545 #   define __hidden_proto_hiddenattr(attrs...)
546 #  else
547 #   define __hidden_proto_hiddenattr(attrs...) \
548   __attribute__ ((visibility ("hidden"), ##attrs))
549 #  endif
550 #  define hidden_proto(name, attrs...) \
551   __hidden_proto (name, __GI_##name, ##attrs)
552 #  define __hidden_proto(name, internal, attrs...) \
553   extern __typeof (name) internal; \
554   extern __typeof (name) name __asm__ (__hidden_asmname (#internal)) \
555   __hidden_proto_hiddenattr (attrs);
556 #  define __hidden_asmname(name) \
557   __hidden_asmname1 (__USER_LABEL_PREFIX__, name)
558 #  define __hidden_asmname1(prefix, name) __hidden_asmname2(prefix, name)
559 #  define __hidden_asmname2(prefix, name) #prefix name
560 #  ifdef HAVE_ASM_SET_DIRECTIVE
561 #   define __hidden_def1(original, alias)			\
562   ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME (alias) ASM_LINE_SEP	\
563   .set C_SYMBOL_NAME (alias), C_SYMBOL_NAME (original)
564 #   ifdef HAVE_ASM_GLOBAL_DOT_NAME
565 #     define __hidden_dot_def1(original, alias)	 ASM_LINE_SEP	\
566   ASM_GLOBAL_DIRECTIVE C_SYMBOL_DOT_NAME (alias) ASM_LINE_SEP	\
567   .set C_SYMBOL_DOT_NAME (alias), C_SYMBOL_DOT_NAME (original)
568 #   else
569 #     define __hidden_dot_def1(original, alias)
570 #   endif
571 #  else
572 #   define __hidden_def1(original, alias)			\
573   ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME (alias) ASM_LINE_SEP	\
574   C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original)
575 #   ifdef HAVE_ASM_GLOBAL_DOT_NAME
576 #    define __hidden_dot_def1(original, alias)	ASM_LINE_SEP	\
577   ASM_GLOBAL_DIRECTIVE C_SYMBOL_DOT_NAME (alias) ASM_LINE_SEP	\
578   C_SYMBOL_DOT_NAME (alias) = C_SYMBOL_DOT_NAME (original)
579 #   else
580 #    define __hidden_dot_def1(original, alias)
581 #   endif
582 #  endif
583 #  define __hidden_def2(...) #__VA_ARGS__
584 #  define __hidden_def3(...) __hidden_def2 (__VA_ARGS__)
585 #  define hidden_def(name)					\
586   __asm__ (__hidden_def3 (__hidden_def1 (__GI_##name, name) \
587   __hidden_dot_def1 (__GI_##name, name)));
588 #  define hidden_data_def(name)					\
589   __asm__ (__hidden_def3 (__hidden_def1 (__GI_##name, name)));
590 #  define hidden_ver(local, name)				\
591   __asm__ (__hidden_def3 (__hidden_def1 (local, __GI_##name) \
592   __hidden_dot_def1 (local, __GI_##name)));
593 #  define hidden_data_ver(local, name)				\
594   __asm__ (__hidden_def3 (__hidden_def1 (local, __GI_##name)));
595 #  ifdef HAVE_WEAK_SYMBOLS
596 #   ifdef HAVE_ASM_WEAKEXT_DIRECTIVE
597 #    define __hidden_weak1(original, alias)			\
598   .weakext C_SYMBOL_NAME (alias), C_SYMBOL_NAME (original)
599 #    ifdef HAVE_ASM_GLOBAL_DOT_NAME
600 #     define __hidden_dot_weak1(original, alias)	ASM_LINE_SEP	\
601   .weakext C_SYMBOL_DOT_NAME (alias), C_SYMBOL_DOT_NAME (original)
602 #    else
603 #     define __hidden_dot_weak1(original, alias)
604 #    endif
605 #   else /* ! HAVE_ASM_WEAKEXT_DIRECTIVE */
606 #    define __hidden_weak1(original, alias)			\
607   .weak C_SYMBOL_NAME (alias) ASM_LINE_SEP			\
608   C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original)
609 #    ifdef HAVE_ASM_GLOBAL_DOT_NAME
610 #     define __hidden_dot_weak1(original, alias)	ASM_LINE_SEP	\
611   .weak C_SYMBOL_DOT_NAME (alias) ASM_LINE_SEP	\
612   C_SYMBOL_DOT_NAME (alias) = C_SYMBOL_DOT_NAME (original)
613 #    else
614 #     define __hidden_dot_weak1(original, alias)
615 #    endif
616 #   endif
617 #   define hidden_weak(name)					\
618   __asm__ (__hidden_def3 (__hidden_weak1 (__GI_##name, name) \
619   __hidden_dot_weak1 (__GI_##name, name)));
620 #   define hidden_data_weak(name)					\
621   __asm__ (__hidden_def3 (__hidden_weak1 (__GI_##name, name)));
622 #  else
623 #   define hidden_weak(name) hidden_def (name)
624 #  endif
625 # else
626 /* For assembly, we need to do the opposite of what we do in C:
627    in assembly gcc __REDIRECT stuff is not in place, so functions
628    are defined by its normal name and we need to create the
629    __GI_* alias to it, in C __REDIRECT causes the function definition
630    to use __GI_* name and we need to add alias to the real name.
631    There is no reason to use hidden_weak over hidden_def in assembly,
632    but we provide it for consistency with the C usage.
633    hidden_proto doesn't make sense for assembly but the equivalent
634    is to call via the HIDDEN_JUMPTARGET macro instead of JUMPTARGET.  */
635 #  define hidden_def(name)	strong_alias (name, __GI_##name)
636 #  define hidden_weak(name)	hidden_def (name)
637 #  define hidden_ver(local, name) strong_alias (local, __GI_##name)
638 #  define hidden_data_def(name)	strong_data_alias (name, __GI_##name)
639 #  define hidden_data_weak(name)	hidden_data_def (name)
640 #  define hidden_data_ver(local, name) strong_data_alias (local, __GI_##name)
641 #  ifdef HAVE_ASM_GLOBAL_DOT_NAME
642 #   define HIDDEN_JUMPTARGET(name) .__GI_##name
643 #  else
644 #   define HIDDEN_JUMPTARGET(name) __GI_##name
645 #  endif
646 # endif
647 #else
648 # ifndef __ASSEMBLER__
649 #  define hidden_proto(name, attrs...)
650 # else
651 #  define HIDDEN_JUMPTARGET(name) JUMPTARGET(name)
652 # endif /* Not  __ASSEMBLER__ */
653 # define hidden_weak(name)
654 # define hidden_def(name)
655 # define hidden_ver(local, name)
656 # define hidden_data_weak(name)
657 # define hidden_data_def(name)
658 # define hidden_data_ver(local, name)
659 #endif
660 
661 #if !defined NOT_IN_libc
662 # define libc_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
663 # define libc_hidden_def(name) hidden_def (name)
664 # define libc_hidden_weak(name) hidden_weak (name)
665 # define libc_hidden_ver(local, name) hidden_ver (local, name)
666 # define libc_hidden_data_def(name) hidden_data_def (name)
667 # define libc_hidden_data_weak(name) hidden_data_weak (name)
668 # define libc_hidden_data_ver(local, name) hidden_data_ver (local, name)
669 #else
670 # define libc_hidden_proto(name, attrs...)
671 # define libc_hidden_def(name)
672 # define libc_hidden_weak(name)
673 # define libc_hidden_ver(local, name)
674 # define libc_hidden_data_def(name)
675 # define libc_hidden_data_weak(name)
676 # define libc_hidden_data_ver(local, name)
677 #endif
678 
679 #if defined NOT_IN_libc && defined IS_IN_rtld
680 # define rtld_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
681 # define rtld_hidden_def(name) hidden_def (name)
682 # define rtld_hidden_weak(name) hidden_weak (name)
683 # define rtld_hidden_ver(local, name) hidden_ver (local, name)
684 # define rtld_hidden_data_def(name) hidden_data_def (name)
685 # define rtld_hidden_data_weak(name) hidden_data_weak (name)
686 # define rtld_hidden_data_ver(local, name) hidden_data_ver (local, name)
687 #else
688 # define rtld_hidden_proto(name, attrs...)
689 # define rtld_hidden_def(name)
690 # define rtld_hidden_weak(name)
691 # define rtld_hidden_ver(local, name)
692 # define rtld_hidden_data_def(name)
693 # define rtld_hidden_data_weak(name)
694 # define rtld_hidden_data_ver(local, name)
695 #endif
696 
697 #if defined NOT_IN_libc && defined IS_IN_libm
698 # define libm_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
699 # define libm_hidden_def(name) hidden_def (name)
700 # define libm_hidden_weak(name) hidden_weak (name)
701 # define libm_hidden_ver(local, name) hidden_ver (local, name)
702 # define libm_hidden_data_def(name) hidden_data_def (name)
703 # define libm_hidden_data_weak(name) hidden_data_weak (name)
704 # define libm_hidden_data_ver(local, name) hidden_data_ver (local, name)
705 #else
706 # define libm_hidden_proto(name, attrs...)
707 # define libm_hidden_def(name)
708 # define libm_hidden_weak(name)
709 # define libm_hidden_ver(local, name)
710 # define libm_hidden_data_def(name)
711 # define libm_hidden_data_weak(name)
712 # define libm_hidden_data_ver(local, name)
713 #endif
714 
715 #endif /* libc-symbols.h */
716