* elfcode.h: Include bfdlink.h. Added several new functions to do
[deliverable/binutils-gdb.git] / bfd / libelf.h
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., 675 Mass Ave, Cambridge, MA 02139, 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
67 /* Constant information held for an ELF backend. */
68
69 struct elf_backend_data
70 {
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. */
74 int use_rela_p;
75
76 /* Whether this backend is 64 bits or not. FIXME: Who cares? */
77 int elf_64_p;
78
79 /* The architecture for this backend. */
80 enum bfd_architecture arch;
81
82 /* The ELF machine code (EM_xxxx) for this backend. */
83 int elf_machine_code;
84
85 /* The maximum page size for this backend. */
86 bfd_vma maxpagesize;
87
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
94 /* A function to translate an ELF RELA relocation to a BFD arelent
95 structure. */
96 void (*elf_info_to_howto) PARAMS ((bfd *, arelent *,
97 Elf_Internal_Rela *));
98
99 /* A function to translate an ELF REL relocation to a BFD arelent
100 structure. */
101 void (*elf_info_to_howto_rel) PARAMS ((bfd *, arelent *,
102 Elf_Internal_Rel *));
103
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
111 /* The remaining functions are hooks which are called only if they
112 are not NULL. */
113
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 *));
121
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 *));
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
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
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
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
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;
217 };
218
219 struct elf_sym_extra
220 {
221 int elf_sym_num; /* sym# after locals/globals are reordered */
222 };
223
224 typedef struct elf_sym_extra Elf_Sym_Extra;
225
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;
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
238 struct 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
248 struct elf_obj_tdata
249 {
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;
254 int num_locals;
255 int num_globals;
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) */
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;
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)
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)
293 \f
294 /* ELF linker hash table entries. */
295
296 struct 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
312 struct 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)))
323
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
336 extern char * elf_string_from_elf_section PARAMS ((bfd *, unsigned, unsigned));
337 extern 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
343 extern unsigned long bfd_elf_hash PARAMS ((CONST unsigned char *));
344
345 extern bfd_reloc_status_type bfd_elf_generic_reloc PARAMS ((bfd *,
346 arelent *,
347 asymbol *,
348 PTR,
349 asection *,
350 bfd *,
351 char **));
352 extern boolean bfd_elf_mkobject PARAMS ((bfd *));
353 extern Elf_Internal_Shdr *bfd_elf_find_section PARAMS ((bfd *, char *));
354
355 extern struct bfd_link_hash_table *_bfd_elf_link_hash_table_create
356 PARAMS ((bfd *));
357
358 extern boolean bfd_elf32_write_object_contents PARAMS ((bfd *));
359 extern boolean bfd_elf64_write_object_contents PARAMS ((bfd *));
360
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 *,
366 bfd *));
367 extern boolean bfd_elf32_set_section_contents PARAMS ((bfd *, sec_ptr, PTR,
368 file_ptr,
369 bfd_size_type));
370
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 *,
382 symbol_info *));
383 extern alent *bfd_elf32_get_lineno PARAMS ((bfd *, asymbol *));
384 extern boolean bfd_elf32_set_arch_mach PARAMS ((bfd *, enum bfd_architecture,
385 unsigned long));
386 extern boolean bfd_elf32_find_nearest_line PARAMS ((bfd *, asection *,
387 asymbol **,
388 bfd_vma, CONST char **,
389 CONST char **,
390 unsigned int *));
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 *));
398
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 *));
402
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 *,
408 bfd *));
409 extern boolean bfd_elf64_set_section_contents PARAMS ((bfd *, sec_ptr, PTR,
410 file_ptr,
411 bfd_size_type));
412
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 *,
424 symbol_info *));
425 extern alent *bfd_elf64_get_lineno PARAMS ((bfd *, asymbol *));
426 extern boolean bfd_elf64_set_arch_mach PARAMS ((bfd *, enum bfd_architecture,
427 unsigned long));
428 extern boolean bfd_elf64_find_nearest_line PARAMS ((bfd *, asection *,
429 asymbol **,
430 bfd_vma, CONST char **,
431 CONST char **,
432 unsigned int *));
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 *));
440
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 *));
444
445 #endif /* _LIBELF_H_ */
This page took 0.038812 seconds and 4 git commands to generate.