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