Commit | Line | Data |
---|---|---|
fd0198f0 ILT |
1 | /* BFD back-end data structures for ELF files. |
2 | Copyright (C) 1992, 1993 Free Software Foundation, Inc. | |
3 | Written by 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |
20 | ||
21 | #ifndef _LIBELF_H_ | |
22 | #define _LIBELF_H_ 1 | |
23 | ||
24 | #include "elf/common.h" | |
25 | #include "elf/internal.h" | |
26 | #include "elf/external.h" | |
27 | #include "bfdlink.h" | |
28 | ||
29 | /* If size isn't specified as 64 or 32, NAME macro should fail. */ | |
30 | #ifndef NAME | |
31 | #if ARCH_SIZE==64 | |
32 | #define NAME(x,y) CAT4(x,64,_,y) | |
33 | #endif | |
34 | #if ARCH_SIZE==32 | |
35 | #define NAME(x,y) CAT4(x,32,_,y) | |
36 | #endif | |
37 | #endif | |
38 | ||
39 | #ifndef NAME | |
40 | #define NAME(x,y) CAT4(x,NOSIZE,_,y) | |
41 | #endif | |
42 | ||
43 | #define ElfNAME(X) NAME(Elf,X) | |
44 | #define elfNAME(X) NAME(elf,X) | |
45 | ||
46 | /* Information held for an ELF symbol. The first field is the | |
47 | corresponding asymbol. Every symbol is an ELF file is actually a | |
48 | pointer to this structure, although it is often handled as a | |
49 | pointer to an asymbol. */ | |
50 | ||
51 | typedef struct | |
52 | { | |
53 | /* The BFD symbol. */ | |
54 | asymbol symbol; | |
55 | /* ELF symbol information. */ | |
56 | Elf_Internal_Sym internal_elf_sym; | |
57 | /* Backend specific information. */ | |
58 | union | |
59 | { | |
60 | unsigned int hppa_arg_reloc; | |
61 | PTR mips_extr; | |
62 | PTR any; | |
63 | } | |
64 | tc_data; | |
65 | } elf_symbol_type; | |
66 | \f | |
67 | /* ELF linker hash table entries. */ | |
68 | ||
69 | struct elf_link_hash_entry | |
70 | { | |
71 | struct bfd_link_hash_entry root; | |
72 | ||
73 | /* Symbol index in output file. This is initialized to -1. It is | |
74 | set to -2 if the symbol is used by a reloc. */ | |
75 | long indx; | |
76 | ||
77 | /* Symbol size. */ | |
78 | bfd_size_type size; | |
79 | ||
80 | /* Symbol index as a dynamic symbol. Initialized to -1, and remains | |
81 | -1 if this is not a dynamic symbol. */ | |
82 | long dynindx; | |
83 | ||
84 | /* String table index in .dynstr if this is a dynamic symbol. */ | |
85 | unsigned long dynstr_index; | |
86 | ||
87 | /* If this is a weak defined symbol from a dynamic object, this | |
88 | field points to a defined symbol with the same value, if there is | |
89 | one. Otherwise it is NULL. */ | |
90 | struct elf_link_hash_entry *weakdef; | |
91 | ||
92 | /* If this symbol requires an entry in the global offset table, the | |
93 | processor specific backend uses this field to hold the offset | |
94 | into the .got section. If this field is -1, then the symbol does | |
95 | not require a global offset table entry. */ | |
96 | bfd_vma got_offset; | |
97 | ||
98 | /* If this symbol requires an entry in the procedure linkage table, | |
99 | the processor specific backend uses these two fields to hold the | |
100 | offset into the procedure linkage section and the offset into the | |
101 | .got section. If plt_offset is -1, then the symbol does not | |
102 | require an entry in the procedure linkage table. */ | |
103 | bfd_vma plt_offset; | |
104 | ||
105 | /* Symbol type (STT_NOTYPE, STT_OBJECT, etc.). */ | |
106 | char type; | |
107 | ||
108 | /* Some flags; legal values follow. */ | |
109 | unsigned char elf_link_hash_flags; | |
110 | /* Symbol is referenced by a non-shared object. */ | |
111 | #define ELF_LINK_HASH_REF_REGULAR 01 | |
112 | /* Symbol is defined by a non-shared object. */ | |
113 | #define ELF_LINK_HASH_DEF_REGULAR 02 | |
114 | /* Symbol is referenced by a shared object. */ | |
115 | #define ELF_LINK_HASH_REF_DYNAMIC 04 | |
116 | /* Symbol is defined by a shared object. */ | |
117 | #define ELF_LINK_HASH_DEF_DYNAMIC 010 | |
118 | /* Dynamic symbol has been adjustd. */ | |
119 | #define ELF_LINK_HASH_DYNAMIC_ADJUSTED 020 | |
120 | /* Symbol needs a copy reloc. */ | |
121 | #define ELF_LINK_HASH_NEEDS_COPY 040 | |
122 | /* Symbol needs a procedure linkage table entry. */ | |
123 | #define ELF_LINK_HASH_NEEDS_PLT 0100 | |
124 | }; | |
125 | ||
126 | /* ELF linker hash table. */ | |
127 | ||
128 | struct elf_link_hash_table | |
129 | { | |
130 | struct bfd_link_hash_table root; | |
131 | /* Whether we have created the special dynamic sections required | |
132 | when linking against or generating a shared object. */ | |
133 | boolean dynamic_sections_created; | |
134 | /* The BFD used to hold special sections created by the linker. | |
135 | This will be the first BFD found which requires these sections to | |
136 | be created. */ | |
137 | bfd *dynobj; | |
138 | /* The number of symbols found in the link which must be put into | |
139 | the .dynsym section. */ | |
140 | bfd_size_type dynsymcount; | |
141 | /* The string table of dynamic symbols, which becomes the .dynstr | |
142 | section. */ | |
143 | struct bfd_strtab_hash *dynstr; | |
144 | /* The number of buckets in the hash table in the .hash section. | |
145 | This is based on the number of dynamic symbols. */ | |
146 | bfd_size_type bucketcount; | |
147 | /* A linked list of DT_NEEDED names found in dynamic objects | |
148 | included in the link. */ | |
149 | struct bfd_link_needed_list *needed; | |
150 | }; | |
151 | ||
152 | /* Look up an entry in an ELF linker hash table. */ | |
153 | ||
154 | #define elf_link_hash_lookup(table, string, create, copy, follow) \ | |
155 | ((struct elf_link_hash_entry *) \ | |
156 | bfd_link_hash_lookup (&(table)->root, (string), (create), \ | |
157 | (copy), (follow))) | |
158 | ||
159 | /* Traverse an ELF linker hash table. */ | |
160 | ||
161 | #define elf_link_hash_traverse(table, func, info) \ | |
162 | (bfd_link_hash_traverse \ | |
163 | (&(table)->root, \ | |
164 | (boolean (*) PARAMS ((struct bfd_link_hash_entry *, PTR))) (func), \ | |
165 | (info))) | |
166 | ||
167 | /* Get the ELF linker hash table from a link_info structure. */ | |
168 | ||
169 | #define elf_hash_table(p) ((struct elf_link_hash_table *) ((p)->hash)) | |
170 | \f | |
171 | /* Constant information held for an ELF backend. */ | |
172 | ||
173 | struct elf_size_info { | |
174 | unsigned char sizeof_ehdr, sizeof_phdr, sizeof_shdr; | |
175 | unsigned char sizeof_rel, sizeof_rela, sizeof_sym, sizeof_dyn, sizeof_note; | |
176 | ||
177 | unsigned char arch_size, file_align; | |
178 | unsigned char elfclass, ev_current; | |
179 | int (*write_out_phdrs) PARAMS ((bfd *, Elf_Internal_Phdr *, int)); | |
180 | boolean (*write_shdrs_and_ehdr) PARAMS ((bfd *)); | |
181 | void (*write_relocs) PARAMS ((bfd *, asection *, PTR)); | |
182 | void (*swap_symbol_out) PARAMS ((bfd *, Elf_Internal_Sym *, PTR)); | |
183 | boolean (*slurp_reloc_table) PARAMS ((bfd *, asection *, asymbol **)); | |
184 | long (*slurp_symbol_table) PARAMS ((bfd *, asymbol **, boolean)); | |
02fcd126 | 185 | void (*swap_dyn_in) PARAMS ((bfd *, const PTR, Elf_Internal_Dyn *)); |
fd0198f0 ILT |
186 | }; |
187 | ||
188 | #define elf_symbol_from(ABFD,S) \ | |
189 | (((S)->the_bfd->xvec->flavour == bfd_target_elf_flavour \ | |
190 | && (S)->the_bfd->tdata.elf_obj_data != 0) \ | |
191 | ? (elf_symbol_type *) (S) \ | |
192 | : 0) | |
193 | ||
194 | struct elf_backend_data | |
195 | { | |
196 | /* Whether the backend uses REL or RELA relocations. FIXME: some | |
197 | ELF backends use both. When we need to support one, this whole | |
198 | approach will need to be changed. */ | |
199 | int use_rela_p; | |
200 | ||
201 | /* The architecture for this backend. */ | |
202 | enum bfd_architecture arch; | |
203 | ||
204 | /* The ELF machine code (EM_xxxx) for this backend. */ | |
205 | int elf_machine_code; | |
206 | ||
207 | /* The maximum page size for this backend. */ | |
208 | bfd_vma maxpagesize; | |
209 | ||
210 | /* This is true if the linker should act like collect and gather | |
211 | global constructors and destructors by name. This is true for | |
212 | MIPS ELF because the Irix 5 tools can not handle the .init | |
213 | section. */ | |
214 | boolean collect; | |
215 | ||
5b3b9ff6 ILT |
216 | /* This is true if the linker should ignore changes to the type of a |
217 | symbol. This is true for MIPS ELF because some Irix 5 objects | |
218 | record undefined functions as STT_OBJECT although the definitions | |
219 | are STT_FUNC. */ | |
220 | boolean type_change_ok; | |
221 | ||
fd0198f0 ILT |
222 | /* A function to translate an ELF RELA relocation to a BFD arelent |
223 | structure. */ | |
224 | void (*elf_info_to_howto) PARAMS ((bfd *, arelent *, | |
225 | Elf_Internal_Rela *)); | |
226 | ||
227 | /* A function to translate an ELF REL relocation to a BFD arelent | |
228 | structure. */ | |
229 | void (*elf_info_to_howto_rel) PARAMS ((bfd *, arelent *, | |
230 | Elf_Internal_Rel *)); | |
231 | ||
232 | /* A function to determine whether a symbol is global when | |
233 | partitioning the symbol table into local and global symbols. | |
234 | This should be NULL for most targets, in which case the correct | |
235 | thing will be done. MIPS ELF, at least on the Irix 5, has | |
236 | special requirements. */ | |
237 | boolean (*elf_backend_sym_is_global) PARAMS ((bfd *, asymbol *)); | |
238 | ||
239 | /* The remaining functions are hooks which are called only if they | |
240 | are not NULL. */ | |
241 | ||
242 | /* A function to permit a backend specific check on whether a | |
243 | particular BFD format is relevant for an object file, and to | |
244 | permit the backend to set any global information it wishes. When | |
245 | this is called elf_elfheader is set, but anything else should be | |
246 | used with caution. If this returns false, the check_format | |
247 | routine will return a bfd_error_wrong_format error. */ | |
248 | boolean (*elf_backend_object_p) PARAMS ((bfd *)); | |
249 | ||
250 | /* A function to do additional symbol processing when reading the | |
251 | ELF symbol table. This is where any processor-specific special | |
252 | section indices are handled. */ | |
253 | void (*elf_backend_symbol_processing) PARAMS ((bfd *, asymbol *)); | |
254 | ||
255 | /* A function to do additional symbol processing after reading the | |
256 | entire ELF symbol table. */ | |
257 | boolean (*elf_backend_symbol_table_processing) PARAMS ((bfd *, | |
258 | elf_symbol_type *, | |
259 | unsigned int)); | |
260 | ||
261 | /* A function to do additional processing on the ELF section header | |
262 | just before writing it out. This is used to set the flags and | |
263 | type fields for some sections, or to actually write out data for | |
264 | unusual sections. */ | |
265 | boolean (*elf_backend_section_processing) PARAMS ((bfd *, | |
266 | Elf32_Internal_Shdr *)); | |
267 | ||
268 | /* A function to handle unusual section types when creating BFD | |
269 | sections from ELF sections. */ | |
270 | boolean (*elf_backend_section_from_shdr) PARAMS ((bfd *, | |
271 | Elf32_Internal_Shdr *, | |
272 | char *)); | |
273 | ||
274 | /* A function to set up the ELF section header for a BFD section in | |
275 | preparation for writing it out. This is where the flags and type | |
276 | fields are set for unusual sections. */ | |
277 | boolean (*elf_backend_fake_sections) PARAMS ((bfd *, Elf32_Internal_Shdr *, | |
278 | asection *)); | |
279 | ||
280 | /* A function to get the ELF section index for a BFD section. If | |
281 | this returns true, the section was found. If it is a normal ELF | |
282 | section, *RETVAL should be left unchanged. If it is not a normal | |
283 | ELF section *RETVAL should be set to the SHN_xxxx index. */ | |
284 | boolean (*elf_backend_section_from_bfd_section) | |
285 | PARAMS ((bfd *, Elf32_Internal_Shdr *, asection *, int *retval)); | |
286 | ||
287 | /* If this field is not NULL, it is called by the add_symbols phase | |
288 | of a link just before adding a symbol to the global linker hash | |
289 | table. It may modify any of the fields as it wishes. If *NAME | |
290 | is set to NULL, the symbol will be skipped rather than being | |
291 | added to the hash table. This function is responsible for | |
292 | handling all processor dependent symbol bindings and section | |
293 | indices, and must set at least *FLAGS and *SEC for each processor | |
294 | dependent case; failure to do so will cause a link error. */ | |
295 | boolean (*elf_add_symbol_hook) | |
296 | PARAMS ((bfd *abfd, struct bfd_link_info *info, | |
297 | const Elf_Internal_Sym *, const char **name, | |
298 | flagword *flags, asection **sec, bfd_vma *value)); | |
299 | ||
300 | /* If this field is not NULL, it is called by the elf_link_output_sym | |
301 | phase of a link for each symbol which will appear in the object file. */ | |
302 | boolean (*elf_backend_link_output_symbol_hook) | |
303 | PARAMS ((bfd *, struct bfd_link_info *info, const char *, | |
304 | Elf_Internal_Sym *, asection *)); | |
305 | ||
306 | /* The CREATE_DYNAMIC_SECTIONS function is called by the ELF backend | |
307 | linker the first time it encounters a dynamic object in the link. | |
308 | This function must create any sections required for dynamic | |
309 | linking. The ABFD argument is a dynamic object. The .interp, | |
310 | .dynamic, .dynsym, .dynstr, and .hash functions have already been | |
311 | created, and this function may modify the section flags if | |
312 | desired. This function will normally create the .got and .plt | |
313 | sections, but different backends have different requirements. */ | |
314 | boolean (*elf_backend_create_dynamic_sections) | |
315 | PARAMS ((bfd *abfd, struct bfd_link_info *info)); | |
316 | ||
317 | /* The CHECK_RELOCS function is called by the add_symbols phase of | |
318 | the ELF backend linker. It is called once for each section with | |
319 | relocs of an object file, just after the symbols for the object | |
320 | file have been added to the global linker hash table. The | |
321 | function must look through the relocs and do any special handling | |
322 | required. This generally means allocating space in the global | |
323 | offset table, and perhaps allocating space for a reloc. The | |
324 | relocs are always passed as Rela structures; if the section | |
325 | actually uses Rel structures, the r_addend field will always be | |
326 | zero. */ | |
327 | boolean (*check_relocs) | |
328 | PARAMS ((bfd *abfd, struct bfd_link_info *info, asection *o, | |
329 | const Elf_Internal_Rela *relocs)); | |
330 | ||
331 | /* The ADJUST_DYNAMIC_SYMBOL function is called by the ELF backend | |
332 | linker for every symbol which is defined by a dynamic object and | |
333 | referenced by a regular object. This is called after all the | |
334 | input files have been seen, but before the SIZE_DYNAMIC_SECTIONS | |
335 | function has been called. The hash table entry should be | |
336 | bfd_link_hash_defined ore bfd_link_hash_defweak, and it should be | |
337 | defined in a section from a dynamic object. Dynamic object | |
338 | sections are not included in the final link, and this function is | |
339 | responsible for changing the value to something which the rest of | |
340 | the link can deal with. This will normally involve adding an | |
341 | entry to the .plt or .got or some such section, and setting the | |
342 | symbol to point to that. */ | |
343 | boolean (*elf_backend_adjust_dynamic_symbol) | |
344 | PARAMS ((struct bfd_link_info *info, struct elf_link_hash_entry *h)); | |
345 | ||
346 | /* The SIZE_DYNAMIC_SECTIONS function is called by the ELF backend | |
347 | linker after all the linker input files have been seen but before | |
348 | the sections sizes have been set. This is called after | |
349 | ADJUST_DYNAMIC_SYMBOL has been called on all appropriate symbols. | |
350 | It is only called when linking against a dynamic object. It must | |
351 | set the sizes of the dynamic sections, and may fill in their | |
352 | contents as well. The generic ELF linker can handle the .dynsym, | |
353 | .dynstr and .hash sections. This function must handle the | |
354 | .interp section and any sections created by the | |
355 | CREATE_DYNAMIC_SECTIONS entry point. */ | |
356 | boolean (*elf_backend_size_dynamic_sections) | |
357 | PARAMS ((bfd *output_bfd, struct bfd_link_info *info)); | |
358 | ||
359 | /* The RELOCATE_SECTION function is called by the ELF backend linker | |
360 | to handle the relocations for a section. | |
361 | ||
362 | The relocs are always passed as Rela structures; if the section | |
363 | actually uses Rel structures, the r_addend field will always be | |
364 | zero. | |
365 | ||
366 | This function is responsible for adjust the section contents as | |
367 | necessary, and (if using Rela relocs and generating a | |
368 | relocateable output file) adjusting the reloc addend as | |
369 | necessary. | |
370 | ||
371 | This function does not have to worry about setting the reloc | |
372 | address or the reloc symbol index. | |
373 | ||
374 | LOCAL_SYMS is a pointer to the swapped in local symbols. | |
375 | ||
376 | LOCAL_SECTIONS is an array giving the section in the input file | |
377 | corresponding to the st_shndx field of each local symbol. | |
378 | ||
379 | The global hash table entry for the global symbols can be found | |
380 | via elf_sym_hashes (input_bfd). | |
381 | ||
382 | When generating relocateable output, this function must handle | |
383 | STB_LOCAL/STT_SECTION symbols specially. The output symbol is | |
384 | going to be the section symbol corresponding to the output | |
385 | section, which means that the addend must be adjusted | |
386 | accordingly. */ | |
387 | boolean (*elf_backend_relocate_section) | |
388 | PARAMS ((bfd *output_bfd, struct bfd_link_info *info, | |
389 | bfd *input_bfd, asection *input_section, bfd_byte *contents, | |
390 | Elf_Internal_Rela *relocs, Elf_Internal_Sym *local_syms, | |
391 | asection **local_sections)); | |
392 | ||
393 | /* The FINISH_DYNAMIC_SYMBOL function is called by the ELF backend | |
394 | linker just before it writes a symbol out to the .dynsym section. | |
395 | The processor backend may make any required adjustment to the | |
396 | symbol. It may also take the opportunity to set contents of the | |
397 | dynamic sections. Note that FINISH_DYNAMIC_SYMBOL is called on | |
398 | all .dynsym symbols, while ADJUST_DYNAMIC_SYMBOL is only called | |
399 | on those symbols which are defined by a dynamic object. */ | |
400 | boolean (*elf_backend_finish_dynamic_symbol) | |
401 | PARAMS ((bfd *output_bfd, struct bfd_link_info *info, | |
402 | struct elf_link_hash_entry *h, Elf_Internal_Sym *sym)); | |
403 | ||
404 | /* The FINISH_DYNAMIC_SECTIONS function is called by the ELF backend | |
405 | linker just before it writes all the dynamic sections out to the | |
406 | output file. The FINISH_DYNAMIC_SYMBOL will have been called on | |
407 | all dynamic symbols. */ | |
408 | boolean (*elf_backend_finish_dynamic_sections) | |
409 | PARAMS ((bfd *output_bfd, struct bfd_link_info *info)); | |
410 | ||
411 | /* A function to do any beginning processing needed for the ELF file | |
412 | before building the ELF headers and computing file positions. */ | |
413 | void (*elf_backend_begin_write_processing) | |
414 | PARAMS ((bfd *, struct bfd_link_info *)); | |
415 | ||
416 | /* A function to do any final processing needed for the ELF file | |
417 | before writing it out. The LINKER argument is true if this BFD | |
418 | was created by the ELF backend linker. */ | |
419 | void (*elf_backend_final_write_processing) | |
420 | PARAMS ((bfd *, boolean linker)); | |
421 | ||
5b3b9ff6 ILT |
422 | /* This function is called by get_program_header_size. It should |
423 | return the number of additional program segments which this BFD | |
424 | will need. It should return -1 on error. */ | |
425 | int (*elf_backend_additional_program_headers) PARAMS ((bfd *)); | |
426 | ||
427 | /* This function is called to modify an existing segment map in a | |
428 | backend specific fashion. */ | |
429 | boolean (*elf_backend_modify_segment_map) PARAMS ((bfd *)); | |
fd0198f0 ILT |
430 | |
431 | /* The swapping table to use when dealing with ECOFF information. | |
432 | Used for the MIPS ELF .mdebug section. */ | |
433 | const struct ecoff_debug_swap *elf_backend_ecoff_debug_swap; | |
434 | ||
435 | /* Alternate EM_xxxx machine codes for this backend. */ | |
436 | int elf_machine_alt1; | |
437 | int elf_machine_alt2; | |
438 | ||
439 | const struct elf_size_info *s; | |
440 | ||
441 | unsigned want_got_plt : 1; | |
442 | unsigned plt_readonly : 1; | |
443 | unsigned want_plt_sym : 1; | |
444 | ||
445 | /* Put ELF and program headers in the first loadable segment. */ | |
446 | unsigned want_hdr_in_seg : 1; | |
447 | }; | |
448 | ||
449 | /* Information stored for each BFD section in an ELF file. This | |
450 | structure is allocated by elf_new_section_hook. */ | |
451 | ||
761f377f ILT |
452 | struct bfd_elf_section_data |
453 | { | |
fd0198f0 ILT |
454 | /* The ELF header for this section. */ |
455 | Elf_Internal_Shdr this_hdr; | |
456 | /* The ELF header for the reloc section associated with this | |
457 | section, if any. */ | |
458 | Elf_Internal_Shdr rel_hdr; | |
459 | /* The ELF section number of this section. Only used for an output | |
460 | file. */ | |
461 | int this_idx; | |
462 | /* The ELF section number of the reloc section associated with this | |
463 | section, if any. Only used for an output file. */ | |
464 | int rel_idx; | |
465 | /* Used by the backend linker to store the symbol hash table entries | |
466 | associated with relocs against global symbols. */ | |
467 | struct elf_link_hash_entry **rel_hashes; | |
468 | /* A pointer to the swapped relocs. If the section uses REL relocs, | |
469 | rather than RELA, all the r_addend fields will be zero. This | |
470 | pointer may be NULL. It is used by the backend linker. */ | |
471 | Elf_Internal_Rela *relocs; | |
472 | /* Used by the backend linker when generating a shared library to | |
473 | record the dynamic symbol index for a section symbol | |
474 | corresponding to this section. */ | |
475 | long dynindx; | |
761f377f ILT |
476 | /* A pointer available for the processor specific ELF backend. */ |
477 | PTR tdata; | |
fd0198f0 ILT |
478 | }; |
479 | ||
480 | #define elf_section_data(sec) ((struct bfd_elf_section_data*)sec->used_by_bfd) | |
481 | ||
482 | #define get_elf_backend_data(abfd) \ | |
483 | ((struct elf_backend_data *) (abfd)->xvec->backend_data) | |
484 | ||
485 | /* Some private data is stashed away for future use using the tdata pointer | |
486 | in the bfd structure. */ | |
487 | ||
488 | struct elf_obj_tdata | |
489 | { | |
490 | Elf_Internal_Ehdr elf_header[1]; /* Actual data, but ref like ptr */ | |
491 | Elf_Internal_Shdr **elf_sect_ptr; | |
492 | Elf_Internal_Phdr *phdr; | |
493 | struct elf_segment_map *segment_map; | |
494 | struct bfd_strtab_hash *strtab_ptr; | |
495 | int num_locals; | |
496 | int num_globals; | |
497 | asymbol **section_syms; /* STT_SECTION symbols for each section */ | |
498 | Elf_Internal_Shdr symtab_hdr; | |
499 | Elf_Internal_Shdr shstrtab_hdr; | |
500 | Elf_Internal_Shdr strtab_hdr; | |
501 | Elf_Internal_Shdr dynsymtab_hdr; | |
502 | Elf_Internal_Shdr dynstrtab_hdr; | |
503 | unsigned int symtab_section, shstrtab_section; | |
504 | unsigned int strtab_section, dynsymtab_section; | |
505 | file_ptr next_file_pos; | |
506 | void *prstatus; /* The raw /proc prstatus structure */ | |
507 | void *prpsinfo; /* The raw /proc prpsinfo structure */ | |
508 | bfd_vma gp; /* The gp value (MIPS only, for now) */ | |
509 | unsigned int gp_size; /* The gp size (MIPS only, for now) */ | |
510 | ||
511 | /* This is set to true if the object was created by the backend | |
512 | linker. */ | |
513 | boolean linker; | |
514 | ||
515 | /* A mapping from external symbols to entries in the linker hash | |
516 | table, used when linking. This is indexed by the symbol index | |
517 | minus the sh_info field of the symbol table header. */ | |
518 | struct elf_link_hash_entry **sym_hashes; | |
519 | ||
520 | /* A mapping from local symbols to offsets into the global offset | |
521 | table, used when linking. This is indexed by the symbol index. */ | |
522 | bfd_vma *local_got_offsets; | |
523 | ||
524 | /* The linker ELF emulation code needs to let the backend ELF linker | |
525 | know what filename should be used for a dynamic object if the | |
526 | dynamic object is found using a search. This field is used to | |
527 | hold that information. */ | |
528 | const char *dt_needed_name; | |
529 | ||
530 | /* Irix 5 often screws up the symbol table, sorting local symbols | |
531 | after global symbols. This flag is set if the symbol table in | |
532 | this BFD appears to be screwed up. If it is, we ignore the | |
533 | sh_info field in the symbol table header, and always read all the | |
534 | symbols. */ | |
535 | boolean bad_symtab; | |
536 | ||
537 | /* Records the result of `get_program_header_size'. */ | |
538 | bfd_size_type program_header_size; | |
539 | ||
540 | /* Used by MIPS ELF find_nearest_line entry point. The structure | |
541 | could be included directly in this one, but there's no point to | |
542 | wasting the memory just for the infrequently called | |
543 | find_nearest_line. */ | |
544 | struct mips_elf_find_line *find_line_info; | |
545 | ||
761f377f ILT |
546 | /* Used to determine if the e_flags field has been initialized */ |
547 | boolean flags_init; | |
fd0198f0 ILT |
548 | }; |
549 | ||
550 | #define elf_tdata(bfd) ((bfd) -> tdata.elf_obj_data) | |
551 | #define elf_elfheader(bfd) (elf_tdata(bfd) -> elf_header) | |
552 | #define elf_elfsections(bfd) (elf_tdata(bfd) -> elf_sect_ptr) | |
553 | #define elf_shstrtab(bfd) (elf_tdata(bfd) -> strtab_ptr) | |
554 | #define elf_onesymtab(bfd) (elf_tdata(bfd) -> symtab_section) | |
555 | #define elf_dynsymtab(bfd) (elf_tdata(bfd) -> dynsymtab_section) | |
556 | #define elf_num_locals(bfd) (elf_tdata(bfd) -> num_locals) | |
557 | #define elf_num_globals(bfd) (elf_tdata(bfd) -> num_globals) | |
558 | #define elf_section_syms(bfd) (elf_tdata(bfd) -> section_syms) | |
559 | #define core_prpsinfo(bfd) (elf_tdata(bfd) -> prpsinfo) | |
560 | #define core_prstatus(bfd) (elf_tdata(bfd) -> prstatus) | |
561 | #define elf_gp(bfd) (elf_tdata(bfd) -> gp) | |
562 | #define elf_gp_size(bfd) (elf_tdata(bfd) -> gp_size) | |
563 | #define elf_sym_hashes(bfd) (elf_tdata(bfd) -> sym_hashes) | |
564 | #define elf_local_got_offsets(bfd) (elf_tdata(bfd) -> local_got_offsets) | |
565 | #define elf_dt_needed_name(bfd) (elf_tdata(bfd) -> dt_needed_name) | |
566 | #define elf_bad_symtab(bfd) (elf_tdata(bfd) -> bad_symtab) | |
761f377f | 567 | #define elf_flags_init(bfd) (elf_tdata(bfd) -> flags_init) |
fd0198f0 | 568 | \f |
98bb57ad ILT |
569 | extern int _bfd_elf_section_from_bfd_section PARAMS ((bfd *, asection *)); |
570 | extern char *bfd_elf_string_from_elf_section | |
571 | PARAMS ((bfd *, unsigned, unsigned)); | |
572 | extern char *bfd_elf_get_str_section PARAMS ((bfd *, unsigned)); | |
fd0198f0 | 573 | |
761f377f | 574 | extern boolean _bfd_elf_print_private_bfd_data PARAMS ((bfd *, PTR)); |
fd0198f0 ILT |
575 | extern void bfd_elf_print_symbol PARAMS ((bfd *, PTR, asymbol *, |
576 | bfd_print_symbol_type)); | |
577 | #define elf_string_from_elf_strtab(abfd,strindex) \ | |
578 | bfd_elf_string_from_elf_section(abfd,elf_elfheader(abfd)->e_shstrndx,strindex) | |
579 | ||
580 | #define bfd_elf32_print_symbol bfd_elf_print_symbol | |
581 | #define bfd_elf64_print_symbol bfd_elf_print_symbol | |
582 | #define bfd_elf32_mkobject bfd_elf_mkobject | |
583 | #define bfd_elf64_mkobject bfd_elf_mkobject | |
584 | #define elf_mkobject bfd_elf_mkobject | |
585 | ||
586 | extern unsigned long bfd_elf_hash PARAMS ((CONST unsigned char *)); | |
587 | ||
588 | extern bfd_reloc_status_type bfd_elf_generic_reloc PARAMS ((bfd *, | |
589 | arelent *, | |
590 | asymbol *, | |
591 | PTR, | |
592 | asection *, | |
593 | bfd *, | |
594 | char **)); | |
595 | extern boolean bfd_elf_mkobject PARAMS ((bfd *)); | |
596 | extern Elf_Internal_Shdr *bfd_elf_find_section PARAMS ((bfd *, char *)); | |
597 | extern boolean _bfd_elf_make_section_from_shdr | |
598 | PARAMS ((bfd *abfd, Elf_Internal_Shdr *hdr, const char *name)); | |
599 | extern struct bfd_hash_entry *_bfd_elf_link_hash_newfunc | |
600 | PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *)); | |
601 | extern struct bfd_link_hash_table *_bfd_elf_link_hash_table_create | |
602 | PARAMS ((bfd *)); | |
603 | extern boolean _bfd_elf_link_hash_table_init | |
604 | PARAMS ((struct elf_link_hash_table *, bfd *, | |
605 | struct bfd_hash_entry *(*) (struct bfd_hash_entry *, | |
606 | struct bfd_hash_table *, | |
607 | const char *))); | |
608 | ||
609 | extern boolean _bfd_elf_copy_private_symbol_data | |
610 | PARAMS ((bfd *, asymbol *, bfd *, asymbol *)); | |
611 | extern boolean _bfd_elf_copy_private_section_data | |
612 | PARAMS ((bfd *, asection *, bfd *, asection *)); | |
613 | extern boolean _bfd_elf_write_object_contents PARAMS ((bfd *)); | |
614 | extern boolean _bfd_elf_set_section_contents PARAMS ((bfd *, sec_ptr, PTR, | |
615 | file_ptr, | |
616 | bfd_size_type)); | |
617 | extern long _bfd_elf_get_symtab_upper_bound PARAMS ((bfd *)); | |
618 | extern long _bfd_elf_get_symtab PARAMS ((bfd *, asymbol **)); | |
619 | extern long _bfd_elf_get_dynamic_symtab_upper_bound PARAMS ((bfd *)); | |
620 | extern long _bfd_elf_canonicalize_dynamic_symtab PARAMS ((bfd *, asymbol **)); | |
621 | extern long _bfd_elf_get_reloc_upper_bound PARAMS ((bfd *, sec_ptr)); | |
622 | extern long _bfd_elf_canonicalize_reloc PARAMS ((bfd *, sec_ptr, | |
623 | arelent **, asymbol **)); | |
624 | extern asymbol *_bfd_elf_make_empty_symbol PARAMS ((bfd *)); | |
625 | extern void _bfd_elf_get_symbol_info PARAMS ((bfd *, asymbol *, | |
626 | symbol_info *)); | |
627 | extern alent *_bfd_elf_get_lineno PARAMS ((bfd *, asymbol *)); | |
628 | extern boolean _bfd_elf_set_arch_mach PARAMS ((bfd *, enum bfd_architecture, | |
629 | unsigned long)); | |
630 | extern boolean _bfd_elf_find_nearest_line PARAMS ((bfd *, asection *, | |
631 | asymbol **, | |
632 | bfd_vma, CONST char **, | |
633 | CONST char **, | |
634 | unsigned int *)); | |
635 | #define _bfd_elf_read_minisymbols _bfd_generic_read_minisymbols | |
636 | #define _bfd_elf_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol | |
637 | extern int _bfd_elf_sizeof_headers PARAMS ((bfd *, boolean)); | |
638 | extern boolean _bfd_elf_new_section_hook PARAMS ((bfd *, asection *)); | |
639 | ||
640 | /* If the target doesn't have reloc handling written yet: */ | |
641 | extern void _bfd_elf_no_info_to_howto PARAMS ((bfd *, arelent *, | |
642 | Elf_Internal_Rela *)); | |
643 | ||
644 | asection *bfd_section_from_elf_index PARAMS ((bfd *, unsigned int)); | |
645 | boolean _bfd_elf_create_dynamic_sections PARAMS ((bfd *, | |
646 | struct bfd_link_info *)); | |
647 | struct bfd_strtab_hash *_bfd_elf_stringtab_init PARAMS ((void)); | |
648 | boolean | |
649 | _bfd_elf_link_record_dynamic_symbol PARAMS ((struct bfd_link_info *, | |
650 | struct elf_link_hash_entry *)); | |
651 | boolean | |
652 | _bfd_elf_compute_section_file_positions PARAMS ((bfd *, | |
653 | struct bfd_link_info *)); | |
654 | void _bfd_elf_assign_file_positions_for_relocs PARAMS ((bfd *)); | |
655 | file_ptr _bfd_elf_assign_file_position_for_section PARAMS ((Elf_Internal_Shdr *, | |
656 | file_ptr, | |
657 | boolean)); | |
658 | ||
659 | boolean _bfd_elf_create_dynamic_sections PARAMS ((bfd *, | |
660 | struct bfd_link_info *)); | |
661 | boolean _bfd_elf_create_got_section PARAMS ((bfd *, | |
662 | struct bfd_link_info *)); | |
663 | ||
664 | extern const bfd_target *bfd_elf32_object_p PARAMS ((bfd *)); | |
665 | extern const bfd_target *bfd_elf32_core_file_p PARAMS ((bfd *)); | |
666 | extern char *bfd_elf32_core_file_failing_command PARAMS ((bfd *)); | |
667 | extern int bfd_elf32_core_file_failing_signal PARAMS ((bfd *)); | |
668 | extern boolean bfd_elf32_core_file_matches_executable_p PARAMS ((bfd *, | |
669 | bfd *)); | |
670 | ||
671 | extern boolean bfd_elf32_bfd_link_add_symbols | |
672 | PARAMS ((bfd *, struct bfd_link_info *)); | |
673 | extern boolean bfd_elf32_bfd_final_link | |
674 | PARAMS ((bfd *, struct bfd_link_info *)); | |
675 | ||
676 | extern void bfd_elf32_swap_symbol_in | |
677 | PARAMS ((bfd *, Elf32_External_Sym *, Elf_Internal_Sym *)); | |
678 | extern void bfd_elf32_swap_symbol_out | |
679 | PARAMS ((bfd *, Elf_Internal_Sym *, PTR)); | |
680 | extern void bfd_elf32_swap_reloc_in | |
681 | PARAMS ((bfd *, Elf32_External_Rel *, Elf_Internal_Rel *)); | |
682 | extern void bfd_elf32_swap_reloc_out | |
683 | PARAMS ((bfd *, Elf_Internal_Rel *, Elf32_External_Rel *)); | |
684 | extern void bfd_elf32_swap_reloca_in | |
685 | PARAMS ((bfd *, Elf32_External_Rela *, Elf_Internal_Rela *)); | |
686 | extern void bfd_elf32_swap_reloca_out | |
687 | PARAMS ((bfd *, Elf_Internal_Rela *, Elf32_External_Rela *)); | |
688 | extern void bfd_elf32_swap_phdr_in | |
689 | PARAMS ((bfd *, Elf32_External_Phdr *, Elf_Internal_Phdr *)); | |
690 | extern void bfd_elf32_swap_phdr_out | |
691 | PARAMS ((bfd *, Elf_Internal_Phdr *, Elf32_External_Phdr *)); | |
692 | extern void bfd_elf32_swap_dyn_in | |
02fcd126 | 693 | PARAMS ((bfd *, const PTR, Elf_Internal_Dyn *)); |
fd0198f0 ILT |
694 | extern void bfd_elf32_swap_dyn_out |
695 | PARAMS ((bfd *, const Elf_Internal_Dyn *, Elf32_External_Dyn *)); | |
696 | extern boolean bfd_elf32_add_dynamic_entry | |
697 | PARAMS ((struct bfd_link_info *, bfd_vma, bfd_vma)); | |
698 | extern boolean bfd_elf32_link_create_dynamic_sections | |
699 | PARAMS ((bfd *, struct bfd_link_info *)); | |
700 | ||
701 | extern const bfd_target *bfd_elf64_object_p PARAMS ((bfd *)); | |
702 | extern const bfd_target *bfd_elf64_core_file_p PARAMS ((bfd *)); | |
703 | extern char *bfd_elf64_core_file_failing_command PARAMS ((bfd *)); | |
704 | extern int bfd_elf64_core_file_failing_signal PARAMS ((bfd *)); | |
705 | extern boolean bfd_elf64_core_file_matches_executable_p PARAMS ((bfd *, | |
706 | bfd *)); | |
707 | extern boolean bfd_elf64_bfd_link_add_symbols | |
708 | PARAMS ((bfd *, struct bfd_link_info *)); | |
709 | extern boolean bfd_elf64_bfd_final_link | |
710 | PARAMS ((bfd *, struct bfd_link_info *)); | |
711 | ||
712 | extern void bfd_elf64_swap_symbol_in | |
713 | PARAMS ((bfd *, Elf64_External_Sym *, Elf_Internal_Sym *)); | |
714 | extern void bfd_elf64_swap_symbol_out | |
715 | PARAMS ((bfd *, Elf_Internal_Sym *, PTR)); | |
716 | extern void bfd_elf64_swap_reloc_in | |
717 | PARAMS ((bfd *, Elf64_External_Rel *, Elf_Internal_Rel *)); | |
718 | extern void bfd_elf64_swap_reloc_out | |
719 | PARAMS ((bfd *, Elf_Internal_Rel *, Elf64_External_Rel *)); | |
720 | extern void bfd_elf64_swap_reloca_in | |
721 | PARAMS ((bfd *, Elf64_External_Rela *, Elf_Internal_Rela *)); | |
722 | extern void bfd_elf64_swap_reloca_out | |
723 | PARAMS ((bfd *, Elf_Internal_Rela *, Elf64_External_Rela *)); | |
724 | extern void bfd_elf64_swap_phdr_in | |
725 | PARAMS ((bfd *, Elf64_External_Phdr *, Elf_Internal_Phdr *)); | |
726 | extern void bfd_elf64_swap_phdr_out | |
727 | PARAMS ((bfd *, Elf_Internal_Phdr *, Elf64_External_Phdr *)); | |
728 | extern void bfd_elf64_swap_dyn_in | |
02fcd126 | 729 | PARAMS ((bfd *, const PTR, Elf_Internal_Dyn *)); |
fd0198f0 ILT |
730 | extern void bfd_elf64_swap_dyn_out |
731 | PARAMS ((bfd *, const Elf_Internal_Dyn *, Elf64_External_Dyn *)); | |
732 | extern boolean bfd_elf64_add_dynamic_entry | |
733 | PARAMS ((struct bfd_link_info *, bfd_vma, bfd_vma)); | |
734 | extern boolean bfd_elf64_link_create_dynamic_sections | |
735 | PARAMS ((bfd *, struct bfd_link_info *)); | |
736 | ||
737 | #define bfd_elf32_link_record_dynamic_symbol _bfd_elf_link_record_dynamic_symbol | |
738 | #define bfd_elf64_link_record_dynamic_symbol _bfd_elf_link_record_dynamic_symbol | |
739 | ||
740 | #endif /* _LIBELF_H_ */ |