Wed Jun 14 03:45:24 1995 Roland McGrath <roland@churchy.gnu.ai.mit.edu>
[glibc.git] / libc-symbols.h
blobf4d82a6e724965f6a66de3b31b162bd0086e555a
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
138 /* When the file using this macro is linked in, the linker
139 will emit a warning message MSG. */
140 #ifdef HAVE_GNU_LD
141 #ifdef HAVE_ELF
142 #define link_warning(msg) \
143 static const char __evoke_link_warning__[] \
144 __attribute__ ((section (".gnu.warning"))) = msg;
145 #else
146 #define link_warning(msg) \
147 asm(".stabs \"" msg "\",30,0,0,0\n" \
148 ".stabs \"__evoke_link_warning__\",1,0,0,0\n"\
149 ".stabs \"__evoke_link_warning__\",2,0,0,0\n");
150 #endif
151 #else
152 /* We will never be heard; they will all die horribly. */
153 #define link_warning(msg)
154 #endif
156 /* A canned warning for sysdeps/stub functions. */
157 #define stub_warning(name) \
158 link_warning ("warning: " #name " is not implemented and will always fail")
164 #ifdef HAVE_GNU_LD
166 /* Symbol set support macros. */
168 #ifdef HAVE_ELF
170 /* Make SYMBOL, which is in the text segment, an element of SET. */
171 #define text_set_element(set, symbol) _elf_set_element(set, symbol)
172 /* Make SYMBOL, which is in the data segment, an element of SET. */
173 #define data_set_element(set, symbol) _elf_set_element(set, symbol)
174 /* Make SYMBOL, which is in the bss segment, an element of SET. */
175 #define bss_set_element(set, symbol) _elf_set_element(set, symbol)
177 /* These are all done the same way in ELF.
178 There is a new section created for each set. */
179 #ifdef PIC
180 /* When building a shared library, make the set section writable,
181 because it will need to be relocated at run time anyway. */
182 #define _elf_set_element(set, symbol) \
183 static const void *__elf_set_##set##_element_##symbol##__ \
184 __attribute__ ((unused, section (#set))) = &(symbol)
185 #else
186 #define _elf_set_element(set, symbol) \
187 static const void *const __elf_set_##set##_element_##symbol##__ \
188 __attribute__ ((unused, section (#set))) = &(symbol)
189 #endif
191 /* Define SET as a symbol set. This may be required (it is in a.out) to
192 be able to use the set's contents. */
193 #define symbol_set_define(set) symbol_set_declare(set)
195 /* Declare SET for use in this module, if defined in another module. */
196 #define symbol_set_declare(set) \
197 extern void *const __start_##set, *const __stop_##set;
199 /* Return a pointer (void *const *) to the first element of SET. */
200 #define symbol_set_first_element(set) (&__start_##set)
202 /* Return true iff PTR (a void *const *) has been incremented
203 past the last element in SET. */
204 #define symbol_set_end_p(set, ptr) ((ptr) >= &__stop_##set)
206 #else /* Not ELF: a.out. */
208 #define text_set_element(set, symbol) \
209 asm(".stabs \"" __SYMBOL_PREFIX #set "\",23,0,0," __SYMBOL_PREFIX #symbol)
210 #define data_set_element(set, symbol) \
211 asm(".stabs \"" __SYMBOL_PREFIX #set "\",25,0,0," __SYMBOL_PREFIX #symbol)
212 #define bss_set_element(set, symbol) ?error Must use initialized data.
213 #define symbol_set_define(set) void *const (set)[1];
214 #define symbol_set_declare(set) extern void *const (set)[1];
216 #define symbol_set_first_element(set) &(set)[1]
217 #define symbol_set_end_p(set, ptr) (*(ptr) == 0)
219 #endif /* ELF. */
220 #endif /* Have GNU ld. */
222 #endif /* libc-symbols.h */