* extra-lib.mk (install-lib, extra-objs, alltypes-$(lib)): Make
[glibc.git] / libc-symbols.h
blob83773bfdc9d3faab8dd14d7db30e7463c2ee97df
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
82 /* Define ALIAS as a strong alias for ORIGINAL. */
83 #define strong_alias_asm(original, alias) \
84 .set C_SYMBOL_NAME (alias),C_SYMBOL_NAME (original)
85 #ifdef ASSEMBLER
86 #define strong_alias(original, alias) strong_alias_asm (original, alias)
87 #else
88 #define strong_alias(original, alias) \
89 asm (".set " __SYMBOL_PREFIX #alias "," __SYMBOL_PREFIX #original);
90 #endif
92 /* Define ALIAS as a weak alias for ORIGINAL.
93 If weak aliases are not available, this defines a strong alias. */
94 #ifdef HAVE_WEAK_SYMBOLS
95 #ifdef ASSEMBLER
96 #define weak_alias(original, alias) \
97 .weak C_SYMBOL_NAME (alias); \
98 C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original)
100 /* Declare SYMBOL to be weak. */
101 #define weak_symbol(symbol) .weak C_SYMBOL_NAME (symbol)
102 #else
103 #define weak_symbol(symbol) asm (".weak " __SYMBOL_PREFIX #symbol);
104 #define weak_alias(original, alias) \
105 asm (".weak " __SYMBOL_PREFIX #alias "\n" \
106 __SYMBOL_PREFIX #alias " = " __SYMBOL_PREFIX #original);
107 #endif
108 #else
109 #define weak_alias(original, alias) strong_alias(original, alias)
110 #define weak_symbol(symbol) /* Do nothing. */
111 #endif
115 /* When the file using this macro is linked in, the linker
116 will emit a warning message MSG. */
117 #ifdef HAVE_GNU_LD
118 #ifdef HAVE_ELF
119 #define link_warning(msg) \
120 static const char __evoke_link_warning__[] \
121 __attribute__ ((section (".gnu.warning"))) = msg;
122 #else
123 #define link_warning(msg) \
124 asm(".stabs \"" msg "\",30,0,0,0\n" \
125 ".stabs \"__evoke_link_warning__\",1,0,0,0\n"\
126 ".stabs \"__evoke_link_warning__\",2,0,0,0\n");
127 #endif
128 #else
129 /* We will never be heard; they will all die horribly. */
130 #define link_warning(msg)
131 #endif
133 /* A canned warning for sysdeps/stub functions. */
134 #define stub_warning(name) \
135 link_warning ("warning: " #name " is not implemented and will always fail")
141 #ifdef HAVE_GNU_LD
143 /* Symbol set support macros. */
145 #ifdef HAVE_ELF
147 /* Make SYMBOL, which is in the text segment, an element of SET. */
148 #define text_set_element(set, symbol) _elf_set_element(set, symbol)
149 /* Make SYMBOL, which is in the data segment, an element of SET. */
150 #define data_set_element(set, symbol) _elf_set_element(set, symbol)
151 /* Make SYMBOL, which is in the bss segment, an element of SET. */
152 #define bss_set_element(set, symbol) _elf_set_element(set, symbol)
154 /* These are all done the same way in ELF.
155 There is a new section created for each set. */
156 #define _elf_set_element(set, symbol) \
157 static const void *const __elf_set_##set##_element_##symbol##__ \
158 __attribute__ ((section (#set))) = &(symbol)
160 /* Define SET as a symbol set. This may be required (it is in a.out) to
161 be able to use the set's contents. */
162 #define symbol_set_define(set) symbol_set_declare(set)
164 /* Declare SET for use in this module, if defined in another module. */
165 #define symbol_set_declare(set) \
166 extern void *const __start_##set, *const __stop_##set;
168 /* Return a pointer (void *const *) to the first element of SET. */
169 #define symbol_set_first_element(set) (&__start_##set)
171 /* Return true iff PTR (a void *const *) has been incremented
172 past the last element in SET. */
173 #define symbol_set_end_p(set, ptr) ((ptr) >= &__stop_##set)
175 #else /* Not ELF: a.out. */
177 #define text_set_element(set, symbol) \
178 asm(".stabs \"" __SYMBOL_PREFIX #set "\",23,0,0," __SYMBOL_PREFIX #symbol)
179 #define data_set_element(set, symbol) \
180 asm(".stabs \"" __SYMBOL_PREFIX #set "\",25,0,0," __SYMBOL_PREFIX #symbol)
181 #define bss_set_element(set, symbol) ?error Must use initialized data.
182 #define symbol_set_define(set) void *const (set)[1];
183 #define symbol_set_declare(set) extern void *const (set)[1];
185 #define symbol_set_first_element(set) &(set)[1]
186 #define symbol_set_end_p(set, ptr) (*(ptr) == 0)
188 #endif /* ELF. */
189 #endif /* Have GNU ld. */
191 #endif /* libc-symbols.h */