]>
Commit | Line | Data |
---|---|---|
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. | |
92777700 | 3 | Copyright (C) 1995, 1996 Free Software Foundation, Inc. |
28f540f4 RM |
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 | |
18 | not, write to the Free Software Foundation, Inc., 675 Mass Ave, | |
19 | Cambridge, MA 02139, USA. */ | |
20 | ||
21 | #ifndef _LIBC_SYMBOLS_H | |
22 | #define _LIBC_SYMBOLS_H | |
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'. | |
28f540f4 RM |
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. | |
c224a18a RM |
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'. | |
28f540f4 RM |
37 | |
38 | */ | |
28f540f4 | 39 | |
92777700 RM |
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. */ | |
c709e372 | 47 | #define _LIBC 1 |
92777700 | 48 | |
d3669add RM |
49 | /* Enable declarations of GNU extensions, since we are compiling them. */ |
50 | #define _GNU_SOURCE 1 | |
51 | ||
92777700 | 52 | #include <config.h> |
cb2f05ed RM |
53 | /* |
54 | \f | |
b3a59f40 | 55 | */ |
28f540f4 | 56 | |
b3a59f40 | 57 | #ifndef ASSEMBLER |
f45e34fc RM |
58 | |
59 | /* Define the macros `_' and `N_' for conveniently marking translatable | |
60 | strings in the libc source code. */ | |
61 | ||
62 | #define N_(msgid) msgid | |
63 | ||
cb2f05ed RM |
64 | #include <libintl.h> |
65 | extern const char _libc_intl_domainname[]; | |
f45e34fc | 66 | |
cb2f05ed RM |
67 | #ifdef dgettext |
68 | /* This is defined as an optimizing macro, so use it. */ | |
69 | #define _(msgid) dgettext (_libc_intl_domainname, (msgid)) | |
70 | #else | |
71 | /* Be sure to use only the __ name when `dgettext' is a plain function | |
72 | instead of an optimizing macro. */ | |
73 | #define _(msgid) __dgettext (_libc_intl_domainname, (msgid)) | |
74 | #endif | |
f45e34fc | 75 | |
b3a59f40 | 76 | #endif |
cb2f05ed RM |
77 | |
78 | /* | |
79 | \f | |
80 | */ | |
c224a18a RM |
81 | /* The symbols in all the user (non-_) macros are C symbols. |
82 | HAVE_GNU_LD without HAVE_ELF implies a.out. */ | |
28f540f4 | 83 | |
c224a18a | 84 | #if defined (HAVE_ASM_WEAK_DIRECTIVE) || defined (HAVE_ASM_WEAKEXT_DIRECTIVE) |
28f540f4 RM |
85 | #define HAVE_WEAK_SYMBOLS |
86 | #endif | |
28f540f4 RM |
87 | |
88 | #ifndef __SYMBOL_PREFIX | |
28f540f4 RM |
89 | #ifdef NO_UNDERSCORES |
90 | #define __SYMBOL_PREFIX | |
91 | #else | |
92 | #define __SYMBOL_PREFIX "_" | |
93 | #endif | |
94 | #endif | |
95 | ||
96 | #ifndef C_SYMBOL_NAME | |
97 | #ifdef NO_UNDERSCORES | |
98 | #define C_SYMBOL_NAME(name) name | |
99 | #else | |
100 | #define C_SYMBOL_NAME(name) _##name | |
101 | #endif | |
102 | #endif | |
103 | ||
d02907df | 104 | |
28f540f4 | 105 | /* Define ALIAS as a strong alias for ORIGINAL. */ |
335aa320 | 106 | #ifdef HAVE_ASM_SET_DIRECTIVE |
28f540f4 | 107 | #define strong_alias_asm(original, alias) \ |
d02907df | 108 | ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME (alias); \ |
28f540f4 RM |
109 | .set C_SYMBOL_NAME (alias),C_SYMBOL_NAME (original) |
110 | #ifdef ASSEMBLER | |
111 | #define strong_alias(original, alias) strong_alias_asm (original, alias) | |
112 | #else | |
113 | #define strong_alias(original, alias) \ | |
d02907df RM |
114 | asm (__string_1 (ASM_GLOBAL_DIRECTIVE) " " __SYMBOL_PREFIX #alias "\n" \ |
115 | ".set " __SYMBOL_PREFIX #alias "," __SYMBOL_PREFIX #original); | |
28f540f4 | 116 | #endif |
335aa320 RM |
117 | #else |
118 | #define strong_alias_asm(original, alias) \ | |
d02907df | 119 | ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME (alias); \ |
335aa320 RM |
120 | C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original) |
121 | #ifdef ASSEMBLER | |
122 | #define strong_alias(original, alias) strong_alias_asm (original, alias) | |
123 | #else | |
124 | #define strong_alias(original, alias) \ | |
d02907df RM |
125 | asm (__string_1 (ASM_GLOBAL_DIRECTIVE) " " __SYMBOL_PREFIX #alias "\n" \ |
126 | __SYMBOL_PREFIX #alias " = " __SYMBOL_PREFIX #original); | |
335aa320 RM |
127 | #endif |
128 | #endif | |
28f540f4 | 129 | |
d02907df RM |
130 | /* Helper macros used above. */ |
131 | #define __string_1(x) __string_0(x) | |
132 | #define __string_0(x) #x | |
133 | ||
134 | ||
28f540f4 | 135 | #ifdef HAVE_WEAK_SYMBOLS |
c224a18a | 136 | |
28f540f4 | 137 | #ifdef ASSEMBLER |
d02907df | 138 | |
c224a18a RM |
139 | #ifdef HAVE_ASM_WEAKEXT_DIRECTIVE |
140 | ||
141 | /* Define ALIAS as a weak alias for ORIGINAL. | |
142 | If weak aliases are not available, this defines a strong alias. */ | |
143 | #define weak_alias(original, alias) \ | |
144 | .weakext C_SYMBOL_NAME (alias), C_SYMBOL_NAME (original) | |
145 | ||
af5b3bc3 RM |
146 | /* Declare SYMBOL as weak undefined symbol (resolved to 0 if not defined). */ |
147 | #define weak_extern(symbol) \ | |
148 | .weakext C_SYMBOL_NAME (symbol) | |
c224a18a RM |
149 | |
150 | #else /* ! HAVE_ASM_WEAKEXT_DIRECTIVE */ | |
151 | ||
d02907df RM |
152 | /* Define ALIAS as a weak alias for ORIGINAL. |
153 | If weak aliases are not available, this defines a strong alias. */ | |
28f540f4 RM |
154 | #define weak_alias(original, alias) \ |
155 | .weak C_SYMBOL_NAME (alias); \ | |
156 | C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original) | |
e6964dd4 | 157 | |
af5b3bc3 RM |
158 | |
159 | /* Declare SYMBOL as weak undefined symbol (resolved to 0 if not defined). */ | |
160 | #define weak_extern(symbol) \ | |
161 | .weak C_SYMBOL_NAME (symbol) | |
d02907df | 162 | |
c224a18a RM |
163 | #endif /* ! HAVE_ASM_WEAKEXT_DIRECTIVE */ |
164 | ||
165 | #else /* ! ASSEMBLER */ | |
166 | ||
167 | #ifdef HAVE_ASM_WEAKEXT_DIRECTIVE | |
af5b3bc3 RM |
168 | #define weak_extern_asm(symbol) asm (".weakext " __SYMBOL_PREFIX #symbol); |
169 | #define weak_alias_asm(original, alias) \ | |
c224a18a RM |
170 | asm (".weakext " __SYMBOL_PREFIX #alias ", " __SYMBOL_PREFIX #original); |
171 | #else /* ! HAVE_ASM_WEAKEXT_DIRECTIVE */ | |
af5b3bc3 RM |
172 | #define weak_extern_asm(symbol) asm (".weak " __SYMBOL_PREFIX #symbol); |
173 | #define weak_alias_asm(original, alias) \ | |
28f540f4 RM |
174 | asm (".weak " __SYMBOL_PREFIX #alias "\n" \ |
175 | __SYMBOL_PREFIX #alias " = " __SYMBOL_PREFIX #original); | |
c224a18a | 176 | #endif /* ! HAVE_ASM_WEAKEXT_DIRECTIVE */ |
af5b3bc3 RM |
177 | |
178 | #define weak_alias(o, a) weak_alias_asm (o, a) | |
179 | #define weak_extern(symbol) weak_extern_asm (symbol) | |
180 | ||
c224a18a | 181 | #endif /* ! ASSEMBLER */ |
28f540f4 RM |
182 | #else |
183 | #define weak_alias(original, alias) strong_alias(original, alias) | |
af5b3bc3 | 184 | #define weak_extern(symbol) /* Do nothing; the ref will be strong. */ |
28f540f4 RM |
185 | #endif |
186 | ||
187 | ||
958f803f | 188 | #if (!defined (ASSEMBLER) && \ |
af5b3bc3 RM |
189 | (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7))) |
190 | /* GCC 2.7 and later has special syntax for weak symbols and aliases. | |
958f803f RM |
191 | Using that is better when possible, because the compiler and assembler |
192 | are better clued in to what we are doing. */ | |
193 | #undef strong_alias | |
194 | #define strong_alias(name, aliasname) \ | |
af5b3bc3 | 195 | extern __typeof (name) aliasname __attribute__ ((alias (#name))); |
958f803f RM |
196 | |
197 | #ifdef HAVE_WEAK_SYMBOLS | |
958f803f RM |
198 | #undef weak_alias |
199 | #define weak_alias(name, aliasname) \ | |
af5b3bc3 RM |
200 | extern __typeof (name) aliasname __attribute__ ((weak, alias (#name))); |
201 | ||
202 | /* This comes between the return type and function name in | |
203 | a function definition to make that definition weak. */ | |
204 | #define weak_function __attribute__ ((weak)) | |
edf5b2d7 | 205 | #define weak_const_function __attribute__ ((weak, __const__)) |
af5b3bc3 | 206 | |
958f803f | 207 | #endif /* HAVE_WEAK_SYMBOLS. */ |
af5b3bc3 RM |
208 | #endif /* Not ASSEMBLER, and GCC 2.7 or later. */ |
209 | ||
958f803f | 210 | |
af5b3bc3 RM |
211 | #ifndef weak_function |
212 | /* If we do not have the __attribute__ ((weak)) syntax, there is no way we | |
213 | can define functions as weak symbols. The compiler will emit a `.globl' | |
214 | directive for the function symbol, and a `.weak' directive in addition | |
215 | will produce an error from the assembler. */ | |
216 | #define weak_function /* empty */ | |
edf5b2d7 | 217 | #define weak_const_function /* empty */ |
af5b3bc3 | 218 | #endif |
958f803f | 219 | |
28f540f4 | 220 | |
44c8d1a2 RM |
221 | /* When a reference to SYMBOL is encountered, the linker will emit a |
222 | warning message MSG. */ | |
28f540f4 RM |
223 | #ifdef HAVE_GNU_LD |
224 | #ifdef HAVE_ELF | |
44c8d1a2 RM |
225 | #define link_warning(symbol, msg) \ |
226 | static const char __evoke_link_warning_##symbol[] \ | |
227 | __attribute__ ((section (".gnu.warning." #symbol))) = msg; | |
28f540f4 | 228 | #else |
44c8d1a2 | 229 | #define link_warning(symbol, msg) \ |
28f540f4 | 230 | asm(".stabs \"" msg "\",30,0,0,0\n" \ |
44c8d1a2 | 231 | ".stabs \"" __SYMBOL_PREFIX #symbol "\",1,0,0,0\n"); |
28f540f4 RM |
232 | #endif |
233 | #else | |
234 | /* We will never be heard; they will all die horribly. */ | |
44c8d1a2 | 235 | #define link_warning(symbol, msg) |
28f540f4 RM |
236 | #endif |
237 | ||
238 | /* A canned warning for sysdeps/stub functions. */ | |
239 | #define stub_warning(name) \ | |
44c8d1a2 RM |
240 | link_warning (name, \ |
241 | "warning: " #name " is not implemented and will always fail") | |
5f9e57ba RM |
242 | |
243 | /* | |
28f540f4 | 244 | \f |
5f9e57ba RM |
245 | */ |
246 | ||
28f540f4 RM |
247 | #ifdef HAVE_GNU_LD |
248 | ||
249 | /* Symbol set support macros. */ | |
250 | ||
251 | #ifdef HAVE_ELF | |
252 | ||
253 | /* Make SYMBOL, which is in the text segment, an element of SET. */ | |
254 | #define text_set_element(set, symbol) _elf_set_element(set, symbol) | |
255 | /* Make SYMBOL, which is in the data segment, an element of SET. */ | |
256 | #define data_set_element(set, symbol) _elf_set_element(set, symbol) | |
257 | /* Make SYMBOL, which is in the bss segment, an element of SET. */ | |
258 | #define bss_set_element(set, symbol) _elf_set_element(set, symbol) | |
259 | ||
260 | /* These are all done the same way in ELF. | |
261 | There is a new section created for each set. */ | |
53afa8d9 RM |
262 | #ifdef PIC |
263 | /* When building a shared library, make the set section writable, | |
264 | because it will need to be relocated at run time anyway. */ | |
265 | #define _elf_set_element(set, symbol) \ | |
266 | static const void *__elf_set_##set##_element_##symbol##__ \ | |
d6e2f671 | 267 | __attribute__ ((unused, section (#set))) = &(symbol) |
53afa8d9 | 268 | #else |
28f540f4 RM |
269 | #define _elf_set_element(set, symbol) \ |
270 | static const void *const __elf_set_##set##_element_##symbol##__ \ | |
d6e2f671 | 271 | __attribute__ ((unused, section (#set))) = &(symbol) |
53afa8d9 | 272 | #endif |
28f540f4 RM |
273 | |
274 | /* Define SET as a symbol set. This may be required (it is in a.out) to | |
275 | be able to use the set's contents. */ | |
276 | #define symbol_set_define(set) symbol_set_declare(set) | |
277 | ||
278 | /* Declare SET for use in this module, if defined in another module. */ | |
279 | #define symbol_set_declare(set) \ | |
ec967c06 RM |
280 | extern void *const __start_##set __attribute__ ((__weak__)); \ |
281 | extern void *const __stop_##set __attribute__ ((__weak__)); \ | |
af5b3bc3 | 282 | weak_extern (__start_##set) weak_extern (__stop_##set) |
28f540f4 RM |
283 | |
284 | /* Return a pointer (void *const *) to the first element of SET. */ | |
285 | #define symbol_set_first_element(set) (&__start_##set) | |
286 | ||
287 | /* Return true iff PTR (a void *const *) has been incremented | |
288 | past the last element in SET. */ | |
289 | #define symbol_set_end_p(set, ptr) ((ptr) >= &__stop_##set) | |
290 | ||
291 | #else /* Not ELF: a.out. */ | |
292 | ||
293 | #define text_set_element(set, symbol) \ | |
294 | asm(".stabs \"" __SYMBOL_PREFIX #set "\",23,0,0," __SYMBOL_PREFIX #symbol) | |
295 | #define data_set_element(set, symbol) \ | |
296 | asm(".stabs \"" __SYMBOL_PREFIX #set "\",25,0,0," __SYMBOL_PREFIX #symbol) | |
297 | #define bss_set_element(set, symbol) ?error Must use initialized data. | |
298 | #define symbol_set_define(set) void *const (set)[1]; | |
299 | #define symbol_set_declare(set) extern void *const (set)[1]; | |
300 | ||
301 | #define symbol_set_first_element(set) &(set)[1] | |
302 | #define symbol_set_end_p(set, ptr) (*(ptr) == 0) | |
303 | ||
304 | #endif /* ELF. */ | |
305 | #endif /* Have GNU ld. */ | |
306 | ||
307 | #endif /* libc-symbols.h */ |