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 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 not,
18 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 #ifndef _LIBC_SYMBOLS_H
22 #define _LIBC_SYMBOLS_H 1
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. */
49 /* Enable declarations of GNU extensions, since we are compiling them. */
51 /* And we also need the data for the reentrant functions. */
61 /* Define the macros `_' and `N_' for conveniently marking translatable
62 strings in the libc source code. */
64 # define N_(msgid) msgid
67 extern const char _libc_intl_domainname
[];
70 /* This is defined as an optimizing macro, so use it. */
71 # define _(msgid) dgettext (_libc_intl_domainname, (msgid))
73 /* Be sure to use only the __ name when `dgettext' is a plain function
74 instead of an optimizing macro. */
75 # define _(msgid) __dgettext (_libc_intl_domainname, (msgid))
83 /* The symbols in all the user (non-_) macros are C symbols.
84 HAVE_GNU_LD without HAVE_ELF implies a.out. */
86 #if defined HAVE_ASM_WEAK_DIRECTIVE || defined HAVE_ASM_WEAKEXT_DIRECTIVE
87 # define HAVE_WEAK_SYMBOLS
90 #ifndef __SYMBOL_PREFIX
91 # ifdef NO_UNDERSCORES
92 # define __SYMBOL_PREFIX
94 # define __SYMBOL_PREFIX "_"
99 # ifdef NO_UNDERSCORES
100 # define C_SYMBOL_NAME(name) name
102 # define C_SYMBOL_NAME(name) _##name
107 /* Define ALIAS as a strong alias for ORIGINAL. */
108 #ifdef HAVE_ASM_SET_DIRECTIVE
109 # define strong_alias_asm(original, alias) \
110 ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME (alias); \
111 .set C_SYMBOL_NAME (alias),C_SYMBOL_NAME (original)
112 # ifdef __ASSEMBLER__
113 # define strong_alias(original, alias) strong_alias_asm (original, alias)
115 # define strong_alias(original, alias) \
116 asm (__string_1 (ASM_GLOBAL_DIRECTIVE) " " __SYMBOL_PREFIX #alias "\n" \
117 ".set " __SYMBOL_PREFIX #alias "," __SYMBOL_PREFIX #original);
120 # define strong_alias_asm(original, alias) \
121 ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME (alias); \
122 C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original)
123 # ifdef __ASSEMBLER__
124 # define strong_alias(original, alias) strong_alias_asm (original, alias)
126 # define strong_alias(original, alias) \
127 asm (__string_1 (ASM_GLOBAL_DIRECTIVE) " " __SYMBOL_PREFIX #alias "\n" \
128 __SYMBOL_PREFIX #alias " = " __SYMBOL_PREFIX #original);
132 /* Helper macros used above. */
133 #define __string_1(x) __string_0(x)
134 #define __string_0(x) #x
137 #ifdef HAVE_WEAK_SYMBOLS
139 # ifdef __ASSEMBLER__
141 # ifdef HAVE_ASM_WEAKEXT_DIRECTIVE
143 /* Define ALIAS as a weak alias for ORIGINAL.
144 If weak aliases are not available, this defines a strong alias. */
145 # define weak_alias(original, alias) \
146 .weakext C_SYMBOL_NAME (alias), C_SYMBOL_NAME (original)
148 /* Declare SYMBOL as weak undefined symbol (resolved to 0 if not defined). */
149 # define weak_extern(symbol) \
150 .weakext C_SYMBOL_NAME (symbol)
152 # else /* ! HAVE_ASM_WEAKEXT_DIRECTIVE */
154 /* Define ALIAS as a weak alias for ORIGINAL.
155 If weak aliases are not available, this defines a strong alias. */
156 # define weak_alias(original, alias) \
157 .weak C_SYMBOL_NAME (alias); \
158 C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original)
161 /* Declare SYMBOL as weak undefined symbol (resolved to 0 if not defined). */
162 # define weak_extern(symbol) \
163 .weak C_SYMBOL_NAME (symbol)
165 # endif /* ! HAVE_ASM_WEAKEXT_DIRECTIVE */
167 # else /* ! __ASSEMBLER__ */
169 # ifdef HAVE_ASM_WEAKEXT_DIRECTIVE
170 # define weak_extern_asm(symbol) asm (".weakext " __SYMBOL_PREFIX #symbol);
171 # define weak_alias_asm(original, alias) \
172 asm (".weakext " __SYMBOL_PREFIX #alias ", " __SYMBOL_PREFIX #original);
173 # else /* ! HAVE_ASM_WEAKEXT_DIRECTIVE */
174 # define weak_extern_asm(symbol) asm (".weak " __SYMBOL_PREFIX #symbol);
175 # define weak_alias_asm(original, alias) \
176 asm (".weak " __SYMBOL_PREFIX #alias "\n" \
177 __SYMBOL_PREFIX #alias " = " __SYMBOL_PREFIX #original);
178 # endif /* ! HAVE_ASM_WEAKEXT_DIRECTIVE */
180 # define weak_alias(o, a) weak_alias_asm (o, a)
181 # define weak_extern(symbol) weak_extern_asm (symbol)
183 # endif /* ! __ASSEMBLER__ */
185 # define weak_alias(original, alias) strong_alias(original, alias)
186 # define weak_extern(symbol) /* Do nothing; the ref will be strong. */
190 #if (!defined __ASSEMBLER__ && \
191 (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)))
192 /* GCC 2.7 and later has special syntax for weak symbols and aliases.
193 Using that is better when possible, because the compiler and assembler
194 are better clued in to what we are doing. */
196 # define strong_alias(name, aliasname) \
197 extern __typeof (name) aliasname __attribute__ ((alias (#name)));
199 # ifdef HAVE_WEAK_SYMBOLS
201 # define weak_alias(name, aliasname) \
202 extern __typeof (name) aliasname __attribute__ ((weak, alias (#name)));
204 /* This comes between the return type and function name in
205 a function definition to make that definition weak. */
206 # define weak_function __attribute__ ((weak))
207 # define weak_const_function __attribute__ ((weak, __const__))
209 # endif /* HAVE_WEAK_SYMBOLS. */
210 #endif /* Not __ASSEMBLER__, and GCC 2.7 or later. */
213 #ifndef weak_function
214 /* If we do not have the __attribute__ ((weak)) syntax, there is no way we
215 can define functions as weak symbols. The compiler will emit a `.globl'
216 directive for the function symbol, and a `.weak' directive in addition
217 will produce an error from the assembler. */
218 # define weak_function /* empty */
219 # define weak_const_function /* empty */
222 /* On some platforms we can make internal function calls (i.e., calls of
223 functions not exported) a bit faster by using a different calling
225 #ifndef internal_function
226 # define internal_function /* empty */
229 /* Prepare for the case that `__builtin_expect' is not available. */
230 #ifndef HAVE_BUILTIN_EXPECT
231 # define __builtin_expect(expr, val) (expr)
234 /* When a reference to SYMBOL is encountered, the linker will emit a
235 warning message MSG. */
239 /* We want the .gnu.warning.SYMBOL section to be unallocated. */
240 # ifdef HAVE_ASM_PREVIOUS_DIRECTIVE
241 # define __make_section_unallocated(section_string) \
242 asm(".section " section_string "; .previous");
243 # elif defined (HAVE_ASM_POPSECTION_DIRECTIVE)
244 # define __make_section_unallocated(section_string) \
245 asm(".pushsection " section_string "; .popsection");
247 # define __make_section_unallocated(section_string)
250 # define link_warning(symbol, msg) \
251 __make_section_unallocated (".gnu.warning." #symbol) \
252 static const char __evoke_link_warning_##symbol[] \
253 __attribute__ ((section (".gnu.warning." #symbol))) = msg;
255 # define link_warning(symbol, msg) \
256 asm(".stabs \"" msg "\",30,0,0,0\n" \
257 ".stabs \"" __SYMBOL_PREFIX #symbol "\",1,0,0,0\n");
260 /* We will never be heard; they will all die horribly. */
261 # define link_warning(symbol, msg)
264 /* A canned warning for sysdeps/stub functions. */
265 #define stub_warning(name) \
266 link_warning (name, \
267 "warning: " #name " is not implemented and will always fail")
275 /* Symbol set support macros. */
279 /* Make SYMBOL, which is in the text segment, an element of SET. */
280 # define text_set_element(set, symbol) _elf_set_element(set, symbol)
281 /* Make SYMBOL, which is in the data segment, an element of SET. */
282 # define data_set_element(set, symbol) _elf_set_element(set, symbol)
283 /* Make SYMBOL, which is in the bss segment, an element of SET. */
284 # define bss_set_element(set, symbol) _elf_set_element(set, symbol)
286 /* These are all done the same way in ELF.
287 There is a new section created for each set. */
289 /* When building a shared library, make the set section writable,
290 because it will need to be relocated at run time anyway. */
291 # define _elf_set_element(set, symbol) \
292 static const void *__elf_set_##set##_element_##symbol##__ \
293 __attribute__ ((unused, section (#set))) = &(symbol)
295 # define _elf_set_element(set, symbol) \
296 static const void *const __elf_set_##set##_element_##symbol##__ \
297 __attribute__ ((unused, section (#set))) = &(symbol)
300 /* Define SET as a symbol set. This may be required (it is in a.out) to
301 be able to use the set's contents. */
302 # define symbol_set_define(set) symbol_set_declare(set)
304 /* Declare SET for use in this module, if defined in another module. */
305 # define symbol_set_declare(set) \
306 extern void *const __start_##set __attribute__ ((__weak__)); \
307 extern void *const __stop_##set __attribute__ ((__weak__)); \
308 weak_extern (__start_##set) weak_extern (__stop_##set)
310 /* Return a pointer (void *const *) to the first element of SET. */
311 # define symbol_set_first_element(set) (&__start_##set)
313 /* Return true iff PTR (a void *const *) has been incremented
314 past the last element in SET. */
315 # define symbol_set_end_p(set, ptr) ((ptr) >= &__stop_##set)
317 # else /* Not ELF: a.out. */
319 # define text_set_element(set, symbol) \
320 asm(".stabs \"" __SYMBOL_PREFIX #set "\",23,0,0," __SYMBOL_PREFIX #symbol)
321 # define data_set_element(set, symbol) \
322 asm(".stabs \"" __SYMBOL_PREFIX #set "\",25,0,0," __SYMBOL_PREFIX #symbol)
323 # define bss_set_element(set, symbol) ?error Must use initialized data.
324 # define symbol_set_define(set) void *const (set)[1];
325 # define symbol_set_declare(set) extern void *const (set)[1];
327 # define symbol_set_first_element(set) &(set)[1]
328 # define symbol_set_end_p(set, ptr) (*(ptr) == 0)
331 #endif /* Have GNU ld. */
334 # ifdef __ASSEMBLER__
335 # define symbol_version(real, name, version) \
336 .symver real, name##@##version
337 # define default_symbol_version(real, name, version) \
338 .symver real, name##@##@##version
340 # define symbol_version(real, name, version) \
341 __asm__ (".symver " #real "," #name "@" #version)
342 # define default_symbol_version(real, name, version) \
343 __asm__ (".symver " #real "," #name "@@" #version)
346 # define symbol_version(real, name, version)
347 # define default_symbol_version(real, name, version) \
348 strong_alias(real, name)
351 #endif /* libc-symbols.h */