(argz_create): Fix param type.
[glibc.git] / libc-symbols.h
blob7405e6708662c8c98f1bd6fed8cf43412a479ae0
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_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
52 #include <config.h>
54 /* This disables sccsid/rcsid strings in lots of code of non-GNU origin. */
55 #define lint 1
60 #ifndef ASSEMBLER
62 /* Define the macros `_' and `N_' for conveniently marking translatable
63 strings in the libc source code. */
65 #define N_(msgid) msgid
67 #include <libintl.h>
68 extern const char _libc_intl_domainname[];
70 #ifdef dgettext
71 /* This is defined as an optimizing macro, so use it. */
72 #define _(msgid) dgettext (_libc_intl_domainname, (msgid))
73 #else
74 /* Be sure to use only the __ name when `dgettext' is a plain function
75 instead of an optimizing macro. */
76 #define _(msgid) __dgettext (_libc_intl_domainname, (msgid))
77 #endif
79 #endif
84 /* The symbols in all the user (non-_) macros are C symbols.
85 HAVE_GNU_LD without HAVE_ELF implies a.out. */
87 #if defined (HAVE_ASM_WEAK_DIRECTIVE) || defined (HAVE_ASM_WEAKEXT_DIRECTIVE)
88 #define HAVE_WEAK_SYMBOLS
89 #endif
91 #ifndef __SYMBOL_PREFIX
92 #ifdef NO_UNDERSCORES
93 #define __SYMBOL_PREFIX
94 #else
95 #define __SYMBOL_PREFIX "_"
96 #endif
97 #endif
99 #ifndef C_SYMBOL_NAME
100 #ifdef NO_UNDERSCORES
101 #define C_SYMBOL_NAME(name) name
102 #else
103 #define C_SYMBOL_NAME(name) _##name
104 #endif
105 #endif
108 /* Define ALIAS as a strong alias for ORIGINAL. */
109 #ifdef HAVE_ASM_SET_DIRECTIVE
110 #define strong_alias_asm(original, alias) \
111 ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME (alias); \
112 .set C_SYMBOL_NAME (alias),C_SYMBOL_NAME (original)
113 #ifdef ASSEMBLER
114 #define strong_alias(original, alias) strong_alias_asm (original, alias)
115 #else
116 #define strong_alias(original, alias) \
117 asm (__string_1 (ASM_GLOBAL_DIRECTIVE) " " __SYMBOL_PREFIX #alias "\n" \
118 ".set " __SYMBOL_PREFIX #alias "," __SYMBOL_PREFIX #original);
119 #endif
120 #else
121 #define strong_alias_asm(original, alias) \
122 ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME (alias); \
123 C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original)
124 #ifdef ASSEMBLER
125 #define strong_alias(original, alias) strong_alias_asm (original, alias)
126 #else
127 #define strong_alias(original, alias) \
128 asm (__string_1 (ASM_GLOBAL_DIRECTIVE) " " __SYMBOL_PREFIX #alias "\n" \
129 __SYMBOL_PREFIX #alias " = " __SYMBOL_PREFIX #original);
130 #endif
131 #endif
133 /* Helper macros used above. */
134 #define __string_1(x) __string_0(x)
135 #define __string_0(x) #x
138 #ifdef HAVE_WEAK_SYMBOLS
140 #ifdef ASSEMBLER
142 #ifdef HAVE_ASM_WEAKEXT_DIRECTIVE
144 /* Define ALIAS as a weak alias for ORIGINAL.
145 If weak aliases are not available, this defines a strong alias. */
146 #define weak_alias(original, alias) \
147 .weakext C_SYMBOL_NAME (alias), C_SYMBOL_NAME (original)
149 /* Declare SYMBOL to be weak. */
150 #define weak_symbol(symbol) .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)
160 /* Declare SYMBOL to be weak. */
161 #define weak_symbol(symbol) .weak C_SYMBOL_NAME (symbol)
163 #endif /* ! HAVE_ASM_WEAKEXT_DIRECTIVE */
165 #else /* ! ASSEMBLER */
167 #ifdef HAVE_ASM_WEAKEXT_DIRECTIVE
168 #define weak_symbol(symbol) asm (".weakext " __SYMBOL_PREFIX #symbol);
169 #define weak_alias(original, alias) \
170 asm (".weakext " __SYMBOL_PREFIX #alias ", " __SYMBOL_PREFIX #original);
171 #else /* ! HAVE_ASM_WEAKEXT_DIRECTIVE */
172 #define weak_symbol(symbol) asm (".weak " __SYMBOL_PREFIX #symbol);
173 #define weak_alias(original, alias) \
174 asm (".weak " __SYMBOL_PREFIX #alias "\n" \
175 __SYMBOL_PREFIX #alias " = " __SYMBOL_PREFIX #original);
176 #endif /* ! HAVE_ASM_WEAKEXT_DIRECTIVE */
177 #endif /* ! ASSEMBLER */
178 #else
179 #define weak_alias(original, alias) strong_alias(original, alias)
180 #define weak_symbol(symbol) /* Do nothing. */
181 #endif
184 #if (!defined (ASSEMBLER) && \
185 (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8)))
186 /* GCC 2.8 and later has special syntax for weak symbols and aliases.
187 Using that is better when possible, because the compiler and assembler
188 are better clued in to what we are doing. */
189 #undef strong_alias
190 #define strong_alias(name, aliasname) \
191 __typeof (name) aliasname __attribute__ ((alias (#name)));
193 #ifdef HAVE_WEAK_SYMBOLS
194 #undef weak_symbol
195 #define weak_symbol(name) \
196 extern __typeof (name) name __attribute__ ((weak));
197 #undef weak_alias
198 #define weak_alias(name, aliasname) \
199 __typeof (name) aliasname __attribute__ ((weak, alias (#name)));
200 #endif /* HAVE_WEAK_SYMBOLS. */
201 #endif /* Not ASSEMBLER, and GCC 2.8 or later. */
205 /* When a reference to SYMBOL is encountered, the linker will emit a
206 warning message MSG. */
207 #ifdef HAVE_GNU_LD
208 #ifdef HAVE_ELF
209 #define link_warning(symbol, msg) \
210 static const char __evoke_link_warning_##symbol[] \
211 __attribute__ ((section (".gnu.warning." #symbol))) = msg;
212 #else
213 #define link_warning(symbol, msg) \
214 asm(".stabs \"" msg "\",30,0,0,0\n" \
215 ".stabs \"" __SYMBOL_PREFIX #symbol "\",1,0,0,0\n");
216 #endif
217 #else
218 /* We will never be heard; they will all die horribly. */
219 #define link_warning(symbol, msg)
220 #endif
222 /* A canned warning for sysdeps/stub functions. */
223 #define stub_warning(name) \
224 link_warning (name, \
225 "warning: " #name " is not implemented and will always fail")
231 #ifdef HAVE_GNU_LD
233 /* Symbol set support macros. */
235 #ifdef HAVE_ELF
237 /* Make SYMBOL, which is in the text segment, an element of SET. */
238 #define text_set_element(set, symbol) _elf_set_element(set, symbol)
239 /* Make SYMBOL, which is in the data segment, an element of SET. */
240 #define data_set_element(set, symbol) _elf_set_element(set, symbol)
241 /* Make SYMBOL, which is in the bss segment, an element of SET. */
242 #define bss_set_element(set, symbol) _elf_set_element(set, symbol)
244 /* These are all done the same way in ELF.
245 There is a new section created for each set. */
246 #ifdef PIC
247 /* When building a shared library, make the set section writable,
248 because it will need to be relocated at run time anyway. */
249 #define _elf_set_element(set, symbol) \
250 static const void *__elf_set_##set##_element_##symbol##__ \
251 __attribute__ ((unused, section (#set))) = &(symbol)
252 #else
253 #define _elf_set_element(set, symbol) \
254 static const void *const __elf_set_##set##_element_##symbol##__ \
255 __attribute__ ((unused, section (#set))) = &(symbol)
256 #endif
258 /* Define SET as a symbol set. This may be required (it is in a.out) to
259 be able to use the set's contents. */
260 #define symbol_set_define(set) symbol_set_declare(set)
262 /* Declare SET for use in this module, if defined in another module. */
263 #define symbol_set_declare(set) \
264 extern void *const __start_##set __attribute__ ((__weak__)); \
265 extern void *const __stop_##set __attribute__ ((__weak__)); \
266 /* Gratuitously repeat weak decl, in case using broken GCC (<2.8). */\
267 weak_symbol (__start_##set) weak_symbol (__stop_##set)
269 /* Return a pointer (void *const *) to the first element of SET. */
270 #define symbol_set_first_element(set) (&__start_##set)
272 /* Return true iff PTR (a void *const *) has been incremented
273 past the last element in SET. */
274 #define symbol_set_end_p(set, ptr) ((ptr) >= &__stop_##set)
276 #else /* Not ELF: a.out. */
278 #define text_set_element(set, symbol) \
279 asm(".stabs \"" __SYMBOL_PREFIX #set "\",23,0,0," __SYMBOL_PREFIX #symbol)
280 #define data_set_element(set, symbol) \
281 asm(".stabs \"" __SYMBOL_PREFIX #set "\",25,0,0," __SYMBOL_PREFIX #symbol)
282 #define bss_set_element(set, symbol) ?error Must use initialized data.
283 #define symbol_set_define(set) void *const (set)[1];
284 #define symbol_set_declare(set) extern void *const (set)[1];
286 #define symbol_set_first_element(set) &(set)[1]
287 #define symbol_set_end_p(set, ptr) (*(ptr) == 0)
289 #endif /* ELF. */
290 #endif /* Have GNU ld. */
292 #endif /* libc-symbols.h */