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