]>
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 | ||
146 | /* Declare SYMBOL to be weak. */ | |
147 | #define weak_symbol(symbol) .weakext C_SYMBOL_NAME (symbol) | |
148 | ||
149 | #else /* ! HAVE_ASM_WEAKEXT_DIRECTIVE */ | |
150 | ||
d02907df RM |
151 | /* Define ALIAS as a weak alias for ORIGINAL. |
152 | If weak aliases are not available, this defines a strong alias. */ | |
28f540f4 RM |
153 | #define weak_alias(original, alias) \ |
154 | .weak C_SYMBOL_NAME (alias); \ | |
155 | C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original) | |
e6964dd4 RM |
156 | |
157 | /* Declare SYMBOL to be weak. */ | |
158 | #define weak_symbol(symbol) .weak C_SYMBOL_NAME (symbol) | |
d02907df | 159 | |
c224a18a RM |
160 | #endif /* ! HAVE_ASM_WEAKEXT_DIRECTIVE */ |
161 | ||
162 | #else /* ! ASSEMBLER */ | |
163 | ||
164 | #ifdef HAVE_ASM_WEAKEXT_DIRECTIVE | |
165 | #define weak_symbol(symbol) asm (".weakext " __SYMBOL_PREFIX #symbol); | |
166 | #define weak_alias(original, alias) \ | |
167 | asm (".weakext " __SYMBOL_PREFIX #alias ", " __SYMBOL_PREFIX #original); | |
168 | #else /* ! HAVE_ASM_WEAKEXT_DIRECTIVE */ | |
e6964dd4 | 169 | #define weak_symbol(symbol) asm (".weak " __SYMBOL_PREFIX #symbol); |
28f540f4 RM |
170 | #define weak_alias(original, alias) \ |
171 | asm (".weak " __SYMBOL_PREFIX #alias "\n" \ | |
172 | __SYMBOL_PREFIX #alias " = " __SYMBOL_PREFIX #original); | |
c224a18a RM |
173 | #endif /* ! HAVE_ASM_WEAKEXT_DIRECTIVE */ |
174 | #endif /* ! ASSEMBLER */ | |
28f540f4 RM |
175 | #else |
176 | #define weak_alias(original, alias) strong_alias(original, alias) | |
e6964dd4 | 177 | #define weak_symbol(symbol) /* Do nothing. */ |
28f540f4 RM |
178 | #endif |
179 | ||
180 | ||
958f803f | 181 | #if (!defined (ASSEMBLER) && \ |
9199ec6e RM |
182 | (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))) |
183 | /* GCC 2.8 and later has special syntax for weak symbols and aliases. | |
958f803f RM |
184 | Using that is better when possible, because the compiler and assembler |
185 | are better clued in to what we are doing. */ | |
186 | #undef strong_alias | |
187 | #define strong_alias(name, aliasname) \ | |
6b628d36 | 188 | __typeof (name) aliasname __attribute__ ((alias (#name))); |
958f803f RM |
189 | |
190 | #ifdef HAVE_WEAK_SYMBOLS | |
191 | #undef weak_symbol | |
192 | #define weak_symbol(name) \ | |
54da5be3 | 193 | extern __typeof (name) name __attribute__ ((weak)); |
958f803f RM |
194 | #undef weak_alias |
195 | #define weak_alias(name, aliasname) \ | |
6b628d36 | 196 | __typeof (name) aliasname __attribute__ ((weak, alias (#name))); |
958f803f | 197 | #endif /* HAVE_WEAK_SYMBOLS. */ |
9199ec6e | 198 | #endif /* Not ASSEMBLER, and GCC 2.8 or later. */ |
958f803f RM |
199 | |
200 | ||
28f540f4 | 201 | |
44c8d1a2 RM |
202 | /* When a reference to SYMBOL is encountered, the linker will emit a |
203 | warning message MSG. */ | |
28f540f4 RM |
204 | #ifdef HAVE_GNU_LD |
205 | #ifdef HAVE_ELF | |
44c8d1a2 RM |
206 | #define link_warning(symbol, msg) \ |
207 | static const char __evoke_link_warning_##symbol[] \ | |
208 | __attribute__ ((section (".gnu.warning." #symbol))) = msg; | |
28f540f4 | 209 | #else |
44c8d1a2 | 210 | #define link_warning(symbol, msg) \ |
28f540f4 | 211 | asm(".stabs \"" msg "\",30,0,0,0\n" \ |
44c8d1a2 | 212 | ".stabs \"" __SYMBOL_PREFIX #symbol "\",1,0,0,0\n"); |
28f540f4 RM |
213 | #endif |
214 | #else | |
215 | /* We will never be heard; they will all die horribly. */ | |
44c8d1a2 | 216 | #define link_warning(symbol, msg) |
28f540f4 RM |
217 | #endif |
218 | ||
219 | /* A canned warning for sysdeps/stub functions. */ | |
220 | #define stub_warning(name) \ | |
44c8d1a2 RM |
221 | link_warning (name, \ |
222 | "warning: " #name " is not implemented and will always fail") | |
5f9e57ba RM |
223 | |
224 | /* | |
28f540f4 | 225 | \f |
5f9e57ba RM |
226 | */ |
227 | ||
28f540f4 RM |
228 | #ifdef HAVE_GNU_LD |
229 | ||
230 | /* Symbol set support macros. */ | |
231 | ||
232 | #ifdef HAVE_ELF | |
233 | ||
234 | /* Make SYMBOL, which is in the text segment, an element of SET. */ | |
235 | #define text_set_element(set, symbol) _elf_set_element(set, symbol) | |
236 | /* Make SYMBOL, which is in the data segment, an element of SET. */ | |
237 | #define data_set_element(set, symbol) _elf_set_element(set, symbol) | |
238 | /* Make SYMBOL, which is in the bss segment, an element of SET. */ | |
239 | #define bss_set_element(set, symbol) _elf_set_element(set, symbol) | |
240 | ||
241 | /* These are all done the same way in ELF. | |
242 | There is a new section created for each set. */ | |
53afa8d9 RM |
243 | #ifdef PIC |
244 | /* When building a shared library, make the set section writable, | |
245 | because it will need to be relocated at run time anyway. */ | |
246 | #define _elf_set_element(set, symbol) \ | |
247 | static const void *__elf_set_##set##_element_##symbol##__ \ | |
d6e2f671 | 248 | __attribute__ ((unused, section (#set))) = &(symbol) |
53afa8d9 | 249 | #else |
28f540f4 RM |
250 | #define _elf_set_element(set, symbol) \ |
251 | static const void *const __elf_set_##set##_element_##symbol##__ \ | |
d6e2f671 | 252 | __attribute__ ((unused, section (#set))) = &(symbol) |
53afa8d9 | 253 | #endif |
28f540f4 RM |
254 | |
255 | /* Define SET as a symbol set. This may be required (it is in a.out) to | |
256 | be able to use the set's contents. */ | |
257 | #define symbol_set_define(set) symbol_set_declare(set) | |
258 | ||
259 | /* Declare SET for use in this module, if defined in another module. */ | |
260 | #define symbol_set_declare(set) \ | |
ec967c06 RM |
261 | extern void *const __start_##set __attribute__ ((__weak__)); \ |
262 | extern void *const __stop_##set __attribute__ ((__weak__)); \ | |
263 | /* Gratuitously repeat weak decl, in case using broken GCC (<2.8). */\ | |
264 | weak_symbol (__start_##set) weak_symbol (__stop_##set) | |
28f540f4 RM |
265 | |
266 | /* Return a pointer (void *const *) to the first element of SET. */ | |
267 | #define symbol_set_first_element(set) (&__start_##set) | |
268 | ||
269 | /* Return true iff PTR (a void *const *) has been incremented | |
270 | past the last element in SET. */ | |
271 | #define symbol_set_end_p(set, ptr) ((ptr) >= &__stop_##set) | |
272 | ||
273 | #else /* Not ELF: a.out. */ | |
274 | ||
275 | #define text_set_element(set, symbol) \ | |
276 | asm(".stabs \"" __SYMBOL_PREFIX #set "\",23,0,0," __SYMBOL_PREFIX #symbol) | |
277 | #define data_set_element(set, symbol) \ | |
278 | asm(".stabs \"" __SYMBOL_PREFIX #set "\",25,0,0," __SYMBOL_PREFIX #symbol) | |
279 | #define bss_set_element(set, symbol) ?error Must use initialized data. | |
280 | #define symbol_set_define(set) void *const (set)[1]; | |
281 | #define symbol_set_declare(set) extern void *const (set)[1]; | |
282 | ||
283 | #define symbol_set_first_element(set) &(set)[1] | |
284 | #define symbol_set_end_p(set, ptr) (*(ptr) == 0) | |
285 | ||
286 | #endif /* ELF. */ | |
287 | #endif /* Have GNU ld. */ | |
288 | ||
289 | #endif /* libc-symbols.h */ |