]>
Commit | Line | Data |
---|---|---|
28f540f4 RM |
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. | |
5 | ||
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. | |
10 | ||
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. | |
15 | ||
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. */ | |
20 | ||
21 | #ifndef _LIBC_SYMBOLS_H | |
22 | #define _LIBC_SYMBOLS_H | |
23 | ||
24 | /* This file's macros are included implicitly in the compilation of every | |
25 | file in the C library by -imacros. | |
26 | ||
27 | We include config.h which is generated by configure. | |
28 | It should define for us the following symbols: | |
29 | ||
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. | |
35 | ||
36 | * HAVE_WEAK_SYMBOLS if weak symbols are available in the assembler and | |
37 | linker being used. Set by --with-weak-symbols. | |
38 | ||
39 | */ | |
40 | #include <config.h> | |
41 | ||
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 | |
49 | ||
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. */ | |
54 | ||
55 | #ifndef HAVE_WEAK_SYMBOLS | |
56 | #if defined (HAVE_ELF) || defined (HAVE_GNU_LD) | |
57 | #define HAVE_WEAK_SYMBOLS | |
58 | #endif | |
59 | #endif | |
60 | ||
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 | |
73 | ||
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 | |
81 | ||
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 | |
91 | ||
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 | |
107 | ||
108 | ||
109 | ||
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 | |
127 | ||
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") | |
131 | \f | |
132 | #ifdef HAVE_GNU_LD | |
133 | ||
134 | /* Symbol set support macros. */ | |
135 | ||
136 | #ifdef HAVE_ELF | |
137 | ||
138 | /* Make SYMBOL, which is in the text segment, an element of SET. */ | |
139 | #define text_set_element(set, symbol) _elf_set_element(set, symbol) | |
140 | /* Make SYMBOL, which is in the data segment, an element of SET. */ | |
141 | #define data_set_element(set, symbol) _elf_set_element(set, symbol) | |
142 | /* Make SYMBOL, which is in the bss segment, an element of SET. */ | |
143 | #define bss_set_element(set, symbol) _elf_set_element(set, symbol) | |
144 | ||
145 | /* These are all done the same way in ELF. | |
146 | There is a new section created for each set. */ | |
147 | #define _elf_set_element(set, symbol) \ | |
148 | static const void *const __elf_set_##set##_element_##symbol##__ \ | |
149 | __attribute__ ((section (#set))) = &(symbol) | |
150 | ||
151 | /* Define SET as a symbol set. This may be required (it is in a.out) to | |
152 | be able to use the set's contents. */ | |
153 | #define symbol_set_define(set) symbol_set_declare(set) | |
154 | ||
155 | /* Declare SET for use in this module, if defined in another module. */ | |
156 | #define symbol_set_declare(set) \ | |
157 | extern void *const __start_##set, *const __stop_##set; | |
158 | ||
159 | /* Return a pointer (void *const *) to the first element of SET. */ | |
160 | #define symbol_set_first_element(set) (&__start_##set) | |
161 | ||
162 | /* Return true iff PTR (a void *const *) has been incremented | |
163 | past the last element in SET. */ | |
164 | #define symbol_set_end_p(set, ptr) ((ptr) >= &__stop_##set) | |
165 | ||
166 | #else /* Not ELF: a.out. */ | |
167 | ||
168 | #define text_set_element(set, symbol) \ | |
169 | asm(".stabs \"" __SYMBOL_PREFIX #set "\",23,0,0," __SYMBOL_PREFIX #symbol) | |
170 | #define data_set_element(set, symbol) \ | |
171 | asm(".stabs \"" __SYMBOL_PREFIX #set "\",25,0,0," __SYMBOL_PREFIX #symbol) | |
172 | #define bss_set_element(set, symbol) ?error Must use initialized data. | |
173 | #define symbol_set_define(set) void *const (set)[1]; | |
174 | #define symbol_set_declare(set) extern void *const (set)[1]; | |
175 | ||
176 | #define symbol_set_first_element(set) &(set)[1] | |
177 | #define symbol_set_end_p(set, ptr) (*(ptr) == 0) | |
178 | ||
179 | #endif /* ELF. */ | |
180 | #endif /* Have GNU ld. */ | |
181 | ||
182 | #endif /* libc-symbols.h */ |