* elfcode.h: Include bfdlink.h. Added several new functions to do
[deliverable/binutils-gdb.git] / bfd / libelf.h
CommitLineData
db232882
KR
1/* BFD back-end data structures for ELF files.
2 Copyright (C) 1992, 1993 Free Software Foundation, Inc.
3 Written by Cygnus Support.
4
5This file is part of BFD, the Binary File Descriptor library.
6
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program; if not, write to the Free Software
19Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
20
21#ifndef _LIBELF_H_
22#define _LIBELF_H_ 1
23
81187b54
KR
24#include "elf/common.h"
25#include "elf/internal.h"
26#include "elf/external.h"
6ec3bb6a 27#include "bfdlink.h"
81187b54 28
998ce1e0 29/* If size isn't specified as 64 or 32, NAME macro should fail. */
9942e684 30#ifndef NAME
7050286d 31#if ARCH_SIZE==64
638616ca 32#define NAME(x,y) CAT4(x,64,_,y)
998ce1e0
KR
33#endif
34#if ARCH_SIZE==32
638616ca 35#define NAME(x,y) CAT4(x,32,_,y)
9942e684
KR
36#endif
37#endif
38
153cb9ad
KR
39#ifndef NAME
40#define NAME(x,y) CAT4(x,NOSIZE,_,y)
41#endif
42
638616ca
KR
43#define ElfNAME(X) NAME(Elf,X)
44#define elfNAME(X) NAME(elf,X)
45
95469b02
ILT
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
db232882
KR
51typedef struct
52{
95469b02 53 /* The BFD symbol. */
db232882 54 asymbol symbol;
95469b02 55 /* ELF symbol information. */
268f94ac 56 Elf_Internal_Sym internal_elf_sym;
95469b02 57 /* Backend specific information. */
7050286d
KR
58 union
59 {
60 unsigned int hppa_arg_reloc;
cf286547 61 PTR mips_extr;
7050286d
KR
62 PTR any;
63 }
64 tc_data;
ee8cb548 65} elf_symbol_type;
7050286d 66
95469b02
ILT
67/* Constant information held for an ELF backend. */
68
268f94ac 69struct elf_backend_data
7050286d 70{
95469b02
ILT
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. */
7050286d 74 int use_rela_p;
95469b02
ILT
75
76 /* Whether this backend is 64 bits or not. FIXME: Who cares? */
7050286d 77 int elf_64_p;
95469b02
ILT
78
79 /* The architecture for this backend. */
81187b54 80 enum bfd_architecture arch;
95469b02 81
a5ccdad1
ILT
82 /* The ELF machine code (EM_xxxx) for this backend. */
83 int elf_machine_code;
84
95469b02
ILT
85 /* The maximum page size for this backend. */
86 bfd_vma maxpagesize;
87
6ec3bb6a
ILT
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
91 section. */
92 boolean collect;
93
95469b02
ILT
94 /* A function to translate an ELF RELA relocation to a BFD arelent
95 structure. */
7050286d 96 void (*elf_info_to_howto) PARAMS ((bfd *, arelent *,
268f94ac 97 Elf_Internal_Rela *));
95469b02
ILT
98
99 /* A function to translate an ELF REL relocation to a BFD arelent
100 structure. */
7050286d 101 void (*elf_info_to_howto_rel) PARAMS ((bfd *, arelent *,
268f94ac 102 Elf_Internal_Rel *));
db232882 103
643e9fc7
ILT
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 *));
110
95469b02
ILT
111 /* The remaining functions are hooks which are called only if they
112 are not NULL. */
113
a5ccdad1
ILT
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
d1ad85a6 119 routine will return a bfd_error_wrong_format error. */
a5ccdad1
ILT
120 boolean (*elf_backend_object_p) PARAMS ((bfd *));
121
95469b02
ILT
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. */
e2a422b8 125 void (*elf_backend_symbol_processing) PARAMS ((bfd *, asymbol *));
95469b02
ILT
126
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 *,
130 elf_symbol_type *,
131 int));
132
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
136 unusual sections. */
137 boolean (*elf_backend_section_processing) PARAMS ((bfd *,
138 Elf32_Internal_Shdr *));
139
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 *,
144 char *));
145
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 *,
150 asection *));
151
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));
158
6ec3bb6a
ILT
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));
171
172 /* The RELOCATE_SECTION function is called by the ELF backend linker
173 to handle the relocations for a section.
174
175 The relocs are always passed as Rela structures; if the section
176 actually uses Rel structures, the r_addend field will always be
177 zero.
178
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
182 necessary.
183
184 This function does not have to worry about setting the reloc
185 address or the reloc symbol index.
186
187 LOCAL_SYMS is a pointer to the swapped in local symbols.
188
189 LOCAL_SECTIONS is an array giving the section in the input file
190 corresponding to the st_shndx field of each local symbol.
191
192 The global hash table entry for the global symbols can be found
193 via elf_sym_hashes (input_bfd).
194
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
199 accordingly. */
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));
205
99a6c761
JL
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 *));
209
643e9fc7
ILT
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 *));
213
95469b02
ILT
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;
81187b54
KR
217};
218
d24928c0
KR
219struct elf_sym_extra
220{
221 int elf_sym_num; /* sym# after locals/globals are reordered */
222};
223
224typedef struct elf_sym_extra Elf_Sym_Extra;
225
32090b8e
KR
226struct bfd_elf_section_data {
227 Elf_Internal_Shdr this_hdr;
228 Elf_Internal_Shdr rel_hdr;
229 int this_idx, rel_idx;
6ec3bb6a 230 struct elf_link_hash_entry **rel_hashes;
32090b8e
KR
231};
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)
234
235#define get_elf_backend_data(abfd) \
236 ((struct elf_backend_data *) (abfd)->xvec->backend_data)
237
238struct strtab
239{
240 char *tab;
241 int nentries;
242 int length;
243};
244
245/* Some private data is stashed away for future use using the tdata pointer
246 in the bfd structure. */
247
248struct elf_obj_tdata
249{
250 Elf_Internal_Ehdr elf_header[1]; /* Actual data, but ref like ptr */
251 Elf_Internal_Shdr **elf_sect_ptr;
d79ab07c 252 Elf_Internal_Phdr *phdr;
32090b8e
KR
253 struct strtab *strtab_ptr;
254 int num_locals;
255 int num_globals;
d24928c0
KR
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 */
32090b8e
KR
259 Elf_Internal_Shdr symtab_hdr;
260 Elf_Internal_Shdr shstrtab_hdr;
261 Elf_Internal_Shdr strtab_hdr;
cb71adf1
PS
262 Elf_Internal_Shdr dynsymtab_hdr;
263 Elf_Internal_Shdr dynstrtab_hdr;
264 int symtab_section, shstrtab_section, strtab_section, dynsymtab_section;
32090b8e
KR
265 file_ptr next_file_pos;
266 void *prstatus; /* The raw /proc prstatus structure */
267 void *prpsinfo; /* The raw /proc prpsinfo structure */
d5a30a08
ILT
268 bfd_vma gp; /* The gp value (MIPS only, for now) */
269 int gp_size; /* The gp size (MIPS only, for now) */
6ec3bb6a
ILT
270
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;
32090b8e
KR
275};
276
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)
cb71adf1 282#define elf_dynsymtab(bfd) (elf_tdata(bfd) -> dynsymtab_section)
32090b8e
KR
283#define elf_num_locals(bfd) (elf_tdata(bfd) -> num_locals)
284#define elf_num_globals(bfd) (elf_tdata(bfd) -> num_globals)
d24928c0
KR
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)
32090b8e
KR
288#define core_prpsinfo(bfd) (elf_tdata(bfd) -> prpsinfo)
289#define core_prstatus(bfd) (elf_tdata(bfd) -> prstatus)
d5a30a08
ILT
290#define elf_gp(bfd) (elf_tdata(bfd) -> gp)
291#define elf_gp_size(bfd) (elf_tdata(bfd) -> gp_size)
6ec3bb6a
ILT
292#define elf_sym_hashes(bfd) (elf_tdata(bfd) -> sym_hashes)
293\f
294/* ELF linker hash table entries. */
295
296struct elf_link_hash_entry
297{
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. */
301 long indx;
302 /* Symbol size. */
303 bfd_size_type size;
304 /* Symbol alignment (common symbols only). */
305 unsigned short align;
306 /* Symbol type (STT_NOTYPE, STT_OBJECT, etc.). */
307 char type;
308};
309
310/* ELF linker hash table. */
311
312struct elf_link_hash_table
313{
314 struct bfd_link_hash_table root;
315};
316
317/* Look up an entry in an ELF linker hash table. */
318
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), \
322 (copy), (follow)))
32090b8e 323
6ec3bb6a
ILT
324/* Traverse an ELF linker hash table. */
325
326#define elf_link_hash_traverse(table, func, info) \
327 (bfd_link_hash_traverse \
328 (&(table)->root, \
329 (boolean (*) PARAMS ((struct bfd_link_hash_entry *, PTR))) (func), \
330 (info)))
331
332/* Get the ELF linker hash table from a link_info structure. */
333
334#define elf_hash_table(p) ((struct elf_link_hash_table *) ((p)->hash))
335\f
32090b8e
KR
336extern char * elf_string_from_elf_section PARAMS ((bfd *, unsigned, unsigned));
337extern char * elf_get_str_section PARAMS ((bfd *, unsigned));
338
339#define bfd_elf32_mkobject bfd_elf_mkobject
340#define bfd_elf64_mkobject bfd_elf_mkobject
341#define elf_mkobject bfd_elf_mkobject
342
153cb9ad 343extern unsigned long bfd_elf_hash PARAMS ((CONST unsigned char *));
7e37f9ff 344
32090b8e
KR
345extern bfd_reloc_status_type bfd_elf_generic_reloc PARAMS ((bfd *,
346 arelent *,
347 asymbol *,
348 PTR,
349 asection *,
4c3721d5
ILT
350 bfd *,
351 char **));
998ce1e0 352extern boolean bfd_elf_mkobject PARAMS ((bfd *));
e2a422b8
KR
353extern Elf_Internal_Shdr *bfd_elf_find_section PARAMS ((bfd *, char *));
354
6ec3bb6a
ILT
355extern struct bfd_link_hash_table *_bfd_elf_link_hash_table_create
356 PARAMS ((bfd *));
357
9942e684 358extern boolean bfd_elf32_write_object_contents PARAMS ((bfd *));
32090b8e
KR
359extern boolean bfd_elf64_write_object_contents PARAMS ((bfd *));
360
361extern bfd_target *bfd_elf32_object_p PARAMS ((bfd *));
362extern bfd_target *bfd_elf32_core_file_p PARAMS ((bfd *));
9942e684
KR
363extern char *bfd_elf32_core_file_failing_command PARAMS ((bfd *));
364extern int bfd_elf32_core_file_failing_signal PARAMS ((bfd *));
365extern boolean bfd_elf32_core_file_matches_executable_p PARAMS ((bfd *,
366 bfd *));
367extern boolean bfd_elf32_set_section_contents PARAMS ((bfd *, sec_ptr, PTR,
368 file_ptr,
369 bfd_size_type));
7050286d 370
326e32d7
ILT
371extern long bfd_elf32_get_symtab_upper_bound PARAMS ((bfd *));
372extern long bfd_elf32_get_symtab PARAMS ((bfd *, asymbol **));
cb71adf1
PS
373extern long bfd_elf32_get_dynamic_symtab_upper_bound PARAMS ((bfd *));
374extern long bfd_elf32_canonicalize_dynamic_symtab PARAMS ((bfd *, asymbol **));
326e32d7
ILT
375extern long bfd_elf32_get_reloc_upper_bound PARAMS ((bfd *, sec_ptr));
376extern long bfd_elf32_canonicalize_reloc PARAMS ((bfd *, sec_ptr,
377 arelent **, asymbol **));
9942e684
KR
378extern asymbol *bfd_elf32_make_empty_symbol PARAMS ((bfd *));
379extern void bfd_elf32_print_symbol PARAMS ((bfd *, PTR, asymbol *,
380 bfd_print_symbol_type));
381extern void bfd_elf32_get_symbol_info PARAMS ((bfd *, asymbol *,
7050286d 382 symbol_info *));
9942e684
KR
383extern alent *bfd_elf32_get_lineno PARAMS ((bfd *, asymbol *));
384extern boolean bfd_elf32_set_arch_mach PARAMS ((bfd *, enum bfd_architecture,
385 unsigned long));
386extern boolean bfd_elf32_find_nearest_line PARAMS ((bfd *, asection *,
387 asymbol **,
388 bfd_vma, CONST char **,
389 CONST char **,
390 unsigned int *));
391extern int bfd_elf32_sizeof_headers PARAMS ((bfd *, boolean));
32090b8e 392extern void bfd_elf32__write_relocs PARAMS ((bfd *, asection *, PTR));
e6858d1b 393extern boolean bfd_elf32_new_section_hook PARAMS ((bfd *, asection *));
6ec3bb6a
ILT
394extern boolean bfd_elf32_bfd_link_add_symbols
395 PARAMS ((bfd *, struct bfd_link_info *));
396extern boolean bfd_elf32_bfd_final_link
397 PARAMS ((bfd *, struct bfd_link_info *));
81187b54
KR
398
399/* If the target doesn't have reloc handling written yet: */
9942e684
KR
400extern void bfd_elf32_no_info_to_howto PARAMS ((bfd *, arelent *,
401 Elf32_Internal_Rela *));
db232882 402
7d9bb6da
KR
403extern bfd_target *bfd_elf64_object_p PARAMS ((bfd *));
404extern bfd_target *bfd_elf64_core_file_p PARAMS ((bfd *));
7d9bb6da
KR
405extern char *bfd_elf64_core_file_failing_command PARAMS ((bfd *));
406extern int bfd_elf64_core_file_failing_signal PARAMS ((bfd *));
407extern boolean bfd_elf64_core_file_matches_executable_p PARAMS ((bfd *,
408 bfd *));
409extern boolean bfd_elf64_set_section_contents PARAMS ((bfd *, sec_ptr, PTR,
410 file_ptr,
411 bfd_size_type));
412
326e32d7
ILT
413extern long bfd_elf64_get_symtab_upper_bound PARAMS ((bfd *));
414extern long bfd_elf64_get_symtab PARAMS ((bfd *, asymbol **));
cb71adf1
PS
415extern long bfd_elf64_get_dynamic_symtab_upper_bound PARAMS ((bfd *));
416extern long bfd_elf64_canonicalize_dynamic_symtab PARAMS ((bfd *, asymbol **));
326e32d7
ILT
417extern long bfd_elf64_get_reloc_upper_bound PARAMS ((bfd *, sec_ptr));
418extern long bfd_elf64_canonicalize_reloc PARAMS ((bfd *, sec_ptr,
419 arelent **, asymbol **));
7d9bb6da
KR
420extern asymbol *bfd_elf64_make_empty_symbol PARAMS ((bfd *));
421extern void bfd_elf64_print_symbol PARAMS ((bfd *, PTR, asymbol *,
422 bfd_print_symbol_type));
423extern void bfd_elf64_get_symbol_info PARAMS ((bfd *, asymbol *,
424 symbol_info *));
425extern alent *bfd_elf64_get_lineno PARAMS ((bfd *, asymbol *));
426extern boolean bfd_elf64_set_arch_mach PARAMS ((bfd *, enum bfd_architecture,
427 unsigned long));
428extern boolean bfd_elf64_find_nearest_line PARAMS ((bfd *, asection *,
429 asymbol **,
430 bfd_vma, CONST char **,
431 CONST char **,
432 unsigned int *));
433extern int bfd_elf64_sizeof_headers PARAMS ((bfd *, boolean));
32090b8e 434extern void bfd_elf64__write_relocs PARAMS ((bfd *, asection *, PTR));
7d9bb6da 435extern boolean bfd_elf64_new_section_hook PARAMS ((bfd *, asection *));
6ec3bb6a
ILT
436extern boolean bfd_elf64_bfd_link_add_symbols
437 PARAMS ((bfd *, struct bfd_link_info *));
438extern boolean bfd_elf64_bfd_final_link
439 PARAMS ((bfd *, struct bfd_link_info *));
7d9bb6da
KR
440
441/* If the target doesn't have reloc handling written yet: */
442extern void bfd_elf64_no_info_to_howto PARAMS ((bfd *, arelent *,
443 Elf64_Internal_Rela *));
444
db232882 445#endif /* _LIBELF_H_ */
This page took 0.091793 seconds and 4 git commands to generate.