(NEED_INETADDR, NEED_INETATON): Define to 1, not empty.
[glibc.git] / libc-symbols.h
blob8030abb08956d294548101d5477f58113e8f4f0c
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 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.
40 #include <config.h>
42 /* This is defined for the compilation of all C library code.
43 features.h tests this to avoid inclusion of stubs.h while
44 compiling the library, before stubs.h has been generated.
45 Some library code that is shared with other packages also
46 tests this symbol to see if it is being compiled as part
47 of the C library. */
48 #define _LIBC
50 /* The symbols in all the user (non-_) macros are C symbols. Predefined
51 should be HAVE_WEAK_SYMBOLS and/or HAVE_ELF and/or HAVE_GNU_LD.
52 HAVE_WEAK_SYMBOLS is implied by the other two. HAVE_GNU_LD without
53 HAVE_ELF implies a.out. */
55 #ifndef HAVE_WEAK_SYMBOLS
56 #if defined (HAVE_ELF) || defined (HAVE_GNU_LD)
57 #define HAVE_WEAK_SYMBOLS
58 #endif
59 #endif
61 #ifndef __SYMBOL_PREFIX
62 #ifdef HAVE_ELF
63 #define NO_UNDERSCORES
64 #else
65 #include <sysdep.h> /* Should define NO_UNDERSCORES. */
66 #endif
67 #ifdef NO_UNDERSCORES
68 #define __SYMBOL_PREFIX
69 #else
70 #define __SYMBOL_PREFIX "_"
71 #endif
72 #endif
74 #ifndef C_SYMBOL_NAME
75 #ifdef NO_UNDERSCORES
76 #define C_SYMBOL_NAME(name) name
77 #else
78 #define C_SYMBOL_NAME(name) _##name
79 #endif
80 #endif
83 /* Define ALIAS as a strong alias for ORIGINAL. */
84 #ifdef HAVE_ASM_SET_DIRECTIVE
85 #define strong_alias_asm(original, alias) \
86 ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME (alias); \
87 .set C_SYMBOL_NAME (alias),C_SYMBOL_NAME (original)
88 #ifdef ASSEMBLER
89 #define strong_alias(original, alias) strong_alias_asm (original, alias)
90 #else
91 #define strong_alias(original, alias) \
92 asm (__string_1 (ASM_GLOBAL_DIRECTIVE) " " __SYMBOL_PREFIX #alias "\n" \
93 ".set " __SYMBOL_PREFIX #alias "," __SYMBOL_PREFIX #original);
94 #endif
95 #else
96 #define strong_alias_asm(original, alias) \
97 ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME (alias); \
98 C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original)
99 #ifdef ASSEMBLER
100 #define strong_alias(original, alias) strong_alias_asm (original, alias)
101 #else
102 #define strong_alias(original, alias) \
103 asm (__string_1 (ASM_GLOBAL_DIRECTIVE) " " __SYMBOL_PREFIX #alias "\n" \
104 __SYMBOL_PREFIX #alias " = " __SYMBOL_PREFIX #original);
105 #endif
106 #endif
108 /* Helper macros used above. */
109 #define __string_1(x) __string_0(x)
110 #define __string_0(x) #x
113 #ifdef HAVE_WEAK_SYMBOLS
114 #ifdef ASSEMBLER
116 /* Define ALIAS as a weak alias for ORIGINAL.
117 If weak aliases are not available, this defines a strong alias. */
118 #define weak_alias(original, alias) \
119 .weak C_SYMBOL_NAME (alias); \
120 C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original)
122 /* Declare SYMBOL to be weak. */
123 #define weak_symbol(symbol) .weak C_SYMBOL_NAME (symbol)
125 #else
126 #define weak_symbol(symbol) asm (".weak " __SYMBOL_PREFIX #symbol);
127 #define weak_alias(original, alias) \
128 asm (".weak " __SYMBOL_PREFIX #alias "\n" \
129 __SYMBOL_PREFIX #alias " = " __SYMBOL_PREFIX #original);
130 #endif
131 #else
132 #define weak_alias(original, alias) strong_alias(original, alias)
133 #define weak_symbol(symbol) /* Do nothing. */
134 #endif
137 #if (!defined (ASSEMBLER) && \
138 (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)))
139 /* GCC 2.7 and later has special syntax for weak symbols and aliases.
140 Using that is better when possible, because the compiler and assembler
141 are better clued in to what we are doing. */
142 #undef strong_alias
143 #define strong_alias(name, aliasname) \
144 extern __typeof (name) aliasname __attribute__ ((alias (#name)));
146 #ifdef HAVE_WEAK_SYMBOLS
147 #undef weak_symbol
148 #define weak_symbol(name) \
149 extern __typeof (name) name __attribute__ ((weak));
150 #undef weak_alias
151 #define weak_alias(name, aliasname) \
152 extern __typeof (name) aliasname __attribute__ ((weak, alias (#name)));
153 #endif /* HAVE_WEAK_SYMBOLS. */
154 #endif /* Not ASSEMBLER, and GCC 2.7 or later. */
158 /* When a reference to SYMBOL is encountered, the linker will emit a
159 warning message MSG. */
160 #ifdef HAVE_GNU_LD
161 #ifdef HAVE_ELF
162 #define link_warning(symbol, msg) \
163 static const char __evoke_link_warning_##symbol[] \
164 __attribute__ ((section (".gnu.warning." #symbol))) = msg;
165 #else
166 #define link_warning(symbol, msg) \
167 asm(".stabs \"" msg "\",30,0,0,0\n" \
168 ".stabs \"" __SYMBOL_PREFIX #symbol "\",1,0,0,0\n");
169 #endif
170 #else
171 /* We will never be heard; they will all die horribly. */
172 #define link_warning(symbol, msg)
173 #endif
175 /* A canned warning for sysdeps/stub functions. */
176 #define stub_warning(name) \
177 link_warning (name, \
178 "warning: " #name " is not implemented and will always fail")
184 #ifdef HAVE_GNU_LD
186 /* Symbol set support macros. */
188 #ifdef HAVE_ELF
190 /* Make SYMBOL, which is in the text segment, an element of SET. */
191 #define text_set_element(set, symbol) _elf_set_element(set, symbol)
192 /* Make SYMBOL, which is in the data segment, an element of SET. */
193 #define data_set_element(set, symbol) _elf_set_element(set, symbol)
194 /* Make SYMBOL, which is in the bss segment, an element of SET. */
195 #define bss_set_element(set, symbol) _elf_set_element(set, symbol)
197 /* These are all done the same way in ELF.
198 There is a new section created for each set. */
199 #ifdef PIC
200 /* When building a shared library, make the set section writable,
201 because it will need to be relocated at run time anyway. */
202 #define _elf_set_element(set, symbol) \
203 static const void *__elf_set_##set##_element_##symbol##__ \
204 __attribute__ ((unused, section (#set))) = &(symbol)
205 #else
206 #define _elf_set_element(set, symbol) \
207 static const void *const __elf_set_##set##_element_##symbol##__ \
208 __attribute__ ((unused, section (#set))) = &(symbol)
209 #endif
211 /* Define SET as a symbol set. This may be required (it is in a.out) to
212 be able to use the set's contents. */
213 #define symbol_set_define(set) symbol_set_declare(set)
215 /* Declare SET for use in this module, if defined in another module. */
216 #define symbol_set_declare(set) \
217 extern void *const __start_##set, *const __stop_##set;
219 /* Return a pointer (void *const *) to the first element of SET. */
220 #define symbol_set_first_element(set) (&__start_##set)
222 /* Return true iff PTR (a void *const *) has been incremented
223 past the last element in SET. */
224 #define symbol_set_end_p(set, ptr) ((ptr) >= &__stop_##set)
226 #else /* Not ELF: a.out. */
228 #define text_set_element(set, symbol) \
229 asm(".stabs \"" __SYMBOL_PREFIX #set "\",23,0,0," __SYMBOL_PREFIX #symbol)
230 #define data_set_element(set, symbol) \
231 asm(".stabs \"" __SYMBOL_PREFIX #set "\",25,0,0," __SYMBOL_PREFIX #symbol)
232 #define bss_set_element(set, symbol) ?error Must use initialized data.
233 #define symbol_set_define(set) void *const (set)[1];
234 #define symbol_set_declare(set) extern void *const (set)[1];
236 #define symbol_set_first_element(set) &(set)[1]
237 #define symbol_set_end_p(set, ptr) (*(ptr) == 0)
239 #endif /* ELF. */
240 #endif /* Have GNU ld. */
242 #endif /* libc-symbols.h */