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