]>
Commit | Line | Data |
---|---|---|
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 | ||
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 | ||
81187b54 KR |
24 | #include "elf/common.h" |
25 | #include "elf/internal.h" | |
26 | #include "elf/external.h" | |
27 | ||
998ce1e0 | 28 | /* If size isn't specified as 64 or 32, NAME macro should fail. */ |
9942e684 | 29 | #ifndef NAME |
7050286d | 30 | #if ARCH_SIZE==64 |
638616ca | 31 | #define NAME(x,y) CAT4(x,64,_,y) |
998ce1e0 KR |
32 | #endif |
33 | #if ARCH_SIZE==32 | |
638616ca | 34 | #define NAME(x,y) CAT4(x,32,_,y) |
9942e684 KR |
35 | #endif |
36 | #endif | |
37 | ||
153cb9ad KR |
38 | #ifndef NAME |
39 | #define NAME(x,y) CAT4(x,NOSIZE,_,y) | |
40 | #endif | |
41 | ||
638616ca KR |
42 | #define ElfNAME(X) NAME(Elf,X) |
43 | #define elfNAME(X) NAME(elf,X) | |
44 | ||
95469b02 ILT |
45 | /* Information held for an ELF symbol. The first field is the |
46 | corresponding asymbol. Every symbol is an ELF file is actually a | |
47 | pointer to this structure, although it is often handled as a | |
48 | pointer to an asymbol. */ | |
49 | ||
db232882 KR |
50 | typedef struct |
51 | { | |
95469b02 | 52 | /* The BFD symbol. */ |
db232882 | 53 | asymbol symbol; |
95469b02 | 54 | /* ELF symbol information. */ |
268f94ac | 55 | Elf_Internal_Sym internal_elf_sym; |
95469b02 | 56 | /* Backend specific information. */ |
7050286d KR |
57 | union |
58 | { | |
59 | unsigned int hppa_arg_reloc; | |
60 | PTR any; | |
61 | } | |
62 | tc_data; | |
ee8cb548 | 63 | } elf_symbol_type; |
7050286d | 64 | |
95469b02 ILT |
65 | /* Constant information held for an ELF backend. */ |
66 | ||
268f94ac | 67 | struct elf_backend_data |
7050286d | 68 | { |
95469b02 ILT |
69 | /* Whether the backend uses REL or RELA relocations. FIXME: some |
70 | ELF backends use both. When we need to support one, this whole | |
71 | approach will need to be changed. */ | |
7050286d | 72 | int use_rela_p; |
95469b02 ILT |
73 | |
74 | /* Whether this backend is 64 bits or not. FIXME: Who cares? */ | |
7050286d | 75 | int elf_64_p; |
95469b02 ILT |
76 | |
77 | /* The architecture for this backend. */ | |
81187b54 | 78 | enum bfd_architecture arch; |
95469b02 ILT |
79 | |
80 | /* The maximum page size for this backend. */ | |
81 | bfd_vma maxpagesize; | |
82 | ||
83 | /* A function to translate an ELF RELA relocation to a BFD arelent | |
84 | structure. */ | |
7050286d | 85 | void (*elf_info_to_howto) PARAMS ((bfd *, arelent *, |
268f94ac | 86 | Elf_Internal_Rela *)); |
95469b02 ILT |
87 | |
88 | /* A function to translate an ELF REL relocation to a BFD arelent | |
89 | structure. */ | |
7050286d | 90 | void (*elf_info_to_howto_rel) PARAMS ((bfd *, arelent *, |
268f94ac | 91 | Elf_Internal_Rel *)); |
db232882 | 92 | |
95469b02 ILT |
93 | /* The remaining functions are hooks which are called only if they |
94 | are not NULL. */ | |
95 | ||
96 | /* A function to do additional symbol processing when reading the | |
97 | ELF symbol table. This is where any processor-specific special | |
98 | section indices are handled. */ | |
e2a422b8 | 99 | void (*elf_backend_symbol_processing) PARAMS ((bfd *, asymbol *)); |
95469b02 ILT |
100 | |
101 | /* A function to do additional symbol processing after reading the | |
102 | entire ELF symbol table. */ | |
103 | boolean (*elf_backend_symbol_table_processing) PARAMS ((bfd *, | |
104 | elf_symbol_type *, | |
105 | int)); | |
106 | ||
107 | /* A function to do additional processing on the ELF section header | |
108 | just before writing it out. This is used to set the flags and | |
109 | type fields for some sections, or to actually write out data for | |
110 | unusual sections. */ | |
111 | boolean (*elf_backend_section_processing) PARAMS ((bfd *, | |
112 | Elf32_Internal_Shdr *)); | |
113 | ||
114 | /* A function to handle unusual section types when creating BFD | |
115 | sections from ELF sections. */ | |
116 | boolean (*elf_backend_section_from_shdr) PARAMS ((bfd *, | |
117 | Elf32_Internal_Shdr *, | |
118 | char *)); | |
119 | ||
120 | /* A function to set up the ELF section header for a BFD section in | |
121 | preparation for writing it out. This is where the flags and type | |
122 | fields are set for unusual sections. */ | |
123 | boolean (*elf_backend_fake_sections) PARAMS ((bfd *, Elf32_Internal_Shdr *, | |
124 | asection *)); | |
125 | ||
126 | /* A function to get the ELF section index for a BFD section. If | |
127 | this returns true, the section was found. If it is a normal ELF | |
128 | section, *RETVAL should be left unchanged. If it is not a normal | |
129 | ELF section *RETVAL should be set to the SHN_xxxx index. */ | |
130 | boolean (*elf_backend_section_from_bfd_section) | |
131 | PARAMS ((bfd *, Elf32_Internal_Shdr *, asection *, int *retval)); | |
132 | ||
133 | /* The swapping table to use when dealing with ECOFF information. | |
134 | Used for the MIPS ELF .mdebug section. */ | |
135 | const struct ecoff_debug_swap *elf_backend_ecoff_debug_swap; | |
81187b54 KR |
136 | }; |
137 | ||
d24928c0 KR |
138 | struct elf_sym_extra |
139 | { | |
140 | int elf_sym_num; /* sym# after locals/globals are reordered */ | |
141 | }; | |
142 | ||
143 | typedef struct elf_sym_extra Elf_Sym_Extra; | |
144 | ||
32090b8e KR |
145 | struct bfd_elf_arch_map { |
146 | enum bfd_architecture bfd_arch; | |
147 | int elf_arch; | |
148 | }; | |
149 | ||
150 | extern const struct bfd_elf_arch_map bfd_elf_arch_map[]; | |
151 | extern const int bfd_elf_arch_map_size; | |
152 | ||
153 | struct bfd_elf_section_data { | |
154 | Elf_Internal_Shdr this_hdr; | |
155 | Elf_Internal_Shdr rel_hdr; | |
156 | int this_idx, rel_idx; | |
32090b8e KR |
157 | }; |
158 | #define elf_section_data(sec) ((struct bfd_elf_section_data*)sec->used_by_bfd) | |
159 | #define shdr_name(abfd,shdr) (elf_shstrtab (abfd)->tab + (shdr)->sh_name) | |
160 | ||
161 | #define get_elf_backend_data(abfd) \ | |
162 | ((struct elf_backend_data *) (abfd)->xvec->backend_data) | |
163 | ||
164 | struct strtab | |
165 | { | |
166 | char *tab; | |
167 | int nentries; | |
168 | int length; | |
169 | }; | |
170 | ||
171 | /* Some private data is stashed away for future use using the tdata pointer | |
172 | in the bfd structure. */ | |
173 | ||
174 | struct elf_obj_tdata | |
175 | { | |
176 | Elf_Internal_Ehdr elf_header[1]; /* Actual data, but ref like ptr */ | |
177 | Elf_Internal_Shdr **elf_sect_ptr; | |
d79ab07c | 178 | Elf_Internal_Phdr *phdr; |
32090b8e KR |
179 | struct strtab *strtab_ptr; |
180 | int num_locals; | |
181 | int num_globals; | |
32090b8e | 182 | Elf_Internal_Sym *internal_syms; |
ee8cb548 | 183 | elf_symbol_type *symbols; /* elf_symbol_type */ |
d24928c0 KR |
184 | Elf_Sym_Extra *sym_extra; |
185 | asymbol **section_syms; /* STT_SECTION symbols for each section */ | |
186 | int num_section_syms; /* number of section_syms allocated */ | |
32090b8e KR |
187 | Elf_Internal_Shdr symtab_hdr; |
188 | Elf_Internal_Shdr shstrtab_hdr; | |
189 | Elf_Internal_Shdr strtab_hdr; | |
190 | int symtab_section, shstrtab_section, strtab_section; | |
191 | file_ptr next_file_pos; | |
192 | void *prstatus; /* The raw /proc prstatus structure */ | |
193 | void *prpsinfo; /* The raw /proc prpsinfo structure */ | |
d5a30a08 ILT |
194 | bfd_vma gp; /* The gp value (MIPS only, for now) */ |
195 | int gp_size; /* The gp size (MIPS only, for now) */ | |
32090b8e KR |
196 | }; |
197 | ||
198 | #define elf_tdata(bfd) ((bfd) -> tdata.elf_obj_data) | |
199 | #define elf_elfheader(bfd) (elf_tdata(bfd) -> elf_header) | |
200 | #define elf_elfsections(bfd) (elf_tdata(bfd) -> elf_sect_ptr) | |
201 | #define elf_shstrtab(bfd) (elf_tdata(bfd) -> strtab_ptr) | |
202 | #define elf_onesymtab(bfd) (elf_tdata(bfd) -> symtab_section) | |
203 | #define elf_num_locals(bfd) (elf_tdata(bfd) -> num_locals) | |
204 | #define elf_num_globals(bfd) (elf_tdata(bfd) -> num_globals) | |
d24928c0 KR |
205 | #define elf_sym_extra(bfd) (elf_tdata(bfd) -> sym_extra) |
206 | #define elf_section_syms(bfd) (elf_tdata(bfd) -> section_syms) | |
207 | #define elf_num_section_syms(bfd) (elf_tdata(bfd) -> num_section_syms) | |
32090b8e KR |
208 | #define core_prpsinfo(bfd) (elf_tdata(bfd) -> prpsinfo) |
209 | #define core_prstatus(bfd) (elf_tdata(bfd) -> prstatus) | |
ee8cb548 | 210 | #define obj_symbols(bfd) (elf_tdata(bfd) -> symbols) |
32090b8e | 211 | #define obj_internal_syms(bfd) (elf_tdata(bfd) -> internal_syms) |
d5a30a08 ILT |
212 | #define elf_gp(bfd) (elf_tdata(bfd) -> gp) |
213 | #define elf_gp_size(bfd) (elf_tdata(bfd) -> gp_size) | |
32090b8e KR |
214 | |
215 | extern char * elf_string_from_elf_section PARAMS ((bfd *, unsigned, unsigned)); | |
216 | extern char * elf_get_str_section PARAMS ((bfd *, unsigned)); | |
217 | ||
218 | #define bfd_elf32_mkobject bfd_elf_mkobject | |
219 | #define bfd_elf64_mkobject bfd_elf_mkobject | |
220 | #define elf_mkobject bfd_elf_mkobject | |
221 | ||
153cb9ad | 222 | extern unsigned long bfd_elf_hash PARAMS ((CONST unsigned char *)); |
7e37f9ff | 223 | |
32090b8e KR |
224 | extern bfd_reloc_status_type bfd_elf_generic_reloc PARAMS ((bfd *, |
225 | arelent *, | |
226 | asymbol *, | |
227 | PTR, | |
228 | asection *, | |
229 | bfd *)); | |
998ce1e0 | 230 | extern boolean bfd_elf_mkobject PARAMS ((bfd *)); |
e2a422b8 KR |
231 | extern Elf_Internal_Shdr *bfd_elf_find_section PARAMS ((bfd *, char *)); |
232 | ||
9942e684 | 233 | extern boolean bfd_elf32_write_object_contents PARAMS ((bfd *)); |
32090b8e KR |
234 | extern boolean bfd_elf64_write_object_contents PARAMS ((bfd *)); |
235 | ||
236 | extern bfd_target *bfd_elf32_object_p PARAMS ((bfd *)); | |
237 | extern bfd_target *bfd_elf32_core_file_p PARAMS ((bfd *)); | |
9942e684 KR |
238 | extern char *bfd_elf32_core_file_failing_command PARAMS ((bfd *)); |
239 | extern int bfd_elf32_core_file_failing_signal PARAMS ((bfd *)); | |
240 | extern boolean bfd_elf32_core_file_matches_executable_p PARAMS ((bfd *, | |
241 | bfd *)); | |
242 | extern boolean bfd_elf32_set_section_contents PARAMS ((bfd *, sec_ptr, PTR, | |
243 | file_ptr, | |
244 | bfd_size_type)); | |
7050286d | 245 | |
9942e684 KR |
246 | extern unsigned int bfd_elf32_get_symtab_upper_bound PARAMS ((bfd *)); |
247 | extern unsigned int bfd_elf32_get_symtab PARAMS ((bfd *, asymbol **)); | |
248 | extern unsigned int bfd_elf32_get_reloc_upper_bound PARAMS ((bfd *, sec_ptr)); | |
249 | extern unsigned int bfd_elf32_canonicalize_reloc PARAMS ((bfd *, sec_ptr, | |
250 | arelent **, | |
251 | asymbol **)); | |
252 | extern asymbol *bfd_elf32_make_empty_symbol PARAMS ((bfd *)); | |
253 | extern void bfd_elf32_print_symbol PARAMS ((bfd *, PTR, asymbol *, | |
254 | bfd_print_symbol_type)); | |
255 | extern void bfd_elf32_get_symbol_info PARAMS ((bfd *, asymbol *, | |
7050286d | 256 | symbol_info *)); |
9942e684 KR |
257 | extern alent *bfd_elf32_get_lineno PARAMS ((bfd *, asymbol *)); |
258 | extern boolean bfd_elf32_set_arch_mach PARAMS ((bfd *, enum bfd_architecture, | |
259 | unsigned long)); | |
260 | extern boolean bfd_elf32_find_nearest_line PARAMS ((bfd *, asection *, | |
261 | asymbol **, | |
262 | bfd_vma, CONST char **, | |
263 | CONST char **, | |
264 | unsigned int *)); | |
265 | extern int bfd_elf32_sizeof_headers PARAMS ((bfd *, boolean)); | |
32090b8e | 266 | extern void bfd_elf32__write_relocs PARAMS ((bfd *, asection *, PTR)); |
e6858d1b | 267 | extern boolean bfd_elf32_new_section_hook PARAMS ((bfd *, asection *)); |
81187b54 KR |
268 | |
269 | /* If the target doesn't have reloc handling written yet: */ | |
9942e684 KR |
270 | extern void bfd_elf32_no_info_to_howto PARAMS ((bfd *, arelent *, |
271 | Elf32_Internal_Rela *)); | |
db232882 | 272 | |
7d9bb6da KR |
273 | extern bfd_target *bfd_elf64_object_p PARAMS ((bfd *)); |
274 | extern bfd_target *bfd_elf64_core_file_p PARAMS ((bfd *)); | |
7d9bb6da KR |
275 | extern char *bfd_elf64_core_file_failing_command PARAMS ((bfd *)); |
276 | extern int bfd_elf64_core_file_failing_signal PARAMS ((bfd *)); | |
277 | extern boolean bfd_elf64_core_file_matches_executable_p PARAMS ((bfd *, | |
278 | bfd *)); | |
279 | extern boolean bfd_elf64_set_section_contents PARAMS ((bfd *, sec_ptr, PTR, | |
280 | file_ptr, | |
281 | bfd_size_type)); | |
282 | ||
283 | extern unsigned int bfd_elf64_get_symtab_upper_bound PARAMS ((bfd *)); | |
284 | extern unsigned int bfd_elf64_get_symtab PARAMS ((bfd *, asymbol **)); | |
285 | extern unsigned int bfd_elf64_get_reloc_upper_bound PARAMS ((bfd *, sec_ptr)); | |
286 | extern unsigned int bfd_elf64_canonicalize_reloc PARAMS ((bfd *, sec_ptr, | |
287 | arelent **, | |
288 | asymbol **)); | |
289 | extern asymbol *bfd_elf64_make_empty_symbol PARAMS ((bfd *)); | |
290 | extern void bfd_elf64_print_symbol PARAMS ((bfd *, PTR, asymbol *, | |
291 | bfd_print_symbol_type)); | |
292 | extern void bfd_elf64_get_symbol_info PARAMS ((bfd *, asymbol *, | |
293 | symbol_info *)); | |
294 | extern alent *bfd_elf64_get_lineno PARAMS ((bfd *, asymbol *)); | |
295 | extern boolean bfd_elf64_set_arch_mach PARAMS ((bfd *, enum bfd_architecture, | |
296 | unsigned long)); | |
297 | extern boolean bfd_elf64_find_nearest_line PARAMS ((bfd *, asection *, | |
298 | asymbol **, | |
299 | bfd_vma, CONST char **, | |
300 | CONST char **, | |
301 | unsigned int *)); | |
302 | extern int bfd_elf64_sizeof_headers PARAMS ((bfd *, boolean)); | |
32090b8e | 303 | extern void bfd_elf64__write_relocs PARAMS ((bfd *, asection *, PTR)); |
7d9bb6da KR |
304 | extern boolean bfd_elf64_new_section_hook PARAMS ((bfd *, asection *)); |
305 | ||
306 | /* If the target doesn't have reloc handling written yet: */ | |
307 | extern void bfd_elf64_no_info_to_howto PARAMS ((bfd *, arelent *, | |
308 | Elf64_Internal_Rela *)); | |
309 | ||
db232882 | 310 | #endif /* _LIBELF_H_ */ |