Sun Feb 19 20:10:43 1995 Brendan Kehoe <brendan@zen.org>
[glibc.git] / libc-symbols.h
blobb41c956efebd0f12daa3df8fb66d3d23c5ab8d64
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)
99 #else
100 #define weak_alias(original, alias) \
101 asm (".weak " __SYMBOL_PREFIX #alias "\n" \
102 __SYMBOL_PREFIX #alias " = " __SYMBOL_PREFIX #original);
103 #endif
104 #else
105 #define weak_alias(original, alias) strong_alias(original, alias)
106 #endif
110 /* When the file using this macro is linked in, the linker
111 will emit a warning message MSG. */
112 #ifdef HAVE_GNU_LD
113 #ifdef HAVE_ELF
114 #define link_warning(msg) \
115 static const char __evoke_link_warning__[] \
116 __attribute__ ((section (".gnu.warning"))) = msg;
117 #else
118 #define link_warning(msg) \
119 asm(".stabs \"" msg "\",30,0,0,0\n" \
120 ".stabs \"__evoke_link_warning__\",1,0,0,0\n"\
121 ".stabs \"__evoke_link_warning__\",2,0,0,0\n");
122 #endif
123 #else
124 /* We will never be heard; they will all die horribly. */
125 #define link_warning(msg)
126 #endif
128 /* A canned warning for sysdeps/stub functions. */
129 #define stub_warning(name) \
130 link_warning ("warning: " #name " is not implemented and will always fail")
136 #ifdef HAVE_GNU_LD
138 /* Symbol set support macros. */
140 #ifdef HAVE_ELF
142 /* Make SYMBOL, which is in the text segment, an element of SET. */
143 #define text_set_element(set, symbol) _elf_set_element(set, symbol)
144 /* Make SYMBOL, which is in the data segment, an element of SET. */
145 #define data_set_element(set, symbol) _elf_set_element(set, symbol)
146 /* Make SYMBOL, which is in the bss segment, an element of SET. */
147 #define bss_set_element(set, symbol) _elf_set_element(set, symbol)
149 /* These are all done the same way in ELF.
150 There is a new section created for each set. */
151 #define _elf_set_element(set, symbol) \
152 static const void *const __elf_set_##set##_element_##symbol##__ \
153 __attribute__ ((section (#set))) = &(symbol)
155 /* Define SET as a symbol set. This may be required (it is in a.out) to
156 be able to use the set's contents. */
157 #define symbol_set_define(set) symbol_set_declare(set)
159 /* Declare SET for use in this module, if defined in another module. */
160 #define symbol_set_declare(set) \
161 extern void *const __start_##set, *const __stop_##set;
163 /* Return a pointer (void *const *) to the first element of SET. */
164 #define symbol_set_first_element(set) (&__start_##set)
166 /* Return true iff PTR (a void *const *) has been incremented
167 past the last element in SET. */
168 #define symbol_set_end_p(set, ptr) ((ptr) >= &__stop_##set)
170 #else /* Not ELF: a.out. */
172 #define text_set_element(set, symbol) \
173 asm(".stabs \"" __SYMBOL_PREFIX #set "\",23,0,0," __SYMBOL_PREFIX #symbol)
174 #define data_set_element(set, symbol) \
175 asm(".stabs \"" __SYMBOL_PREFIX #set "\",25,0,0," __SYMBOL_PREFIX #symbol)
176 #define bss_set_element(set, symbol) ?error Must use initialized data.
177 #define symbol_set_define(set) void *const (set)[1];
178 #define symbol_set_declare(set) extern void *const (set)[1];
180 #define symbol_set_first_element(set) &(set)[1]
181 #define symbol_set_end_p(set, ptr) (*(ptr) == 0)
183 #endif /* ELF. */
184 #endif /* Have GNU ld. */
186 #endif /* libc-symbols.h */