Correct return value.
[glibc/history.git] / libc-symbols.h
blob07a35f1b5311e349e1a3c737e3b0d6cca377723a
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. */
47 #define _LIBC 1
49 /* Enable declarations of GNU extensions, since we are compiling them. */
50 #define _GNU_SOURCE 1
51 /* And we also need the data for the reentrant functions. */
52 #define _REENTRANT 1
54 #include <config.h>
59 #ifndef ASSEMBLER
61 /* Define the macros `_' and `N_' for conveniently marking translatable
62 strings in the libc source code. */
64 #define N_(msgid) msgid
66 #include <libintl.h>
67 extern const char _libc_intl_domainname[];
69 #ifdef dgettext
70 /* This is defined as an optimizing macro, so use it. */
71 #define _(msgid) dgettext (_libc_intl_domainname, (msgid))
72 #else
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))
76 #endif
78 #endif
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
88 #endif
90 #ifndef __SYMBOL_PREFIX
91 #ifdef NO_UNDERSCORES
92 #define __SYMBOL_PREFIX
93 #else
94 #define __SYMBOL_PREFIX "_"
95 #endif
96 #endif
98 #ifndef C_SYMBOL_NAME
99 #ifdef NO_UNDERSCORES
100 #define C_SYMBOL_NAME(name) name
101 #else
102 #define C_SYMBOL_NAME(name) _##name
103 #endif
104 #endif
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)
114 #else
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);
118 #endif
119 #else
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)
125 #else
126 #define strong_alias(original, alias) \
127 asm (__string_1 (ASM_GLOBAL_DIRECTIVE) " " __SYMBOL_PREFIX #alias "\n" \
128 __SYMBOL_PREFIX #alias " = " __SYMBOL_PREFIX #original);
129 #endif
130 #endif
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 */
184 #else
185 #define weak_alias(original, alias) strong_alias(original, alias)
186 #define weak_extern(symbol) /* Do nothing; the ref will be strong. */
187 #endif
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. */
195 #undef strong_alias
196 #define strong_alias(name, aliasname) \
197 extern __typeof (name) aliasname __attribute__ ((alias (#name)));
199 #ifdef HAVE_WEAK_SYMBOLS
200 #undef weak_alias
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 */
220 #endif
223 /* When a reference to SYMBOL is encountered, the linker will emit a
224 warning message MSG. */
225 #ifdef HAVE_GNU_LD
226 #ifdef HAVE_ELF
228 /* We want the .gnu.warning.SYMBOL section to be unallocated. */
229 #ifdef HAVE_ASM_PREVIOUS_DIRECTIVE
230 #define __make_section_unallocated(section_string) \
231 asm(".section " section_string "; .previous");
232 #elif defined (HAVE_ASM_POPSECTION_DIRECTIVE)
233 #define __make_section_unallocated(section_string) \
234 asm(".pushsection " section_string "; .popsection");
235 #else
236 #define __make_section_unallocated(section_string)
237 #endif
239 #define link_warning(symbol, msg) \
240 __make_section_unallocated (".gnu.warning." #symbol) \
241 static const char __evoke_link_warning_##symbol[] \
242 __attribute__ ((section (".gnu.warning." #symbol))) = msg;
243 #else
244 #define link_warning(symbol, msg) \
245 asm(".stabs \"" msg "\",30,0,0,0\n" \
246 ".stabs \"" __SYMBOL_PREFIX #symbol "\",1,0,0,0\n");
247 #endif
248 #else
249 /* We will never be heard; they will all die horribly. */
250 #define link_warning(symbol, msg)
251 #endif
253 /* A canned warning for sysdeps/stub functions. */
254 #define stub_warning(name) \
255 link_warning (name, \
256 "warning: " #name " is not implemented and will always fail")
262 #ifdef HAVE_GNU_LD
264 /* Symbol set support macros. */
266 #ifdef HAVE_ELF
268 /* Make SYMBOL, which is in the text segment, an element of SET. */
269 #define text_set_element(set, symbol) _elf_set_element(set, symbol)
270 /* Make SYMBOL, which is in the data segment, an element of SET. */
271 #define data_set_element(set, symbol) _elf_set_element(set, symbol)
272 /* Make SYMBOL, which is in the bss segment, an element of SET. */
273 #define bss_set_element(set, symbol) _elf_set_element(set, symbol)
275 /* These are all done the same way in ELF.
276 There is a new section created for each set. */
277 #ifdef PIC
278 /* When building a shared library, make the set section writable,
279 because it will need to be relocated at run time anyway. */
280 #define _elf_set_element(set, symbol) \
281 static const void *__elf_set_##set##_element_##symbol##__ \
282 __attribute__ ((unused, section (#set))) = &(symbol)
283 #else
284 #define _elf_set_element(set, symbol) \
285 static const void *const __elf_set_##set##_element_##symbol##__ \
286 __attribute__ ((unused, section (#set))) = &(symbol)
287 #endif
289 /* Define SET as a symbol set. This may be required (it is in a.out) to
290 be able to use the set's contents. */
291 #define symbol_set_define(set) symbol_set_declare(set)
293 /* Declare SET for use in this module, if defined in another module. */
294 #define symbol_set_declare(set) \
295 extern void *const __start_##set __attribute__ ((__weak__)); \
296 extern void *const __stop_##set __attribute__ ((__weak__)); \
297 weak_extern (__start_##set) weak_extern (__stop_##set)
299 /* Return a pointer (void *const *) to the first element of SET. */
300 #define symbol_set_first_element(set) (&__start_##set)
302 /* Return true iff PTR (a void *const *) has been incremented
303 past the last element in SET. */
304 #define symbol_set_end_p(set, ptr) ((ptr) >= &__stop_##set)
306 #else /* Not ELF: a.out. */
308 #define text_set_element(set, symbol) \
309 asm(".stabs \"" __SYMBOL_PREFIX #set "\",23,0,0," __SYMBOL_PREFIX #symbol)
310 #define data_set_element(set, symbol) \
311 asm(".stabs \"" __SYMBOL_PREFIX #set "\",25,0,0," __SYMBOL_PREFIX #symbol)
312 #define bss_set_element(set, symbol) ?error Must use initialized data.
313 #define symbol_set_define(set) void *const (set)[1];
314 #define symbol_set_declare(set) extern void *const (set)[1];
316 #define symbol_set_first_element(set) &(set)[1]
317 #define symbol_set_end_p(set, ptr) (*(ptr) == 0)
319 #endif /* ELF. */
320 #endif /* Have GNU ld. */
322 #endif /* libc-symbols.h */