]>
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 | ||
30 | * HAVE_GNU_LD if using GNU ld, with support for weak symbols in a.out, | |
31 | and for symbol set and warning messages extensions in a.out and ELF. | |
32 | This implies HAVE_WEAK_SYMBOLS; set by --with-gnu-ld. | |
33 | * HAVE_ELF if using ELF, which supports weak symbols. | |
34 | This implies HAVE_WEAK_SYMBOLS; set by --with-elf. | |
35 | ||
36 | * HAVE_WEAK_SYMBOLS if weak symbols are available in the assembler and | |
37 | linker being used. Set by --with-weak-symbols. | |
38 | ||
39 | */ | |
28f540f4 | 40 | |
92777700 RM |
41 | /* This is defined for the compilation of all C library code. features.h |
42 | tests this to avoid inclusion of stubs.h while compiling the library, | |
43 | before stubs.h has been generated. Some library code that is shared | |
44 | with other packages also tests this symbol to see if it is being | |
45 | compiled as part of the C library. We must define this before including | |
46 | config.h, because it makes some definitions conditional on whether libc | |
47 | itself is being compiled, or just some generator program. */ | |
c709e372 | 48 | #define _LIBC 1 |
92777700 RM |
49 | |
50 | #include <config.h> | |
6025c399 RM |
51 | |
52 | /* This disables sccsid/rcsid strings in lots of code of non-GNU origin. */ | |
53 | #define lint 1 | |
cb2f05ed RM |
54 | /* |
55 | \f | |
b3a59f40 | 56 | */ |
28f540f4 | 57 | |
b3a59f40 | 58 | #ifndef ASSEMBLER |
f45e34fc RM |
59 | |
60 | /* Define the macros `_' and `N_' for conveniently marking translatable | |
61 | strings in the libc source code. */ | |
62 | ||
63 | #define N_(msgid) msgid | |
64 | ||
cb2f05ed RM |
65 | #include <libintl.h> |
66 | extern const char _libc_intl_domainname[]; | |
f45e34fc | 67 | |
cb2f05ed RM |
68 | #ifdef dgettext |
69 | /* This is defined as an optimizing macro, so use it. */ | |
70 | #define _(msgid) dgettext (_libc_intl_domainname, (msgid)) | |
71 | #else | |
72 | /* Be sure to use only the __ name when `dgettext' is a plain function | |
73 | instead of an optimizing macro. */ | |
74 | #define _(msgid) __dgettext (_libc_intl_domainname, (msgid)) | |
75 | #endif | |
f45e34fc | 76 | |
b3a59f40 | 77 | #endif |
cb2f05ed RM |
78 | |
79 | /* | |
80 | \f | |
81 | */ | |
28f540f4 RM |
82 | /* The symbols in all the user (non-_) macros are C symbols. Predefined |
83 | should be HAVE_WEAK_SYMBOLS and/or HAVE_ELF and/or HAVE_GNU_LD. | |
84 | HAVE_WEAK_SYMBOLS is implied by the other two. HAVE_GNU_LD without | |
85 | HAVE_ELF implies a.out. */ | |
86 | ||
87 | #ifndef HAVE_WEAK_SYMBOLS | |
88 | #if defined (HAVE_ELF) || defined (HAVE_GNU_LD) | |
89 | #define HAVE_WEAK_SYMBOLS | |
90 | #endif | |
91 | #endif | |
92 | ||
93 | #ifndef __SYMBOL_PREFIX | |
94 | #ifdef HAVE_ELF | |
95 | #define NO_UNDERSCORES | |
96 | #else | |
97 | #include <sysdep.h> /* Should define NO_UNDERSCORES. */ | |
98 | #endif | |
99 | #ifdef NO_UNDERSCORES | |
100 | #define __SYMBOL_PREFIX | |
101 | #else | |
102 | #define __SYMBOL_PREFIX "_" | |
103 | #endif | |
104 | #endif | |
105 | ||
106 | #ifndef C_SYMBOL_NAME | |
107 | #ifdef NO_UNDERSCORES | |
108 | #define C_SYMBOL_NAME(name) name | |
109 | #else | |
110 | #define C_SYMBOL_NAME(name) _##name | |
111 | #endif | |
112 | #endif | |
113 | ||
d02907df | 114 | |
28f540f4 | 115 | /* Define ALIAS as a strong alias for ORIGINAL. */ |
335aa320 | 116 | #ifdef HAVE_ASM_SET_DIRECTIVE |
28f540f4 | 117 | #define strong_alias_asm(original, alias) \ |
d02907df | 118 | ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME (alias); \ |
28f540f4 RM |
119 | .set C_SYMBOL_NAME (alias),C_SYMBOL_NAME (original) |
120 | #ifdef ASSEMBLER | |
121 | #define strong_alias(original, alias) strong_alias_asm (original, alias) | |
122 | #else | |
123 | #define strong_alias(original, alias) \ | |
d02907df RM |
124 | asm (__string_1 (ASM_GLOBAL_DIRECTIVE) " " __SYMBOL_PREFIX #alias "\n" \ |
125 | ".set " __SYMBOL_PREFIX #alias "," __SYMBOL_PREFIX #original); | |
28f540f4 | 126 | #endif |
335aa320 RM |
127 | #else |
128 | #define strong_alias_asm(original, alias) \ | |
d02907df | 129 | ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME (alias); \ |
335aa320 RM |
130 | C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original) |
131 | #ifdef ASSEMBLER | |
132 | #define strong_alias(original, alias) strong_alias_asm (original, alias) | |
133 | #else | |
134 | #define strong_alias(original, alias) \ | |
d02907df RM |
135 | asm (__string_1 (ASM_GLOBAL_DIRECTIVE) " " __SYMBOL_PREFIX #alias "\n" \ |
136 | __SYMBOL_PREFIX #alias " = " __SYMBOL_PREFIX #original); | |
335aa320 RM |
137 | #endif |
138 | #endif | |
28f540f4 | 139 | |
d02907df RM |
140 | /* Helper macros used above. */ |
141 | #define __string_1(x) __string_0(x) | |
142 | #define __string_0(x) #x | |
143 | ||
144 | ||
28f540f4 RM |
145 | #ifdef HAVE_WEAK_SYMBOLS |
146 | #ifdef ASSEMBLER | |
d02907df RM |
147 | |
148 | /* Define ALIAS as a weak alias for ORIGINAL. | |
149 | If weak aliases are not available, this defines a strong alias. */ | |
28f540f4 RM |
150 | #define weak_alias(original, alias) \ |
151 | .weak C_SYMBOL_NAME (alias); \ | |
152 | C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original) | |
e6964dd4 RM |
153 | |
154 | /* Declare SYMBOL to be weak. */ | |
155 | #define weak_symbol(symbol) .weak C_SYMBOL_NAME (symbol) | |
d02907df | 156 | |
28f540f4 | 157 | #else |
e6964dd4 | 158 | #define weak_symbol(symbol) asm (".weak " __SYMBOL_PREFIX #symbol); |
28f540f4 RM |
159 | #define weak_alias(original, alias) \ |
160 | asm (".weak " __SYMBOL_PREFIX #alias "\n" \ | |
161 | __SYMBOL_PREFIX #alias " = " __SYMBOL_PREFIX #original); | |
162 | #endif | |
163 | #else | |
164 | #define weak_alias(original, alias) strong_alias(original, alias) | |
e6964dd4 | 165 | #define weak_symbol(symbol) /* Do nothing. */ |
28f540f4 RM |
166 | #endif |
167 | ||
168 | ||
958f803f | 169 | #if (!defined (ASSEMBLER) && \ |
9199ec6e RM |
170 | (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))) |
171 | /* GCC 2.8 and later has special syntax for weak symbols and aliases. | |
958f803f RM |
172 | Using that is better when possible, because the compiler and assembler |
173 | are better clued in to what we are doing. */ | |
174 | #undef strong_alias | |
175 | #define strong_alias(name, aliasname) \ | |
6b628d36 | 176 | __typeof (name) aliasname __attribute__ ((alias (#name))); |
958f803f RM |
177 | |
178 | #ifdef HAVE_WEAK_SYMBOLS | |
179 | #undef weak_symbol | |
180 | #define weak_symbol(name) \ | |
54da5be3 | 181 | extern __typeof (name) name __attribute__ ((weak)); |
958f803f RM |
182 | #undef weak_alias |
183 | #define weak_alias(name, aliasname) \ | |
6b628d36 | 184 | __typeof (name) aliasname __attribute__ ((weak, alias (#name))); |
958f803f | 185 | #endif /* HAVE_WEAK_SYMBOLS. */ |
9199ec6e | 186 | #endif /* Not ASSEMBLER, and GCC 2.8 or later. */ |
958f803f RM |
187 | |
188 | ||
28f540f4 | 189 | |
44c8d1a2 RM |
190 | /* When a reference to SYMBOL is encountered, the linker will emit a |
191 | warning message MSG. */ | |
28f540f4 RM |
192 | #ifdef HAVE_GNU_LD |
193 | #ifdef HAVE_ELF | |
44c8d1a2 RM |
194 | #define link_warning(symbol, msg) \ |
195 | static const char __evoke_link_warning_##symbol[] \ | |
196 | __attribute__ ((section (".gnu.warning." #symbol))) = msg; | |
28f540f4 | 197 | #else |
44c8d1a2 | 198 | #define link_warning(symbol, msg) \ |
28f540f4 | 199 | asm(".stabs \"" msg "\",30,0,0,0\n" \ |
44c8d1a2 | 200 | ".stabs \"" __SYMBOL_PREFIX #symbol "\",1,0,0,0\n"); |
28f540f4 RM |
201 | #endif |
202 | #else | |
203 | /* We will never be heard; they will all die horribly. */ | |
44c8d1a2 | 204 | #define link_warning(symbol, msg) |
28f540f4 RM |
205 | #endif |
206 | ||
207 | /* A canned warning for sysdeps/stub functions. */ | |
208 | #define stub_warning(name) \ | |
44c8d1a2 RM |
209 | link_warning (name, \ |
210 | "warning: " #name " is not implemented and will always fail") | |
5f9e57ba RM |
211 | |
212 | /* | |
28f540f4 | 213 | \f |
5f9e57ba RM |
214 | */ |
215 | ||
28f540f4 RM |
216 | #ifdef HAVE_GNU_LD |
217 | ||
218 | /* Symbol set support macros. */ | |
219 | ||
220 | #ifdef HAVE_ELF | |
221 | ||
222 | /* Make SYMBOL, which is in the text segment, an element of SET. */ | |
223 | #define text_set_element(set, symbol) _elf_set_element(set, symbol) | |
224 | /* Make SYMBOL, which is in the data segment, an element of SET. */ | |
225 | #define data_set_element(set, symbol) _elf_set_element(set, symbol) | |
226 | /* Make SYMBOL, which is in the bss segment, an element of SET. */ | |
227 | #define bss_set_element(set, symbol) _elf_set_element(set, symbol) | |
228 | ||
229 | /* These are all done the same way in ELF. | |
230 | There is a new section created for each set. */ | |
53afa8d9 RM |
231 | #ifdef PIC |
232 | /* When building a shared library, make the set section writable, | |
233 | because it will need to be relocated at run time anyway. */ | |
234 | #define _elf_set_element(set, symbol) \ | |
235 | static const void *__elf_set_##set##_element_##symbol##__ \ | |
d6e2f671 | 236 | __attribute__ ((unused, section (#set))) = &(symbol) |
53afa8d9 | 237 | #else |
28f540f4 RM |
238 | #define _elf_set_element(set, symbol) \ |
239 | static const void *const __elf_set_##set##_element_##symbol##__ \ | |
d6e2f671 | 240 | __attribute__ ((unused, section (#set))) = &(symbol) |
53afa8d9 | 241 | #endif |
28f540f4 RM |
242 | |
243 | /* Define SET as a symbol set. This may be required (it is in a.out) to | |
244 | be able to use the set's contents. */ | |
245 | #define symbol_set_define(set) symbol_set_declare(set) | |
246 | ||
247 | /* Declare SET for use in this module, if defined in another module. */ | |
248 | #define symbol_set_declare(set) \ | |
ec967c06 RM |
249 | extern void *const __start_##set __attribute__ ((__weak__)); \ |
250 | extern void *const __stop_##set __attribute__ ((__weak__)); \ | |
251 | /* Gratuitously repeat weak decl, in case using broken GCC (<2.8). */\ | |
252 | weak_symbol (__start_##set) weak_symbol (__stop_##set) | |
28f540f4 RM |
253 | |
254 | /* Return a pointer (void *const *) to the first element of SET. */ | |
255 | #define symbol_set_first_element(set) (&__start_##set) | |
256 | ||
257 | /* Return true iff PTR (a void *const *) has been incremented | |
258 | past the last element in SET. */ | |
259 | #define symbol_set_end_p(set, ptr) ((ptr) >= &__stop_##set) | |
260 | ||
261 | #else /* Not ELF: a.out. */ | |
262 | ||
263 | #define text_set_element(set, symbol) \ | |
264 | asm(".stabs \"" __SYMBOL_PREFIX #set "\",23,0,0," __SYMBOL_PREFIX #symbol) | |
265 | #define data_set_element(set, symbol) \ | |
266 | asm(".stabs \"" __SYMBOL_PREFIX #set "\",25,0,0," __SYMBOL_PREFIX #symbol) | |
267 | #define bss_set_element(set, symbol) ?error Must use initialized data. | |
268 | #define symbol_set_define(set) void *const (set)[1]; | |
269 | #define symbol_set_declare(set) extern void *const (set)[1]; | |
270 | ||
271 | #define symbol_set_first_element(set) &(set)[1] | |
272 | #define symbol_set_end_p(set, ptr) (*(ptr) == 0) | |
273 | ||
274 | #endif /* ELF. */ | |
275 | #endif /* Have GNU ld. */ | |
276 | ||
277 | #endif /* libc-symbols.h */ |