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 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)
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)
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
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 /* When a reference to SYMBOL is encountered, the linker will emit a
230 warning message MSG. */
234 /* We want the .gnu.warning.SYMBOL section to be unallocated. */
235 # ifdef HAVE_ASM_PREVIOUS_DIRECTIVE
236 # define __make_section_unallocated(section_string) \
237 asm(".section " section_string "; .previous");
238 # elif defined (HAVE_ASM_POPSECTION_DIRECTIVE)
239 # define __make_section_unallocated(section_string) \
240 asm(".pushsection " section_string "; .popsection");
242 # define __make_section_unallocated(section_string)
245 # define link_warning(symbol, msg) \
246 __make_section_unallocated (".gnu.warning." #symbol) \
247 static const char __evoke_link_warning_##symbol[] \
248 __attribute__ ((section (".gnu.warning." #symbol))) = msg;
250 # define link_warning(symbol, msg) \
251 asm(".stabs \"" msg "\",30,0,0,0\n" \
252 ".stabs \"" __SYMBOL_PREFIX #symbol "\",1,0,0,0\n");
255 /* We will never be heard; they will all die horribly. */
256 # define link_warning(symbol, msg)
259 /* A canned warning for sysdeps/stub functions. */
260 #define stub_warning(name) \
261 link_warning (name, \
262 "warning: " #name " is not implemented and will always fail")
270 /* Symbol set support macros. */
274 /* Make SYMBOL, which is in the text segment, an element of SET. */
275 # define text_set_element(set, symbol) _elf_set_element(set, symbol)
276 /* Make SYMBOL, which is in the data segment, an element of SET. */
277 # define data_set_element(set, symbol) _elf_set_element(set, symbol)
278 /* Make SYMBOL, which is in the bss segment, an element of SET. */
279 # define bss_set_element(set, symbol) _elf_set_element(set, symbol)
281 /* These are all done the same way in ELF.
282 There is a new section created for each set. */
284 /* When building a shared library, make the set section writable,
285 because it will need to be relocated at run time anyway. */
286 # define _elf_set_element(set, symbol) \
287 static const void *__elf_set_##set##_element_##symbol##__ \
288 __attribute__ ((unused, section (#set))) = &(symbol)
290 # define _elf_set_element(set, symbol) \
291 static const void *const __elf_set_##set##_element_##symbol##__ \
292 __attribute__ ((unused, section (#set))) = &(symbol)
295 /* Define SET as a symbol set. This may be required (it is in a.out) to
296 be able to use the set's contents. */
297 # define symbol_set_define(set) symbol_set_declare(set)
299 /* Declare SET for use in this module, if defined in another module. */
300 # define symbol_set_declare(set) \
301 extern void *const __start_##set __attribute__ ((__weak__)); \
302 extern void *const __stop_##set __attribute__ ((__weak__)); \
303 weak_extern (__start_##set) weak_extern (__stop_##set)
305 /* Return a pointer (void *const *) to the first element of SET. */
306 # define symbol_set_first_element(set) (&__start_##set)
308 /* Return true iff PTR (a void *const *) has been incremented
309 past the last element in SET. */
310 # define symbol_set_end_p(set, ptr) ((ptr) >= &__stop_##set)
312 # else /* Not ELF: a.out. */
314 # define text_set_element(set, symbol) \
315 asm(".stabs \"" __SYMBOL_PREFIX #set "\",23,0,0," __SYMBOL_PREFIX #symbol)
316 # define data_set_element(set, symbol) \
317 asm(".stabs \"" __SYMBOL_PREFIX #set "\",25,0,0," __SYMBOL_PREFIX #symbol)
318 # define bss_set_element(set, symbol) ?error Must use initialized data.
319 # define symbol_set_define(set) void *const (set)[1];
320 # define symbol_set_declare(set) extern void *const (set)[1];
322 # define symbol_set_first_element(set) &(set)[1]
323 # define symbol_set_end_p(set, ptr) (*(ptr) == 0)
326 #endif /* Have GNU ld. */
329 # define symbol_version(real, name, version) \
330 __asm__ (".symver " #real "," #name "@" #version)
331 # define default_symbol_version(real, name, version) \
332 __asm__ (".symver " #real "," #name "@@" #version)
334 # define symbol_version(real, name, version)
335 # define default_symbol_version(real, name, version)
338 #endif /* libc-symbols.h */