* Version 1.90 test release.
[glibc.git] / libc-symbols.h
blobaaf9f2a817fc931321080def4e61f7c2f5c9c172
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 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
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.
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.
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. */
21 #ifndef _LIBC_SYMBOLS_H
22 #define _LIBC_SYMBOLS_H
24 /* This file's macros are included implicitly in the compilation of every
25 file in the C library by -imacros.
27 We include config.h which is generated by configure.
28 It should define for us the following symbols:
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'.
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
49 /* Enable declarations of GNU extensions, since we are compiling them. */
50 #define _GNU_SOURCE 1
52 #include <config.h>
57 #ifndef ASSEMBLER
59 /* Define the macros `_' and `N_' for conveniently marking translatable
60 strings in the libc source code. */
62 #define N_(msgid) msgid
64 #include <libintl.h>
65 extern const char _libc_intl_domainname[];
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
76 #endif
81 /* The symbols in all the user (non-_) macros are C symbols.
82 HAVE_GNU_LD without HAVE_ELF implies a.out. */
84 #if defined (HAVE_ASM_WEAK_DIRECTIVE) || defined (HAVE_ASM_WEAKEXT_DIRECTIVE)
85 #define HAVE_WEAK_SYMBOLS
86 #endif
88 #ifndef __SYMBOL_PREFIX
89 #ifdef NO_UNDERSCORES
90 #define __SYMBOL_PREFIX
91 #else
92 #define __SYMBOL_PREFIX "_"
93 #endif
94 #endif
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
105 /* Define ALIAS as a strong alias for ORIGINAL. */
106 #ifdef HAVE_ASM_SET_DIRECTIVE
107 #define strong_alias_asm(original, alias) \
108 ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME (alias); \
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) \
114 asm (__string_1 (ASM_GLOBAL_DIRECTIVE) " " __SYMBOL_PREFIX #alias "\n" \
115 ".set " __SYMBOL_PREFIX #alias "," __SYMBOL_PREFIX #original);
116 #endif
117 #else
118 #define strong_alias_asm(original, alias) \
119 ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME (alias); \
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) \
125 asm (__string_1 (ASM_GLOBAL_DIRECTIVE) " " __SYMBOL_PREFIX #alias "\n" \
126 __SYMBOL_PREFIX #alias " = " __SYMBOL_PREFIX #original);
127 #endif
128 #endif
130 /* Helper macros used above. */
131 #define __string_1(x) __string_0(x)
132 #define __string_0(x) #x
135 #ifdef HAVE_WEAK_SYMBOLS
137 #ifdef ASSEMBLER
139 #ifdef HAVE_ASM_WEAKEXT_DIRECTIVE
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)
146 /* Declare SYMBOL to be weak. */
147 #define weak_symbol(symbol) .weakext C_SYMBOL_NAME (symbol)
149 #else /* ! HAVE_ASM_WEAKEXT_DIRECTIVE */
151 /* Define ALIAS as a weak alias for ORIGINAL.
152 If weak aliases are not available, this defines a strong alias. */
153 #define weak_alias(original, alias) \
154 .weak C_SYMBOL_NAME (alias); \
155 C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original)
157 /* Declare SYMBOL to be weak. */
158 #define weak_symbol(symbol) .weak C_SYMBOL_NAME (symbol)
160 #endif /* ! HAVE_ASM_WEAKEXT_DIRECTIVE */
162 #else /* ! ASSEMBLER */
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 */
169 #define weak_symbol(symbol) asm (".weak " __SYMBOL_PREFIX #symbol);
170 #define weak_alias(original, alias) \
171 asm (".weak " __SYMBOL_PREFIX #alias "\n" \
172 __SYMBOL_PREFIX #alias " = " __SYMBOL_PREFIX #original);
173 #endif /* ! HAVE_ASM_WEAKEXT_DIRECTIVE */
174 #endif /* ! ASSEMBLER */
175 #else
176 #define weak_alias(original, alias) strong_alias(original, alias)
177 #define weak_symbol(symbol) /* Do nothing. */
178 #endif
181 #if (!defined (ASSEMBLER) && \
182 (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8)))
183 /* GCC 2.8 and later has special syntax for weak symbols and aliases.
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) \
188 __typeof (name) aliasname __attribute__ ((alias (#name)));
190 #ifdef HAVE_WEAK_SYMBOLS
191 #undef weak_symbol
192 #define weak_symbol(name) \
193 extern __typeof (name) name __attribute__ ((weak));
194 #undef weak_alias
195 #define weak_alias(name, aliasname) \
196 __typeof (name) aliasname __attribute__ ((weak, alias (#name)));
197 #endif /* HAVE_WEAK_SYMBOLS. */
198 #endif /* Not ASSEMBLER, and GCC 2.8 or later. */
202 /* When a reference to SYMBOL is encountered, the linker will emit a
203 warning message MSG. */
204 #ifdef HAVE_GNU_LD
205 #ifdef HAVE_ELF
206 #define link_warning(symbol, msg) \
207 static const char __evoke_link_warning_##symbol[] \
208 __attribute__ ((section (".gnu.warning." #symbol))) = msg;
209 #else
210 #define link_warning(symbol, msg) \
211 asm(".stabs \"" msg "\",30,0,0,0\n" \
212 ".stabs \"" __SYMBOL_PREFIX #symbol "\",1,0,0,0\n");
213 #endif
214 #else
215 /* We will never be heard; they will all die horribly. */
216 #define link_warning(symbol, msg)
217 #endif
219 /* A canned warning for sysdeps/stub functions. */
220 #define stub_warning(name) \
221 link_warning (name, \
222 "warning: " #name " is not implemented and will always fail")
228 #ifdef HAVE_GNU_LD
230 /* Symbol set support macros. */
232 #ifdef HAVE_ELF
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)
241 /* These are all done the same way in ELF.
242 There is a new section created for each set. */
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##__ \
248 __attribute__ ((unused, section (#set))) = &(symbol)
249 #else
250 #define _elf_set_element(set, symbol) \
251 static const void *const __elf_set_##set##_element_##symbol##__ \
252 __attribute__ ((unused, section (#set))) = &(symbol)
253 #endif
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)
259 /* Declare SET for use in this module, if defined in another module. */
260 #define symbol_set_declare(set) \
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)
266 /* Return a pointer (void *const *) to the first element of SET. */
267 #define symbol_set_first_element(set) (&__start_##set)
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)
273 #else /* Not ELF: a.out. */
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];
283 #define symbol_set_first_element(set) &(set)[1]
284 #define symbol_set_end_p(set, ptr) (*(ptr) == 0)
286 #endif /* ELF. */
287 #endif /* Have GNU ld. */
289 #endif /* libc-symbols.h */