(__select): Don't fault when some fdmask is 0.
[glibc.git] / libc-symbols.h
blobf211f48675887724d5a0f9f01a2612ad1be2d0a2
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_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.
36 * HAVE_WEAK_SYMBOLS if weak symbols are available in the assembler and
37 linker being used. Set by --with-weak-symbols.
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. */
48 #define _LIBC 1
50 #include <config.h>
55 #ifndef ASSEMBLER
57 /* Define the macros `_' and `N_' for conveniently marking translatable
58 strings in the libc source code. */
60 #define N_(msgid) msgid
62 #include <libintl.h>
63 extern const char _libc_intl_domainname[];
65 #ifdef dgettext
66 /* This is defined as an optimizing macro, so use it. */
67 #define _(msgid) dgettext (_libc_intl_domainname, (msgid))
68 #else
69 /* Be sure to use only the __ name when `dgettext' is a plain function
70 instead of an optimizing macro. */
71 #define _(msgid) __dgettext (_libc_intl_domainname, (msgid))
72 #endif
74 #endif
79 /* The symbols in all the user (non-_) macros are C symbols. Predefined
80 should be HAVE_WEAK_SYMBOLS and/or HAVE_ELF and/or HAVE_GNU_LD.
81 HAVE_WEAK_SYMBOLS is implied by the other two. HAVE_GNU_LD without
82 HAVE_ELF implies a.out. */
84 #ifndef HAVE_WEAK_SYMBOLS
85 #if defined (HAVE_ELF) || defined (HAVE_GNU_LD)
86 #define HAVE_WEAK_SYMBOLS
87 #endif
88 #endif
90 #ifndef __SYMBOL_PREFIX
91 #ifdef HAVE_ELF
92 #define NO_UNDERSCORES
93 #else
94 #include <sysdep.h> /* Should define NO_UNDERSCORES. */
95 #endif
96 #ifdef NO_UNDERSCORES
97 #define __SYMBOL_PREFIX
98 #else
99 #define __SYMBOL_PREFIX "_"
100 #endif
101 #endif
103 #ifndef C_SYMBOL_NAME
104 #ifdef NO_UNDERSCORES
105 #define C_SYMBOL_NAME(name) name
106 #else
107 #define C_SYMBOL_NAME(name) _##name
108 #endif
109 #endif
112 /* Define ALIAS as a strong alias for ORIGINAL. */
113 #ifdef HAVE_ASM_SET_DIRECTIVE
114 #define strong_alias_asm(original, alias) \
115 ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME (alias); \
116 .set C_SYMBOL_NAME (alias),C_SYMBOL_NAME (original)
117 #ifdef ASSEMBLER
118 #define strong_alias(original, alias) strong_alias_asm (original, alias)
119 #else
120 #define strong_alias(original, alias) \
121 asm (__string_1 (ASM_GLOBAL_DIRECTIVE) " " __SYMBOL_PREFIX #alias "\n" \
122 ".set " __SYMBOL_PREFIX #alias "," __SYMBOL_PREFIX #original);
123 #endif
124 #else
125 #define strong_alias_asm(original, alias) \
126 ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME (alias); \
127 C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original)
128 #ifdef ASSEMBLER
129 #define strong_alias(original, alias) strong_alias_asm (original, alias)
130 #else
131 #define strong_alias(original, alias) \
132 asm (__string_1 (ASM_GLOBAL_DIRECTIVE) " " __SYMBOL_PREFIX #alias "\n" \
133 __SYMBOL_PREFIX #alias " = " __SYMBOL_PREFIX #original);
134 #endif
135 #endif
137 /* Helper macros used above. */
138 #define __string_1(x) __string_0(x)
139 #define __string_0(x) #x
142 #ifdef HAVE_WEAK_SYMBOLS
143 #ifdef ASSEMBLER
145 /* Define ALIAS as a weak alias for ORIGINAL.
146 If weak aliases are not available, this defines a strong alias. */
147 #define weak_alias(original, alias) \
148 .weak C_SYMBOL_NAME (alias); \
149 C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original)
151 /* Declare SYMBOL to be weak. */
152 #define weak_symbol(symbol) .weak C_SYMBOL_NAME (symbol)
154 #else
155 #define weak_symbol(symbol) asm (".weak " __SYMBOL_PREFIX #symbol);
156 #define weak_alias(original, alias) \
157 asm (".weak " __SYMBOL_PREFIX #alias "\n" \
158 __SYMBOL_PREFIX #alias " = " __SYMBOL_PREFIX #original);
159 #endif
160 #else
161 #define weak_alias(original, alias) strong_alias(original, alias)
162 #define weak_symbol(symbol) /* Do nothing. */
163 #endif
166 #if (!defined (ASSEMBLER) && \
167 (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8)))
168 /* GCC 2.8 and later has special syntax for weak symbols and aliases.
169 Using that is better when possible, because the compiler and assembler
170 are better clued in to what we are doing. */
171 #undef strong_alias
172 #define strong_alias(name, aliasname) \
173 __typeof (name) aliasname __attribute__ ((alias (#name)));
175 #ifdef HAVE_WEAK_SYMBOLS
176 #undef weak_symbol
177 #define weak_symbol(name) \
178 extern __typeof (name) name __attribute__ ((weak));
179 #undef weak_alias
180 #define weak_alias(name, aliasname) \
181 __typeof (name) aliasname __attribute__ ((weak, alias (#name)));
182 #endif /* HAVE_WEAK_SYMBOLS. */
183 #endif /* Not ASSEMBLER, and GCC 2.8 or later. */
187 /* When a reference to SYMBOL is encountered, the linker will emit a
188 warning message MSG. */
189 #ifdef HAVE_GNU_LD
190 #ifdef HAVE_ELF
191 #define link_warning(symbol, msg) \
192 static const char __evoke_link_warning_##symbol[] \
193 __attribute__ ((section (".gnu.warning." #symbol))) = msg;
194 #else
195 #define link_warning(symbol, msg) \
196 asm(".stabs \"" msg "\",30,0,0,0\n" \
197 ".stabs \"" __SYMBOL_PREFIX #symbol "\",1,0,0,0\n");
198 #endif
199 #else
200 /* We will never be heard; they will all die horribly. */
201 #define link_warning(symbol, msg)
202 #endif
204 /* A canned warning for sysdeps/stub functions. */
205 #define stub_warning(name) \
206 link_warning (name, \
207 "warning: " #name " is not implemented and will always fail")
213 #ifdef HAVE_GNU_LD
215 /* Symbol set support macros. */
217 #ifdef HAVE_ELF
219 /* Make SYMBOL, which is in the text segment, an element of SET. */
220 #define text_set_element(set, symbol) _elf_set_element(set, symbol)
221 /* Make SYMBOL, which is in the data segment, an element of SET. */
222 #define data_set_element(set, symbol) _elf_set_element(set, symbol)
223 /* Make SYMBOL, which is in the bss segment, an element of SET. */
224 #define bss_set_element(set, symbol) _elf_set_element(set, symbol)
226 /* These are all done the same way in ELF.
227 There is a new section created for each set. */
228 #ifdef PIC
229 /* When building a shared library, make the set section writable,
230 because it will need to be relocated at run time anyway. */
231 #define _elf_set_element(set, symbol) \
232 static const void *__elf_set_##set##_element_##symbol##__ \
233 __attribute__ ((unused, section (#set))) = &(symbol)
234 #else
235 #define _elf_set_element(set, symbol) \
236 static const void *const __elf_set_##set##_element_##symbol##__ \
237 __attribute__ ((unused, section (#set))) = &(symbol)
238 #endif
240 /* Define SET as a symbol set. This may be required (it is in a.out) to
241 be able to use the set's contents. */
242 #define symbol_set_define(set) symbol_set_declare(set)
244 /* Declare SET for use in this module, if defined in another module. */
245 #define symbol_set_declare(set) \
246 extern void *const __start_##set __attribute__ ((__weak__)); \
247 extern void *const __stop_##set __attribute__ ((__weak__)); \
248 /* Gratuitously repeat weak decl, in case using broken GCC (<2.8). */\
249 weak_symbol (__start_##set) weak_symbol (__stop_##set)
251 /* Return a pointer (void *const *) to the first element of SET. */
252 #define symbol_set_first_element(set) (&__start_##set)
254 /* Return true iff PTR (a void *const *) has been incremented
255 past the last element in SET. */
256 #define symbol_set_end_p(set, ptr) ((ptr) >= &__stop_##set)
258 #else /* Not ELF: a.out. */
260 #define text_set_element(set, symbol) \
261 asm(".stabs \"" __SYMBOL_PREFIX #set "\",23,0,0," __SYMBOL_PREFIX #symbol)
262 #define data_set_element(set, symbol) \
263 asm(".stabs \"" __SYMBOL_PREFIX #set "\",25,0,0," __SYMBOL_PREFIX #symbol)
264 #define bss_set_element(set, symbol) ?error Must use initialized data.
265 #define symbol_set_define(set) void *const (set)[1];
266 #define symbol_set_declare(set) extern void *const (set)[1];
268 #define symbol_set_first_element(set) &(set)[1]
269 #define symbol_set_end_p(set, ptr) (*(ptr) == 0)
271 #endif /* ELF. */
272 #endif /* Have GNU ld. */
274 #endif /* libc-symbols.h */