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