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 | ||
db232882 KR |
45 | typedef struct |
46 | { | |
47 | asymbol symbol; | |
268f94ac | 48 | Elf_Internal_Sym internal_elf_sym; |
db232882 KR |
49 | /* these are used for the generation of .stabX symbols (?) */ |
50 | short desc; | |
51 | unsigned char type; | |
52 | char other; | |
7050286d KR |
53 | union |
54 | { | |
55 | unsigned int hppa_arg_reloc; | |
56 | PTR any; | |
57 | } | |
58 | tc_data; | |
998ce1e0 KR |
59 | Elf32_External_Sym native_elf_sym; |
60 | } elf32_symbol_type; | |
db232882 | 61 | |
998ce1e0 KR |
62 | typedef struct |
63 | { | |
64 | asymbol symbol; | |
65 | Elf_Internal_Sym internal_elf_sym; | |
66 | /* these are used for the generation of .stabX symbols (?) */ | |
67 | short desc; | |
68 | unsigned char type; | |
69 | char other; | |
70 | union | |
71 | { | |
72 | unsigned int hppa_arg_reloc; | |
73 | PTR any; | |
74 | } | |
75 | tc_data; | |
76 | Elf64_External_Sym native_elf_sym; | |
77 | } elf64_symbol_type; | |
7050286d | 78 | |
268f94ac | 79 | struct elf_backend_data |
7050286d KR |
80 | { |
81 | int use_rela_p; | |
82 | int elf_64_p; | |
81187b54 | 83 | enum bfd_architecture arch; |
7050286d | 84 | void (*elf_info_to_howto) PARAMS ((bfd *, arelent *, |
268f94ac | 85 | Elf_Internal_Rela *)); |
7050286d | 86 | void (*elf_info_to_howto_rel) PARAMS ((bfd *, arelent *, |
268f94ac | 87 | Elf_Internal_Rel *)); |
d79ab07c | 88 | bfd_vma maxpagesize; |
32090b8e | 89 | void (*write_relocs) PARAMS ((bfd *, asection *, PTR)); |
db232882 | 90 | |
8e40bcd8 KR |
91 | /* @@ I really don't think this should be here. I don't know what |
92 | global_sym is supposed to be used for, but I doubt it's something | |
93 | that would be considered global, e.g., if you've got a program | |
94 | reading and writing many BFDs. My hunch is that it's specific to | |
95 | the output BFD. If not, put a comment here explaining why. */ | |
998ce1e0 KR |
96 | /* @@ Was pointer to elfNAME(symbol_type). This makes it size- |
97 | independent. */ | |
e2a422b8 KR |
98 | void (*elf_backend_symbol_processing) PARAMS ((bfd *, asymbol *)); |
99 | boolean (*elf_backend_symbol_table_processing) PARAMS ((bfd *, elf32_symbol_type *, int)); | |
100 | boolean (*elf_backend_section_processing) PARAMS ((bfd *, Elf32_Internal_Shdr *)); | |
101 | boolean (*elf_backend_section_from_shdr) PARAMS ((bfd *, Elf32_Internal_Shdr *, char *)); | |
102 | boolean (*elf_backend_fake_sections) PARAMS ((bfd *, Elf32_Internal_Shdr *, asection *)); | |
103 | boolean (*elf_backend_section_from_bfd_section) PARAMS ((bfd *, Elf32_Internal_Shdr *, asection *)); | |
81187b54 KR |
104 | }; |
105 | ||
d24928c0 KR |
106 | struct elf_sym_extra |
107 | { | |
108 | int elf_sym_num; /* sym# after locals/globals are reordered */ | |
109 | }; | |
110 | ||
111 | typedef struct elf_sym_extra Elf_Sym_Extra; | |
112 | ||
32090b8e KR |
113 | struct bfd_elf_arch_map { |
114 | enum bfd_architecture bfd_arch; | |
115 | int elf_arch; | |
116 | }; | |
117 | ||
118 | extern const struct bfd_elf_arch_map bfd_elf_arch_map[]; | |
119 | extern const int bfd_elf_arch_map_size; | |
120 | ||
121 | struct bfd_elf_section_data { | |
122 | Elf_Internal_Shdr this_hdr; | |
123 | Elf_Internal_Shdr rel_hdr; | |
124 | int this_idx, rel_idx; | |
125 | #if 0 | |
126 | Elf_Internal_Shdr str_hdr; | |
127 | int str_idx; | |
128 | #endif | |
129 | }; | |
130 | #define elf_section_data(sec) ((struct bfd_elf_section_data*)sec->used_by_bfd) | |
131 | #define shdr_name(abfd,shdr) (elf_shstrtab (abfd)->tab + (shdr)->sh_name) | |
132 | ||
133 | #define get_elf_backend_data(abfd) \ | |
134 | ((struct elf_backend_data *) (abfd)->xvec->backend_data) | |
135 | ||
136 | struct strtab | |
137 | { | |
138 | char *tab; | |
139 | int nentries; | |
140 | int length; | |
141 | }; | |
142 | ||
143 | /* Some private data is stashed away for future use using the tdata pointer | |
144 | in the bfd structure. */ | |
145 | ||
146 | struct elf_obj_tdata | |
147 | { | |
148 | Elf_Internal_Ehdr elf_header[1]; /* Actual data, but ref like ptr */ | |
149 | Elf_Internal_Shdr **elf_sect_ptr; | |
d79ab07c | 150 | Elf_Internal_Phdr *phdr; |
32090b8e KR |
151 | struct strtab *strtab_ptr; |
152 | int num_locals; | |
153 | int num_globals; | |
32090b8e KR |
154 | PTR raw_syms; /* Elf_External_Sym* */ |
155 | Elf_Internal_Sym *internal_syms; | |
156 | PTR symbols; /* elf_symbol_type */ | |
d24928c0 KR |
157 | Elf_Sym_Extra *sym_extra; |
158 | asymbol **section_syms; /* STT_SECTION symbols for each section */ | |
159 | int num_section_syms; /* number of section_syms allocated */ | |
32090b8e KR |
160 | Elf_Internal_Shdr symtab_hdr; |
161 | Elf_Internal_Shdr shstrtab_hdr; | |
162 | Elf_Internal_Shdr strtab_hdr; | |
163 | int symtab_section, shstrtab_section, strtab_section; | |
164 | file_ptr next_file_pos; | |
165 | void *prstatus; /* The raw /proc prstatus structure */ | |
166 | void *prpsinfo; /* The raw /proc prpsinfo structure */ | |
167 | }; | |
168 | ||
169 | #define elf_tdata(bfd) ((bfd) -> tdata.elf_obj_data) | |
170 | #define elf_elfheader(bfd) (elf_tdata(bfd) -> elf_header) | |
171 | #define elf_elfsections(bfd) (elf_tdata(bfd) -> elf_sect_ptr) | |
172 | #define elf_shstrtab(bfd) (elf_tdata(bfd) -> strtab_ptr) | |
173 | #define elf_onesymtab(bfd) (elf_tdata(bfd) -> symtab_section) | |
174 | #define elf_num_locals(bfd) (elf_tdata(bfd) -> num_locals) | |
175 | #define elf_num_globals(bfd) (elf_tdata(bfd) -> num_globals) | |
d24928c0 KR |
176 | #define elf_sym_extra(bfd) (elf_tdata(bfd) -> sym_extra) |
177 | #define elf_section_syms(bfd) (elf_tdata(bfd) -> section_syms) | |
178 | #define elf_num_section_syms(bfd) (elf_tdata(bfd) -> num_section_syms) | |
32090b8e KR |
179 | #define core_prpsinfo(bfd) (elf_tdata(bfd) -> prpsinfo) |
180 | #define core_prstatus(bfd) (elf_tdata(bfd) -> prstatus) | |
181 | #define obj_symbols(bfd) ((elf_symbol_type*)(elf_tdata(bfd) -> symbols)) | |
182 | #define obj_raw_syms(bfd) ((Elf_External_Sym*)(elf_tdata(bfd) -> raw_syms)) | |
183 | #define obj_internal_syms(bfd) (elf_tdata(bfd) -> internal_syms) | |
184 | ||
185 | extern char * elf_string_from_elf_section PARAMS ((bfd *, unsigned, unsigned)); | |
186 | extern char * elf_get_str_section PARAMS ((bfd *, unsigned)); | |
187 | ||
188 | #define bfd_elf32_mkobject bfd_elf_mkobject | |
189 | #define bfd_elf64_mkobject bfd_elf_mkobject | |
190 | #define elf_mkobject bfd_elf_mkobject | |
191 | ||
153cb9ad | 192 | extern unsigned long bfd_elf_hash PARAMS ((CONST unsigned char *)); |
7e37f9ff | 193 | |
32090b8e KR |
194 | extern bfd_reloc_status_type bfd_elf_generic_reloc PARAMS ((bfd *, |
195 | arelent *, | |
196 | asymbol *, | |
197 | PTR, | |
198 | asection *, | |
199 | bfd *)); | |
998ce1e0 | 200 | extern boolean bfd_elf_mkobject PARAMS ((bfd *)); |
e2a422b8 KR |
201 | extern Elf_Internal_Shdr *bfd_elf_find_section PARAMS ((bfd *, char *)); |
202 | ||
9942e684 | 203 | extern boolean bfd_elf32_write_object_contents PARAMS ((bfd *)); |
32090b8e KR |
204 | extern boolean bfd_elf64_write_object_contents PARAMS ((bfd *)); |
205 | ||
206 | extern bfd_target *bfd_elf32_object_p PARAMS ((bfd *)); | |
207 | extern bfd_target *bfd_elf32_core_file_p PARAMS ((bfd *)); | |
9942e684 KR |
208 | extern char *bfd_elf32_core_file_failing_command PARAMS ((bfd *)); |
209 | extern int bfd_elf32_core_file_failing_signal PARAMS ((bfd *)); | |
210 | extern boolean bfd_elf32_core_file_matches_executable_p PARAMS ((bfd *, | |
211 | bfd *)); | |
212 | extern boolean bfd_elf32_set_section_contents PARAMS ((bfd *, sec_ptr, PTR, | |
213 | file_ptr, | |
214 | bfd_size_type)); | |
7050286d | 215 | |
9942e684 KR |
216 | extern unsigned int bfd_elf32_get_symtab_upper_bound PARAMS ((bfd *)); |
217 | extern unsigned int bfd_elf32_get_symtab PARAMS ((bfd *, asymbol **)); | |
218 | extern unsigned int bfd_elf32_get_reloc_upper_bound PARAMS ((bfd *, sec_ptr)); | |
219 | extern unsigned int bfd_elf32_canonicalize_reloc PARAMS ((bfd *, sec_ptr, | |
220 | arelent **, | |
221 | asymbol **)); | |
222 | extern asymbol *bfd_elf32_make_empty_symbol PARAMS ((bfd *)); | |
223 | extern void bfd_elf32_print_symbol PARAMS ((bfd *, PTR, asymbol *, | |
224 | bfd_print_symbol_type)); | |
225 | extern void bfd_elf32_get_symbol_info PARAMS ((bfd *, asymbol *, | |
7050286d | 226 | symbol_info *)); |
9942e684 KR |
227 | extern alent *bfd_elf32_get_lineno PARAMS ((bfd *, asymbol *)); |
228 | extern boolean bfd_elf32_set_arch_mach PARAMS ((bfd *, enum bfd_architecture, | |
229 | unsigned long)); | |
230 | extern boolean bfd_elf32_find_nearest_line PARAMS ((bfd *, asection *, | |
231 | asymbol **, | |
232 | bfd_vma, CONST char **, | |
233 | CONST char **, | |
234 | unsigned int *)); | |
235 | extern int bfd_elf32_sizeof_headers PARAMS ((bfd *, boolean)); | |
32090b8e | 236 | extern void bfd_elf32__write_relocs PARAMS ((bfd *, asection *, PTR)); |
e6858d1b | 237 | extern boolean bfd_elf32_new_section_hook PARAMS ((bfd *, asection *)); |
81187b54 KR |
238 | |
239 | /* If the target doesn't have reloc handling written yet: */ | |
9942e684 KR |
240 | extern void bfd_elf32_no_info_to_howto PARAMS ((bfd *, arelent *, |
241 | Elf32_Internal_Rela *)); | |
db232882 | 242 | |
7d9bb6da KR |
243 | extern bfd_target *bfd_elf64_object_p PARAMS ((bfd *)); |
244 | extern bfd_target *bfd_elf64_core_file_p PARAMS ((bfd *)); | |
7d9bb6da KR |
245 | extern char *bfd_elf64_core_file_failing_command PARAMS ((bfd *)); |
246 | extern int bfd_elf64_core_file_failing_signal PARAMS ((bfd *)); | |
247 | extern boolean bfd_elf64_core_file_matches_executable_p PARAMS ((bfd *, | |
248 | bfd *)); | |
249 | extern boolean bfd_elf64_set_section_contents PARAMS ((bfd *, sec_ptr, PTR, | |
250 | file_ptr, | |
251 | bfd_size_type)); | |
252 | ||
253 | extern unsigned int bfd_elf64_get_symtab_upper_bound PARAMS ((bfd *)); | |
254 | extern unsigned int bfd_elf64_get_symtab PARAMS ((bfd *, asymbol **)); | |
255 | extern unsigned int bfd_elf64_get_reloc_upper_bound PARAMS ((bfd *, sec_ptr)); | |
256 | extern unsigned int bfd_elf64_canonicalize_reloc PARAMS ((bfd *, sec_ptr, | |
257 | arelent **, | |
258 | asymbol **)); | |
259 | extern asymbol *bfd_elf64_make_empty_symbol PARAMS ((bfd *)); | |
260 | extern void bfd_elf64_print_symbol PARAMS ((bfd *, PTR, asymbol *, | |
261 | bfd_print_symbol_type)); | |
262 | extern void bfd_elf64_get_symbol_info PARAMS ((bfd *, asymbol *, | |
263 | symbol_info *)); | |
264 | extern alent *bfd_elf64_get_lineno PARAMS ((bfd *, asymbol *)); | |
265 | extern boolean bfd_elf64_set_arch_mach PARAMS ((bfd *, enum bfd_architecture, | |
266 | unsigned long)); | |
267 | extern boolean bfd_elf64_find_nearest_line PARAMS ((bfd *, asection *, | |
268 | asymbol **, | |
269 | bfd_vma, CONST char **, | |
270 | CONST char **, | |
271 | unsigned int *)); | |
272 | extern int bfd_elf64_sizeof_headers PARAMS ((bfd *, boolean)); | |
32090b8e | 273 | extern void bfd_elf64__write_relocs PARAMS ((bfd *, asection *, PTR)); |
7d9bb6da KR |
274 | extern boolean bfd_elf64_new_section_hook PARAMS ((bfd *, asection *)); |
275 | ||
276 | /* If the target doesn't have reloc handling written yet: */ | |
277 | extern void bfd_elf64_no_info_to_howto PARAMS ((bfd *, arelent *, | |
278 | Elf64_Internal_Rela *)); | |
279 | ||
db232882 | 280 | #endif /* _LIBELF_H_ */ |