1 /* BFD back-end data structures for ELF files.
2 Copyright (C) 1992, 1993 Free Software Foundation, Inc.
3 Written by Cygnus Support.
5 This file is part of BFD, the Binary File Descriptor library.
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.
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.
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. */
24 #include "elf/common.h"
25 #include "elf/internal.h"
26 #include "elf/external.h"
29 /* If size isn't specified as 64 or 32, NAME macro should fail. */
32 #define NAME(x,y) CAT4(x,64,_,y)
35 #define NAME(x,y) CAT4(x,32,_,y)
40 #define NAME(x,y) CAT4(x,NOSIZE,_,y)
43 #define ElfNAME(X) NAME(Elf,X)
44 #define elfNAME(X) NAME(elf,X)
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. */
55 /* ELF symbol information. */
56 Elf_Internal_Sym internal_elf_sym
;
57 /* Backend specific information. */
60 unsigned int hppa_arg_reloc
;
67 /* Constant information held for an ELF backend. */
69 struct elf_backend_data
71 /* Whether the backend uses REL or RELA relocations. FIXME: some
72 ELF backends use both. When we need to support one, this whole
73 approach will need to be changed. */
76 /* Whether this backend is 64 bits or not. FIXME: Who cares? */
79 /* The architecture for this backend. */
80 enum bfd_architecture arch
;
82 /* The ELF machine code (EM_xxxx) for this backend. */
85 /* The maximum page size for this backend. */
88 /* This is true if the linker should act like collect and gather
89 global constructors and destructors by name. This is true for
90 MIPS ELF because the Irix 5 tools can not handle the .init
94 /* A function to translate an ELF RELA relocation to a BFD arelent
96 void (*elf_info_to_howto
) PARAMS ((bfd
*, arelent
*,
97 Elf_Internal_Rela
*));
99 /* A function to translate an ELF REL relocation to a BFD arelent
101 void (*elf_info_to_howto_rel
) PARAMS ((bfd
*, arelent
*,
102 Elf_Internal_Rel
*));
104 /* A function to determine whether a symbol is global when
105 partitioning the symbol table into local and global symbols.
106 This should be NULL for most targets, in which case the correct
107 thing will be done. MIPS ELF, at least on the Irix 5, has
108 special requirements. */
109 boolean (*elf_backend_sym_is_global
) PARAMS ((bfd
*, asymbol
*));
111 /* The remaining functions are hooks which are called only if they
114 /* A function to permit a backend specific check on whether a
115 particular BFD format is relevant for an object file, and to
116 permit the backend to set any global information it wishes. When
117 this is called elf_elfheader is set, but anything else should be
118 used with caution. If this returns false, the check_format
119 routine will return a bfd_error_wrong_format error. */
120 boolean (*elf_backend_object_p
) PARAMS ((bfd
*));
122 /* A function to do additional symbol processing when reading the
123 ELF symbol table. This is where any processor-specific special
124 section indices are handled. */
125 void (*elf_backend_symbol_processing
) PARAMS ((bfd
*, asymbol
*));
127 /* A function to do additional symbol processing after reading the
128 entire ELF symbol table. */
129 boolean (*elf_backend_symbol_table_processing
) PARAMS ((bfd
*,
133 /* A function to do additional processing on the ELF section header
134 just before writing it out. This is used to set the flags and
135 type fields for some sections, or to actually write out data for
137 boolean (*elf_backend_section_processing
) PARAMS ((bfd
*,
138 Elf32_Internal_Shdr
*));
140 /* A function to handle unusual section types when creating BFD
141 sections from ELF sections. */
142 boolean (*elf_backend_section_from_shdr
) PARAMS ((bfd
*,
143 Elf32_Internal_Shdr
*,
146 /* A function to set up the ELF section header for a BFD section in
147 preparation for writing it out. This is where the flags and type
148 fields are set for unusual sections. */
149 boolean (*elf_backend_fake_sections
) PARAMS ((bfd
*, Elf32_Internal_Shdr
*,
152 /* A function to get the ELF section index for a BFD section. If
153 this returns true, the section was found. If it is a normal ELF
154 section, *RETVAL should be left unchanged. If it is not a normal
155 ELF section *RETVAL should be set to the SHN_xxxx index. */
156 boolean (*elf_backend_section_from_bfd_section
)
157 PARAMS ((bfd
*, Elf32_Internal_Shdr
*, asection
*, int *retval
));
159 /* If this field is not NULL, it is called by the add_symbols phase
160 of a link just before adding a symbol to the global linker hash
161 table. It may modify any of the fields as it wishes. If *NAME
162 is set to NULL, the symbol will be skipped rather than being
163 added to the hash table. This function is responsible for
164 handling all processor dependent symbol bindings and section
165 indices, and must set at least *FLAGS and *SEC for each processor
166 dependent case; failure to do so will cause a link error. */
167 boolean (*elf_add_symbol_hook
)
168 PARAMS ((bfd
*abfd
, struct bfd_link_info
*info
,
169 const Elf_Internal_Sym
*, const char **name
,
170 flagword
*flags
, asection
**sec
, bfd_vma
*value
));
172 /* The RELOCATE_SECTION function is called by the ELF backend linker
173 to handle the relocations for a section.
175 The relocs are always passed as Rela structures; if the section
176 actually uses Rel structures, the r_addend field will always be
179 This function is responsible for adjust the section contents as
180 necessary, and (if using Rela relocs and generating a
181 relocateable output file) adjusting the reloc addend as
184 This function does not have to worry about setting the reloc
185 address or the reloc symbol index.
187 LOCAL_SYMS is a pointer to the swapped in local symbols.
189 LOCAL_SECTIONS is an array giving the section in the input file
190 corresponding to the st_shndx field of each local symbol.
192 The global hash table entry for the global symbols can be found
193 via elf_sym_hashes (input_bfd).
195 When generating relocateable output, this function must handle
196 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
197 going to be the section symbol corresponding to the output
198 section, which means that the addend must be adjusted
200 boolean (*elf_backend_relocate_section
)
201 PARAMS ((bfd
*output_bfd
, struct bfd_link_info
*info
,
202 bfd
*input_bfd
, asection
*input_section
, bfd_byte
*contents
,
203 Elf_Internal_Rela
*relocs
, Elf_Internal_Sym
*local_syms
,
204 asection
**local_sections
));
206 /* A function to do any beginning processing needed for the ELF file
207 before building the ELF headers and computing file positions. */
208 void (*elf_backend_begin_write_processing
) PARAMS ((bfd
*));
210 /* A function to do any final processing needed for the ELF file
211 before writing it out. */
212 void (*elf_backend_final_write_processing
) PARAMS ((bfd
*));
214 /* The swapping table to use when dealing with ECOFF information.
215 Used for the MIPS ELF .mdebug section. */
216 const struct ecoff_debug_swap
*elf_backend_ecoff_debug_swap
;
221 int elf_sym_num
; /* sym# after locals/globals are reordered */
224 typedef struct elf_sym_extra Elf_Sym_Extra
;
226 struct bfd_elf_section_data
{
227 Elf_Internal_Shdr this_hdr
;
228 Elf_Internal_Shdr rel_hdr
;
229 int this_idx
, rel_idx
;
230 struct elf_link_hash_entry
**rel_hashes
;
232 #define elf_section_data(sec) ((struct bfd_elf_section_data*)sec->used_by_bfd)
233 #define shdr_name(abfd,shdr) (elf_shstrtab (abfd)->tab + (shdr)->sh_name)
235 #define get_elf_backend_data(abfd) \
236 ((struct elf_backend_data *) (abfd)->xvec->backend_data)
245 /* Some private data is stashed away for future use using the tdata pointer
246 in the bfd structure. */
250 Elf_Internal_Ehdr elf_header
[1]; /* Actual data, but ref like ptr */
251 Elf_Internal_Shdr
**elf_sect_ptr
;
252 Elf_Internal_Phdr
*phdr
;
253 struct strtab
*strtab_ptr
;
256 Elf_Sym_Extra
*sym_extra
;
257 asymbol
**section_syms
; /* STT_SECTION symbols for each section */
258 int num_section_syms
; /* number of section_syms allocated */
259 Elf_Internal_Shdr symtab_hdr
;
260 Elf_Internal_Shdr shstrtab_hdr
;
261 Elf_Internal_Shdr strtab_hdr
;
262 Elf_Internal_Shdr dynsymtab_hdr
;
263 Elf_Internal_Shdr dynstrtab_hdr
;
264 int symtab_section
, shstrtab_section
, strtab_section
, dynsymtab_section
;
265 file_ptr next_file_pos
;
266 void *prstatus
; /* The raw /proc prstatus structure */
267 void *prpsinfo
; /* The raw /proc prpsinfo structure */
268 bfd_vma gp
; /* The gp value (MIPS only, for now) */
269 int gp_size
; /* The gp size (MIPS only, for now) */
271 /* A mapping from external symbols to entries in the linker hash
272 table, used when linking. This is indexed by the symbol index
273 minus the sh_info field of the symbol table header. */
274 struct elf_link_hash_entry
**sym_hashes
;
277 #define elf_tdata(bfd) ((bfd) -> tdata.elf_obj_data)
278 #define elf_elfheader(bfd) (elf_tdata(bfd) -> elf_header)
279 #define elf_elfsections(bfd) (elf_tdata(bfd) -> elf_sect_ptr)
280 #define elf_shstrtab(bfd) (elf_tdata(bfd) -> strtab_ptr)
281 #define elf_onesymtab(bfd) (elf_tdata(bfd) -> symtab_section)
282 #define elf_dynsymtab(bfd) (elf_tdata(bfd) -> dynsymtab_section)
283 #define elf_num_locals(bfd) (elf_tdata(bfd) -> num_locals)
284 #define elf_num_globals(bfd) (elf_tdata(bfd) -> num_globals)
285 #define elf_sym_extra(bfd) (elf_tdata(bfd) -> sym_extra)
286 #define elf_section_syms(bfd) (elf_tdata(bfd) -> section_syms)
287 #define elf_num_section_syms(bfd) (elf_tdata(bfd) -> num_section_syms)
288 #define core_prpsinfo(bfd) (elf_tdata(bfd) -> prpsinfo)
289 #define core_prstatus(bfd) (elf_tdata(bfd) -> prstatus)
290 #define elf_gp(bfd) (elf_tdata(bfd) -> gp)
291 #define elf_gp_size(bfd) (elf_tdata(bfd) -> gp_size)
292 #define elf_sym_hashes(bfd) (elf_tdata(bfd) -> sym_hashes)
294 /* ELF linker hash table entries. */
296 struct elf_link_hash_entry
298 struct bfd_link_hash_entry root
;
299 /* Symbol index in output file. This is initialized to -1. It is
300 set to -2 if the symbol is used by a reloc. */
304 /* Symbol alignment (common symbols only). */
305 unsigned short align
;
306 /* Symbol type (STT_NOTYPE, STT_OBJECT, etc.). */
310 /* ELF linker hash table. */
312 struct elf_link_hash_table
314 struct bfd_link_hash_table root
;
317 /* Look up an entry in an ELF linker hash table. */
319 #define elf_link_hash_lookup(table, string, create, copy, follow) \
320 ((struct elf_link_hash_entry *) \
321 bfd_link_hash_lookup (&(table)->root, (string), (create), \
324 /* Traverse an ELF linker hash table. */
326 #define elf_link_hash_traverse(table, func, info) \
327 (bfd_link_hash_traverse \
329 (boolean (*) PARAMS ((struct bfd_link_hash_entry *, PTR))) (func), \
332 /* Get the ELF linker hash table from a link_info structure. */
334 #define elf_hash_table(p) ((struct elf_link_hash_table *) ((p)->hash))
336 extern char * elf_string_from_elf_section
PARAMS ((bfd
*, unsigned, unsigned));
337 extern char * elf_get_str_section
PARAMS ((bfd
*, unsigned));
339 #define bfd_elf32_mkobject bfd_elf_mkobject
340 #define bfd_elf64_mkobject bfd_elf_mkobject
341 #define elf_mkobject bfd_elf_mkobject
343 extern unsigned long bfd_elf_hash
PARAMS ((CONST
unsigned char *));
345 extern bfd_reloc_status_type bfd_elf_generic_reloc
PARAMS ((bfd
*,
352 extern boolean bfd_elf_mkobject
PARAMS ((bfd
*));
353 extern Elf_Internal_Shdr
*bfd_elf_find_section
PARAMS ((bfd
*, char *));
355 extern struct bfd_link_hash_table
*_bfd_elf_link_hash_table_create
358 extern boolean bfd_elf32_write_object_contents
PARAMS ((bfd
*));
359 extern boolean bfd_elf64_write_object_contents
PARAMS ((bfd
*));
361 extern bfd_target
*bfd_elf32_object_p
PARAMS ((bfd
*));
362 extern bfd_target
*bfd_elf32_core_file_p
PARAMS ((bfd
*));
363 extern char *bfd_elf32_core_file_failing_command
PARAMS ((bfd
*));
364 extern int bfd_elf32_core_file_failing_signal
PARAMS ((bfd
*));
365 extern boolean bfd_elf32_core_file_matches_executable_p
PARAMS ((bfd
*,
367 extern boolean bfd_elf32_set_section_contents
PARAMS ((bfd
*, sec_ptr
, PTR
,
371 extern long bfd_elf32_get_symtab_upper_bound
PARAMS ((bfd
*));
372 extern long bfd_elf32_get_symtab
PARAMS ((bfd
*, asymbol
**));
373 extern long bfd_elf32_get_dynamic_symtab_upper_bound
PARAMS ((bfd
*));
374 extern long bfd_elf32_canonicalize_dynamic_symtab
PARAMS ((bfd
*, asymbol
**));
375 extern long bfd_elf32_get_reloc_upper_bound
PARAMS ((bfd
*, sec_ptr
));
376 extern long bfd_elf32_canonicalize_reloc
PARAMS ((bfd
*, sec_ptr
,
377 arelent
**, asymbol
**));
378 extern asymbol
*bfd_elf32_make_empty_symbol
PARAMS ((bfd
*));
379 extern void bfd_elf32_print_symbol
PARAMS ((bfd
*, PTR
, asymbol
*,
380 bfd_print_symbol_type
));
381 extern void bfd_elf32_get_symbol_info
PARAMS ((bfd
*, asymbol
*,
383 extern alent
*bfd_elf32_get_lineno
PARAMS ((bfd
*, asymbol
*));
384 extern boolean bfd_elf32_set_arch_mach
PARAMS ((bfd
*, enum bfd_architecture
,
386 extern boolean bfd_elf32_find_nearest_line
PARAMS ((bfd
*, asection
*,
388 bfd_vma
, CONST
char **,
391 extern int bfd_elf32_sizeof_headers
PARAMS ((bfd
*, boolean
));
392 extern void bfd_elf32__write_relocs
PARAMS ((bfd
*, asection
*, PTR
));
393 extern boolean bfd_elf32_new_section_hook
PARAMS ((bfd
*, asection
*));
394 extern boolean bfd_elf32_bfd_link_add_symbols
395 PARAMS ((bfd
*, struct bfd_link_info
*));
396 extern boolean bfd_elf32_bfd_final_link
397 PARAMS ((bfd
*, struct bfd_link_info
*));
399 /* If the target doesn't have reloc handling written yet: */
400 extern void bfd_elf32_no_info_to_howto
PARAMS ((bfd
*, arelent
*,
401 Elf32_Internal_Rela
*));
403 extern bfd_target
*bfd_elf64_object_p
PARAMS ((bfd
*));
404 extern bfd_target
*bfd_elf64_core_file_p
PARAMS ((bfd
*));
405 extern char *bfd_elf64_core_file_failing_command
PARAMS ((bfd
*));
406 extern int bfd_elf64_core_file_failing_signal
PARAMS ((bfd
*));
407 extern boolean bfd_elf64_core_file_matches_executable_p
PARAMS ((bfd
*,
409 extern boolean bfd_elf64_set_section_contents
PARAMS ((bfd
*, sec_ptr
, PTR
,
413 extern long bfd_elf64_get_symtab_upper_bound
PARAMS ((bfd
*));
414 extern long bfd_elf64_get_symtab
PARAMS ((bfd
*, asymbol
**));
415 extern long bfd_elf64_get_dynamic_symtab_upper_bound
PARAMS ((bfd
*));
416 extern long bfd_elf64_canonicalize_dynamic_symtab
PARAMS ((bfd
*, asymbol
**));
417 extern long bfd_elf64_get_reloc_upper_bound
PARAMS ((bfd
*, sec_ptr
));
418 extern long bfd_elf64_canonicalize_reloc
PARAMS ((bfd
*, sec_ptr
,
419 arelent
**, asymbol
**));
420 extern asymbol
*bfd_elf64_make_empty_symbol
PARAMS ((bfd
*));
421 extern void bfd_elf64_print_symbol
PARAMS ((bfd
*, PTR
, asymbol
*,
422 bfd_print_symbol_type
));
423 extern void bfd_elf64_get_symbol_info
PARAMS ((bfd
*, asymbol
*,
425 extern alent
*bfd_elf64_get_lineno
PARAMS ((bfd
*, asymbol
*));
426 extern boolean bfd_elf64_set_arch_mach
PARAMS ((bfd
*, enum bfd_architecture
,
428 extern boolean bfd_elf64_find_nearest_line
PARAMS ((bfd
*, asection
*,
430 bfd_vma
, CONST
char **,
433 extern int bfd_elf64_sizeof_headers
PARAMS ((bfd
*, boolean
));
434 extern void bfd_elf64__write_relocs
PARAMS ((bfd
*, asection
*, PTR
));
435 extern boolean bfd_elf64_new_section_hook
PARAMS ((bfd
*, asection
*));
436 extern boolean bfd_elf64_bfd_link_add_symbols
437 PARAMS ((bfd
*, struct bfd_link_info
*));
438 extern boolean bfd_elf64_bfd_final_link
439 PARAMS ((bfd
*, struct bfd_link_info
*));
441 /* If the target doesn't have reloc handling written yet: */
442 extern void bfd_elf64_no_info_to_howto
PARAMS ((bfd
*, arelent
*,
443 Elf64_Internal_Rela
*));
445 #endif /* _LIBELF_H_ */