]>
Commit | Line | Data |
---|---|---|
651d2da7 ILT |
1 | /* bfdlink.h -- header file for BFD link routines |
2 | Copyright 1993 Free Software Foundation, Inc. | |
3 | Written by Steve Chamberlain and Ian Lance Taylor, Cygnus Support. | |
4 | ||
5 | This file is part of BFD, the Binary File Descriptor library. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with this program; if not, write to the Free Software | |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
20 | ||
21 | #ifndef BFDLINK_H | |
22 | #define BFDLINK_H | |
23 | ||
24 | /* Which symbols to strip during a link. */ | |
25 | enum bfd_link_strip | |
26 | { | |
27 | strip_none, /* Don't strip any symbols. */ | |
28 | strip_debugger, /* Strip debugging symbols. */ | |
29 | strip_some, /* keep_hash is the list of symbols to keep. */ | |
30 | strip_all /* Strip all symbols. */ | |
31 | }; | |
32 | ||
33 | /* Which local symbols to discard during a link. This is irrelevant | |
34 | if strip_all is used. */ | |
35 | enum bfd_link_discard | |
36 | { | |
37 | discard_none, /* Don't discard any locals. */ | |
38 | discard_l, /* Discard locals with a certain prefix. */ | |
39 | discard_all /* Discard all locals. */ | |
40 | }; | |
41 | \f | |
42 | /* These are the possible types of an entry in the BFD link hash | |
43 | table. */ | |
44 | ||
45 | enum bfd_link_hash_type | |
46 | { | |
47 | bfd_link_hash_new, /* Symbol is new. */ | |
48 | bfd_link_hash_undefined, /* Symbol seen before, but undefined. */ | |
49 | bfd_link_hash_weak, /* Symbol is weak and undefined. */ | |
50 | bfd_link_hash_defined, /* Symbol is defined. */ | |
51 | bfd_link_hash_common, /* Symbol is common. */ | |
52 | bfd_link_hash_indirect, /* Symbol is an indirect link. */ | |
53 | bfd_link_hash_warning /* Like indirect, but warn if referenced. */ | |
54 | }; | |
55 | ||
56 | /* The linking routines use a hash table which uses this structure for | |
57 | its elements. */ | |
58 | ||
59 | struct bfd_link_hash_entry | |
60 | { | |
61 | /* Base hash table entry structure. */ | |
62 | struct bfd_hash_entry root; | |
63 | /* Type of this entry. */ | |
64 | enum bfd_link_hash_type type; | |
65 | /* Whether this symbol has been written out. */ | |
66 | boolean written; | |
67 | /* Undefined and common entries are kept in a linked list through | |
68 | this field. This field is not in the union because that would | |
69 | force us to remove entries from the list when we changed their | |
70 | type, which would force the list to be doubly linked, which would | |
71 | waste more memory. When an undefined or common symbol is | |
72 | created, it should be added to this list, the head of which is in | |
73 | the link hash table itself. As symbols are defined, they need | |
74 | not be removed from the list; anything which reads the list must | |
75 | doublecheck the symbol type. Weak symbols are not kept on this | |
76 | list. */ | |
77 | struct bfd_link_hash_entry *next; | |
78 | /* A union of information depending upon the type. */ | |
79 | union | |
80 | { | |
81 | /* Nothing is kept for bfd_hash_new. */ | |
82 | /* bfd_link_hash_undefined, bfd_link_hash_weak. */ | |
83 | struct | |
84 | { | |
85 | bfd *abfd; /* BFD symbol was found in. */ | |
86 | } undef; | |
87 | /* bfd_link_hash_defined. */ | |
88 | struct | |
89 | { | |
90 | bfd_vma value; /* Symbol value. */ | |
91 | asection *section; /* Symbol section. */ | |
92 | } def; | |
93 | /* bfd_link_hash_indirect, bfd_link_hash_warning. */ | |
94 | struct | |
95 | { | |
96 | struct bfd_link_hash_entry *link; /* Real symbol. */ | |
97 | const char *warning; /* Warning (bfd_link_hash_warning only). */ | |
98 | } i; | |
99 | /* bfd_link_hash_common. */ | |
100 | struct | |
101 | { | |
102 | bfd_vma size; /* Common symbol size. */ | |
103 | asection *section; /* Symbol section. */ | |
104 | } c; | |
105 | } u; | |
106 | }; | |
107 | ||
108 | /* This is the link hash table. It is a derived class of | |
109 | bfd_hash_table. */ | |
110 | ||
111 | struct bfd_link_hash_table | |
112 | { | |
113 | /* The hash table itself. */ | |
114 | struct bfd_hash_table table; | |
115 | /* The back end which created this hash table. This indicates the | |
116 | type of the entries in the hash table, which is sometimes | |
117 | important information when linking object files of different | |
118 | types together. */ | |
119 | bfd_target *creator; | |
120 | /* A linked list of undefined and common symbols, linked through the | |
121 | next field in the bfd_link_hash_entry structure. */ | |
122 | struct bfd_link_hash_entry *undefs; | |
123 | /* Entries are added to the tail of the undefs list. */ | |
124 | struct bfd_link_hash_entry *undefs_tail; | |
125 | }; | |
126 | ||
127 | /* Look up an entry in a link hash table. If FOLLOW is true, this | |
128 | follows bfd_link_hash_indirect and bfd_link_hash_warning links to | |
129 | the real symbol. */ | |
130 | extern struct bfd_link_hash_entry *bfd_link_hash_lookup | |
131 | PARAMS ((struct bfd_link_hash_table *, const char *, boolean create, | |
132 | boolean copy, boolean follow)); | |
133 | ||
134 | /* Traverse a link hash table. */ | |
135 | extern void bfd_link_hash_traverse | |
136 | PARAMS ((struct bfd_link_hash_table *, | |
137 | boolean (*) (struct bfd_link_hash_entry *, PTR), | |
138 | PTR)); | |
139 | ||
140 | /* Add an entry to the undefs list. */ | |
141 | extern void bfd_link_add_undef | |
142 | PARAMS ((struct bfd_link_hash_table *, struct bfd_link_hash_entry *)); | |
143 | \f | |
144 | /* This structure holds all the information needed to communicate | |
145 | between BFD and the linker when doing a link. */ | |
146 | ||
147 | struct bfd_link_info | |
148 | { | |
149 | /* Function callbacks. */ | |
150 | const struct bfd_link_callbacks *callbacks; | |
151 | /* true if BFD should generate a relocateable object file. */ | |
152 | boolean relocateable; | |
153 | /* Which symbols to strip. */ | |
154 | enum bfd_link_strip strip; | |
155 | /* Which local symbols to discard. */ | |
156 | enum bfd_link_discard discard; | |
157 | /* The local symbol prefix to discard if using discard_l. */ | |
158 | unsigned int lprefix_len; | |
159 | const char *lprefix; | |
160 | /* true if symbols should be retained in memory, false if they | |
161 | should be freed and reread. */ | |
162 | boolean keep_memory; | |
163 | /* The list of input BFD's involved in the link. These are chained | |
164 | together via the link_next field. */ | |
165 | bfd *input_bfds; | |
166 | /* If a symbol should be created for each input BFD, this is section | |
167 | where those symbols should be placed. It must be a section in | |
168 | the output BFD. It may be NULL, in which case no such symbols | |
169 | will be created. This is to support CREATE_OBJECT_SYMBOLS in the | |
170 | linker command language. */ | |
171 | asection *create_object_symbols_section; | |
172 | /* Hash table handled by BFD. */ | |
173 | struct bfd_link_hash_table *hash; | |
174 | /* Hash table of symbols to keep. This is NULL unless strip is | |
175 | strip_some. */ | |
176 | struct bfd_hash_table *keep_hash; | |
177 | /* Hash table of symbols to report back via notice_callback. If | |
178 | this is NULL no symbols are reported back. */ | |
179 | struct bfd_hash_table *notice_hash; | |
180 | }; | |
181 | ||
182 | /* This structures holds a set of callback functions. These are | |
183 | called by the BFD linker routines. The first argument to each | |
184 | callback function is the bfd_link_info structure being used. Each | |
185 | function returns a boolean value. If the function returns false, | |
186 | then the BFD function which called it will return with a failure | |
187 | indication. */ | |
188 | ||
189 | struct bfd_link_callbacks | |
190 | { | |
191 | /* A function which is called when an object is added from an | |
192 | archive. ABFD is the archive element being added. NAME is the | |
193 | name of the symbol which caused the archive element to be pulled | |
194 | in. */ | |
195 | boolean (*add_archive_element) PARAMS ((struct bfd_link_info *, | |
196 | bfd *abfd, | |
197 | const char *name)); | |
198 | /* A function which is called when a symbol is found with multiple | |
199 | definitions. NAME is the symbol which is defined multiple times. | |
200 | OBFD is the old BFD, OSEC is the old section, OVAL is the old | |
201 | value, NBFD is the new BFD, NSEC is the new section, and NVAL is | |
202 | the new value. OBFD may be NULL. OSEC and NSEC may be | |
203 | bfd_com_section or bfd_ind_section. */ | |
204 | boolean (*multiple_definition) PARAMS ((struct bfd_link_info *, | |
205 | const char *name, | |
206 | bfd *obfd, | |
207 | asection *osec, | |
208 | bfd_vma oval, | |
209 | bfd *nbfd, | |
210 | asection *nsec, | |
211 | bfd_vma nval)); | |
212 | /* A function which is called when a common symbol is defined | |
213 | multiple times. NAME is the symbol appearing multiple times. | |
214 | OBFD is the BFD of the existing symbol. OTYPE is the type of the | |
215 | existing symbol, either bfd_link_hash_defined or | |
216 | bfd_link_hash_common. If OTYPE is bfd_link_hash_common, OSIZE is | |
217 | the size of the existing symbol. NBFD is the BFD of the new | |
218 | symbol. NTYPE is the type of the new symbol, either | |
219 | bfd_link_hash_defined or bfd_link_hash_common. If NTYPE is | |
220 | bfd_link_hash_common, NSIZE is the size of the new symbol. */ | |
221 | boolean (*multiple_common) PARAMS ((struct bfd_link_info *, | |
222 | const char *name, | |
223 | bfd *obfd, | |
224 | enum bfd_link_hash_type otype, | |
225 | bfd_vma osize, | |
226 | bfd *nbfd, | |
227 | enum bfd_link_hash_type ntype, | |
228 | bfd_vma nsize)); | |
229 | /* A function which is called to add a symbol to a set. ENTRY is | |
230 | the link hash table entry for the set itself (e.g., | |
231 | __CTOR_LIST__). RELOC is the relocation to use for an entry in | |
232 | the set when generating a relocateable file, and is also used to | |
233 | get the size of the entry when generating an executable file. | |
234 | ABFD, SEC and VALUE identify the value to add to the set. */ | |
235 | boolean (*add_to_set) PARAMS ((struct bfd_link_info *, | |
236 | struct bfd_link_hash_entry *entry, | |
237 | bfd_reloc_code_real_type reloc, | |
238 | bfd *abfd, asection *sec, bfd_vma value)); | |
239 | /* A function which is called when the name of a g++ constructor or | |
240 | destructor is found. This is only called by some object file | |
241 | formats. CONSTRUCTOR is true for a constructor, false for a | |
242 | destructor. This will use BFD_RELOC_CTOR when generating a | |
243 | relocateable file. NAME is the name of the symbol found. ABFD, | |
244 | SECTION and VALUE are the value of the symbol. */ | |
245 | boolean (*constructor) PARAMS ((struct bfd_link_info *, | |
246 | boolean constructor, | |
247 | const char *name, bfd *abfd, asection *sec, | |
248 | bfd_vma value)); | |
249 | /* A function which is called when there is a reference to a warning | |
250 | symbol. WARNING is the warning to be issued. */ | |
251 | boolean (*warning) PARAMS ((struct bfd_link_info *, | |
252 | const char *warning)); | |
253 | /* A function which is called when a relocation is attempted against | |
254 | an undefined symbol. NAME is the symbol which is undefined. | |
255 | ABFD, SECTION and ADDRESS identify the location from which the | |
256 | reference is made. */ | |
257 | boolean (*undefined_symbol) PARAMS ((struct bfd_link_info *, | |
258 | const char *name, bfd *abfd, | |
259 | asection *section, bfd_vma address)); | |
260 | /* A function which is called when a reloc overflow occurs. NAME is | |
261 | the name of the symbol or section the reloc is against, | |
262 | RELOC_NAME is the name of the relocation, and ADDEND is any | |
263 | addend that is used. ABFD, SECTION and ADDRESS identify the | |
264 | location at which the overflow occurs; if this is the result of a | |
265 | bfd_section_reloc_link_order or bfd_symbol_reloc_link_order, then | |
266 | ABFD will be NULL. */ | |
267 | boolean (*reloc_overflow) PARAMS ((struct bfd_link_info *, | |
268 | const char *name, | |
269 | const char *reloc_name, bfd_vma addend, | |
270 | bfd *abfd, asection *section, | |
271 | bfd_vma address)); | |
272 | /* A function which is called when a dangerous reloc is performed. | |
273 | The canonical example is an a29k IHCONST reloc which does not | |
274 | follow an IHIHALF reloc. MESSAGE is an appropriate message. | |
275 | ABFD, SECTION and ADDRESS identify the location at which the | |
276 | problem occurred; if this is the result of a | |
277 | bfd_section_reloc_link_order or bfd_symbol_reloc_link_order, then | |
278 | ABFD will be NULL. */ | |
279 | boolean (*reloc_dangerous) PARAMS ((struct bfd_link_info *, | |
280 | const char *message, | |
281 | bfd *abfd, asection *section, | |
282 | bfd_vma address)); | |
283 | /* A function which is called when a reloc is found to be attached | |
284 | to a symbol which is not being written out. NAME is the name of | |
285 | the symbol. ABFD, SECTION and ADDRESS identify the location of | |
286 | the reloc; if this is the result of a | |
287 | bfd_section_reloc_link_order or bfd_symbol_reloc_link_order, then | |
288 | ABFD will be NULL. */ | |
289 | boolean (*unattached_reloc) PARAMS ((struct bfd_link_info *, | |
290 | const char *name, | |
291 | bfd *abfd, asection *section, | |
292 | bfd_vma address)); | |
293 | /* A function which is called when a symbol in notice_hash is | |
294 | defined or referenced. NAME is the symbol. ABFD, SECTION and | |
295 | ADDRESS are the value of the symbol. If SECTION is | |
296 | bfd_und_section, this is a reference. */ | |
297 | boolean (*notice) PARAMS ((struct bfd_link_info *, const char *name, | |
298 | bfd *abfd, asection *section, bfd_vma address)); | |
299 | }; | |
300 | \f | |
301 | /* The linker builds link_order structures which tell the code how to | |
302 | include input data in the output file. */ | |
303 | ||
304 | /* These are the types of link_order structures. */ | |
305 | ||
306 | enum bfd_link_order_type | |
307 | { | |
308 | bfd_undefined_link_order, /* Undefined. */ | |
309 | bfd_indirect_link_order, /* Built from a section. */ | |
310 | bfd_fill_link_order, /* Fill with a 16 bit constant. */ | |
311 | bfd_section_reloc_link_order, /* Relocate against a section. */ | |
312 | bfd_symbol_reloc_link_order /* Relocate against a symbol. */ | |
313 | }; | |
314 | ||
315 | /* This is the link_order structure itself. These form a chain | |
316 | attached to the section whose contents they are describing. */ | |
317 | ||
318 | struct bfd_link_order | |
319 | { | |
320 | /* Next link_order in chain. */ | |
321 | struct bfd_link_order *next; | |
322 | /* Type of link_order. */ | |
323 | enum bfd_link_order_type type; | |
324 | /* Offset within output section. */ | |
325 | bfd_vma offset; | |
326 | /* Size within output section. */ | |
327 | bfd_size_type size; | |
328 | /* Type specific information. */ | |
329 | union | |
330 | { | |
331 | struct | |
332 | { | |
333 | /* Section to include. If this is used, then | |
334 | section->output_section must be the section the | |
335 | link_order is attached to, section->output_offset must | |
336 | equal the link_order offset field, and section->_raw_size | |
337 | must equal the link_order size field. Maybe these | |
338 | restrictions should be relaxed someday. */ | |
339 | asection *section; | |
340 | } indirect; | |
341 | struct | |
342 | { | |
343 | /* Value to fill with. */ | |
344 | unsigned int value; | |
345 | } fill; | |
346 | struct | |
347 | { | |
348 | /* Description of reloc to generate. Used for | |
349 | bfd_section_reloc_link_order and | |
350 | bfd_symbol_reloc_link_order. */ | |
351 | struct bfd_link_order_reloc *p; | |
352 | } reloc; | |
353 | } u; | |
354 | }; | |
355 | ||
356 | /* A linker order of type bfd_section_reloc_link_order or | |
357 | bfd_symbol_reloc_link_order means to create a reloc against a | |
358 | section or symbol, respectively. This is used to implement -Ur to | |
359 | generate relocs for the constructor tables. The | |
360 | bfd_link_order_reloc structure describes the reloc that BFD should | |
361 | create. It is similar to a arelent, but I didn't use arelent | |
362 | because the linker does not know anything about most symbols, and | |
363 | any asymbol structure it creates will be partially meaningless. | |
364 | This information could logically be in the bfd_link_order struct, | |
365 | but I didn't want to waste the space since these types of relocs | |
366 | are relatively rare. */ | |
367 | ||
368 | struct bfd_link_order_reloc | |
369 | { | |
370 | /* Reloc type. */ | |
371 | bfd_reloc_code_real_type reloc; | |
372 | ||
373 | union | |
374 | { | |
375 | /* For type bfd_section_reloc_link_order, this is the section | |
376 | the reloc should be against. This must be a section in the | |
377 | output BFD, not any of the input BFDs. */ | |
378 | asection *section; | |
379 | /* For type bfd_symbol_reloc_link_order, this is the name of the | |
380 | symbol the reloc should be against. */ | |
381 | const char *name; | |
382 | } u; | |
383 | ||
384 | /* Addend to use. The object file should contain zero. The BFD | |
385 | backend is responsible for filling in the contents of the object | |
386 | file correctly. For some object file formats (e.g., COFF) the | |
387 | addend must be stored into in the object file, and for some | |
388 | (e.g., SPARC a.out) it is kept in the reloc. */ | |
389 | bfd_vma addend; | |
390 | }; | |
391 | ||
392 | /* Allocate a new link_order for a section. */ | |
393 | extern struct bfd_link_order *bfd_new_link_order PARAMS ((bfd *, asection *)); | |
394 | ||
395 | #endif |