]> git.ipfire.org Git - thirdparty/glibc.git/blob - include/libc-symbols.h
Update.
[thirdparty/glibc.git] / include / libc-symbols.h
1 /* Support macros for making weak and strong aliases for symbols,
2 and for using symbol sets and linker warnings with GNU ld.
3 Copyright (C) 1995, 1996, 1997, 1998, 2000 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 Library General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 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 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public
17 License along with the GNU C Library; see the file COPYING.LIB. If not,
18 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 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 * HAVE_GNU_LD if using GNU ld, with support for weak symbols in a.out,
33 and for symbol set and warning messages extensions in a.out and ELF.
34 * HAVE_ELF if using ELF, which supports weak symbols using `.weak'.
35 * HAVE_ASM_WEAK_DIRECTIVE if we have weak symbols using `.weak'.
36 * HAVE_ASM_WEAKEXT_DIRECTIVE if we have weak symbols using `.weakext'.
37
38 */
39
40 /* This is defined for the compilation of all C library code. features.h
41 tests this to avoid inclusion of stubs.h while compiling the library,
42 before stubs.h has been generated. Some library code that is shared
43 with other packages also tests this symbol to see if it is being
44 compiled as part of the C library. We must define this before including
45 config.h, because it makes some definitions conditional on whether libc
46 itself is being compiled, or just some generator program. */
47 #define _LIBC 1
48
49 /* Enable declarations of GNU extensions, since we are compiling them. */
50 #define _GNU_SOURCE 1
51 /* And we also need the data for the reentrant functions. */
52 #define _REENTRANT 1
53
54 #include <config.h>
55
56 /* The symbols in all the user (non-_) macros are C symbols.
57 HAVE_GNU_LD without HAVE_ELF implies a.out. */
58
59 #if defined HAVE_ASM_WEAK_DIRECTIVE || defined HAVE_ASM_WEAKEXT_DIRECTIVE
60 # define HAVE_WEAK_SYMBOLS
61 #endif
62
63 #ifndef __SYMBOL_PREFIX
64 # ifdef NO_UNDERSCORES
65 # define __SYMBOL_PREFIX
66 # else
67 # define __SYMBOL_PREFIX "_"
68 # endif
69 #endif
70
71 #ifndef C_SYMBOL_NAME
72 # ifdef NO_UNDERSCORES
73 # define C_SYMBOL_NAME(name) name
74 # else
75 # define C_SYMBOL_NAME(name) _##name
76 # endif
77 #endif
78
79 #ifndef ASM_LINE_SEP
80 # define ASM_LINE_SEP ;
81 #endif
82
83 #ifndef __ASSEMBLER__
84 /* GCC understands weak symbols and aliases; use its interface where
85 possible, instead of embedded assembly language. */
86
87 /* Define ALIASNAME as a strong alias for NAME. */
88 # define strong_alias(name, aliasname) _strong_alias(name, aliasname)
89 # define _strong_alias(name, aliasname) \
90 extern __typeof (name) aliasname __attribute__ ((alias (#name)));
91
92 /* This comes between the return type and function name in
93 a function definition to make that definition weak. */
94 # define weak_function __attribute__ ((weak))
95 # define weak_const_function __attribute__ ((weak, __const__))
96
97 # ifdef HAVE_WEAK_SYMBOLS
98
99 /* Define ALIASNAME as a weak alias for NAME.
100 If weak aliases are not available, this defines a strong alias. */
101 # define weak_alias(name, aliasname) _weak_alias (name, aliasname)
102 # define _weak_alias(name, aliasname) \
103 extern __typeof (name) aliasname __attribute__ ((weak, alias (#name)));
104
105 /* Declare SYMBOL as weak undefined symbol (resolved to 0 if not defined). */
106 # define weak_extern(symbol) _weak_extern (symbol)
107 # ifdef HAVE_ASM_WEAKEXT_DIRECTIVE
108 # define _weak_extern(symbol) asm (".weakext " __SYMBOL_PREFIX #symbol);
109 # else
110 # define _weak_extern(symbol) asm (".weak " __SYMBOL_PREFIX #symbol);
111 # endif
112
113 # else
114
115 # define weak_alias(name, aliasname) strong_alias(name, aliasname)
116 # define weak_extern(symbol) /* Nothing. */
117
118 # endif
119
120 #else /* __ASSEMBLER__ */
121
122 # ifdef HAVE_ASM_SET_DIRECTIVE
123 # define strong_alias(original, alias) \
124 ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME (alias) ASM_LINE_SEP \
125 .set C_SYMBOL_NAME (alias),C_SYMBOL_NAME (original)
126 # else
127 # ifdef HAVE_ASM_GLOBAL_DOT_NAME
128 # define strong_alias(original, alias) \
129 ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME (alias) ASM_LINE_SEP \
130 C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original) ASM_LINE_SEP \
131 ASM_GLOBAL_DIRECTIVE C_SYMBOL_DOT_NAME (alias) ASM_LINE_SEP \
132 C_SYMBOL_DOT_NAME (alias) = C_SYMBOL_DOT_NAME (original)
133 # else
134 # define strong_alias(original, alias) \
135 ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME (alias) ASM_LINE_SEP \
136 C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original)
137 # endif
138 # endif
139
140 # ifdef HAVE_WEAK_SYMBOLS
141 # ifdef HAVE_ASM_WEAKEXT_DIRECTIVE
142 # define weak_alias(original, alias) \
143 .weakext C_SYMBOL_NAME (alias), C_SYMBOL_NAME (original)
144 # define weak_extern(symbol) \
145 .weakext C_SYMBOL_NAME (symbol)
146
147 # else /* ! HAVE_ASM_WEAKEXT_DIRECTIVE */
148
149 # ifdef HAVE_ASM_GLOBAL_DOT_NAME
150 # define weak_alias(original, alias) \
151 .weak C_SYMBOL_NAME (alias) ASM_LINE_SEP \
152 C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original) ASM_LINE_SEP \
153 .weak C_SYMBOL_DOT_NAME (alias) ASM_LINE_SEP \
154 C_SYMBOL_DOT_NAME (alias) = C_SYMBOL_DOT_NAME (original)
155 # else
156 # define weak_alias(original, alias) \
157 .weak C_SYMBOL_NAME (alias) ASM_LINE_SEP \
158 C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original)
159 # endif
160
161 # define weak_extern(symbol) \
162 .weak C_SYMBOL_NAME (symbol)
163
164 # endif /* ! HAVE_ASM_WEAKEXT_DIRECTIVE */
165
166 # else /* ! HAVE_WEAK_SYMBOLS */
167
168 # define weak_alias(original, alias) strong_alias(original, alias)
169 # define weak_extern(symbol) /* Nothing */
170 # endif /* ! HAVE_WEAK_SYMBOLS */
171
172 #endif /* __ASSEMBLER__ */
173
174 /* On some platforms we can make internal function calls (i.e., calls of
175 functions not exported) a bit faster by using a different calling
176 convention. */
177 #ifndef internal_function
178 # define internal_function /* empty */
179 #endif
180
181 /* Prepare for the case that `__builtin_expect' is not available. */
182 #ifndef HAVE_BUILTIN_EXPECT
183 # define __builtin_expect(expr, val) (expr)
184 #endif
185
186 /* Determine the return address. */
187 #define RETURN_ADDRESS(nr) \
188 __builtin_extract_return_addr (__builtin_return_address (nr))
189
190 /* When a reference to SYMBOL is encountered, the linker will emit a
191 warning message MSG. */
192 #ifdef HAVE_GNU_LD
193 # ifdef HAVE_ELF
194
195 /* We want the .gnu.warning.SYMBOL section to be unallocated. */
196 # ifdef HAVE_ASM_PREVIOUS_DIRECTIVE
197 # define __make_section_unallocated(section_string) \
198 asm (".section " section_string "\n\t.previous");
199 # elif defined HAVE_ASM_POPSECTION_DIRECTIVE
200 # define __make_section_unallocated(section_string) \
201 asm (".pushsection " section_string "\n\t.popsection");
202 # else
203 # define __make_section_unallocated(section_string)
204 # endif
205
206 /* Tacking on "\n\t#" to the section name makes gcc put it's bogus
207 section attributes on what looks like a comment to the assembler. */
208 # ifdef HAVE_SECTION_QUOTES
209 # define link_warning(symbol, msg) \
210 __make_section_unallocated (".gnu.warning." #symbol) \
211 static const char __evoke_link_warning_##symbol[] \
212 __attribute__ ((section (".gnu.warning." #symbol "\"\n\t#\""))) = msg;
213 # else
214 # define link_warning(symbol, msg) \
215 __make_section_unallocated (".gnu.warning." #symbol) \
216 static const char __evoke_link_warning_##symbol[] \
217 __attribute__ ((section (".gnu.warning." #symbol "\n\t#"))) = msg;
218 # endif
219 # else
220 # define link_warning(symbol, msg) \
221 asm (".stabs \"" msg "\",30,0,0,0\n\t" \
222 ".stabs \"" __SYMBOL_PREFIX #symbol "\",1,0,0,0\n");
223 # endif
224 #else
225 /* We will never be heard; they will all die horribly. */
226 # define link_warning(symbol, msg)
227 #endif
228
229 /* A canned warning for sysdeps/stub functions. */
230 #define stub_warning(name) \
231 link_warning (name, \
232 "warning: " #name " is not implemented and will always fail")
233
234 /*
235 \f
236 */
237
238 #ifdef HAVE_GNU_LD
239
240 /* Symbol set support macros. */
241
242 # ifdef HAVE_ELF
243
244 /* Make SYMBOL, which is in the text segment, an element of SET. */
245 # define text_set_element(set, symbol) _elf_set_element(set, symbol)
246 /* Make SYMBOL, which is in the data segment, an element of SET. */
247 # define data_set_element(set, symbol) _elf_set_element(set, symbol)
248 /* Make SYMBOL, which is in the bss segment, an element of SET. */
249 # define bss_set_element(set, symbol) _elf_set_element(set, symbol)
250
251 /* These are all done the same way in ELF.
252 There is a new section created for each set. */
253 # ifdef SHARED
254 /* When building a shared library, make the set section writable,
255 because it will need to be relocated at run time anyway. */
256 # define _elf_set_element(set, symbol) \
257 static const void *__elf_set_##set##_element_##symbol##__ \
258 __attribute__ ((unused, section (#set))) = &(symbol)
259 # else
260 # define _elf_set_element(set, symbol) \
261 static const void *const __elf_set_##set##_element_##symbol##__ \
262 __attribute__ ((unused, section (#set))) = &(symbol)
263 # endif
264
265 /* Define SET as a symbol set. This may be required (it is in a.out) to
266 be able to use the set's contents. */
267 # define symbol_set_define(set) symbol_set_declare(set)
268
269 /* Declare SET for use in this module, if defined in another module. */
270 # define symbol_set_declare(set) \
271 extern void *const __start_##set __attribute__ ((__weak__)); \
272 extern void *const __stop_##set __attribute__ ((__weak__)); \
273 weak_extern (__start_##set) weak_extern (__stop_##set)
274
275 /* Return a pointer (void *const *) to the first element of SET. */
276 # define symbol_set_first_element(set) (&__start_##set)
277
278 /* Return true iff PTR (a void *const *) has been incremented
279 past the last element in SET. */
280 # define symbol_set_end_p(set, ptr) ((ptr) >= &__stop_##set)
281
282 # else /* Not ELF: a.out. */
283
284 # define text_set_element(set, symbol) \
285 asm (".stabs \"" __SYMBOL_PREFIX #set "\",23,0,0," __SYMBOL_PREFIX #symbol)
286 # define data_set_element(set, symbol) \
287 asm (".stabs \"" __SYMBOL_PREFIX #set "\",25,0,0," __SYMBOL_PREFIX #symbol)
288 # define bss_set_element(set, symbol) ?error Must use initialized data.
289 # define symbol_set_define(set) void *const (set)[1];
290 # define symbol_set_declare(set) extern void *const (set)[1];
291
292 # define symbol_set_first_element(set) &(set)[1]
293 # define symbol_set_end_p(set, ptr) (*(ptr) == 0)
294
295 # endif /* ELF. */
296 #endif /* Have GNU ld. */
297
298 #if DO_VERSIONING
299 # define symbol_version(real, name, version) \
300 _symbol_version(real, name, version)
301 # define default_symbol_version(real, name, version) \
302 _default_symbol_version(real, name, version)
303 # ifdef __ASSEMBLER__
304 # define _symbol_version(real, name, version) \
305 .symver real, name##@##version
306 # define _default_symbol_version(real, name, version) \
307 .symver real, name##@##@##version
308 # else
309 # define _symbol_version(real, name, version) \
310 __asm__ (".symver " #real "," #name "@" #version)
311 # define _default_symbol_version(real, name, version) \
312 __asm__ (".symver " #real "," #name "@@" #version)
313 # endif
314 #else
315 # define symbol_version(real, name, version)
316 # define default_symbol_version(real, name, version) \
317 strong_alias(real, name)
318 #endif
319
320 #endif /* libc-symbols.h */