]>
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. */ | |
98 | PTR global_sym; | |
81187b54 KR |
99 | }; |
100 | ||
d24928c0 KR |
101 | struct elf_sym_extra |
102 | { | |
103 | int elf_sym_num; /* sym# after locals/globals are reordered */ | |
104 | }; | |
105 | ||
106 | typedef struct elf_sym_extra Elf_Sym_Extra; | |
107 | ||
32090b8e KR |
108 | struct bfd_elf_arch_map { |
109 | enum bfd_architecture bfd_arch; | |
110 | int elf_arch; | |
111 | }; | |
112 | ||
113 | extern const struct bfd_elf_arch_map bfd_elf_arch_map[]; | |
114 | extern const int bfd_elf_arch_map_size; | |
115 | ||
116 | struct bfd_elf_section_data { | |
117 | Elf_Internal_Shdr this_hdr; | |
118 | Elf_Internal_Shdr rel_hdr; | |
119 | int this_idx, rel_idx; | |
120 | #if 0 | |
121 | Elf_Internal_Shdr str_hdr; | |
122 | int str_idx; | |
123 | #endif | |
124 | }; | |
125 | #define elf_section_data(sec) ((struct bfd_elf_section_data*)sec->used_by_bfd) | |
126 | #define shdr_name(abfd,shdr) (elf_shstrtab (abfd)->tab + (shdr)->sh_name) | |
127 | ||
128 | #define get_elf_backend_data(abfd) \ | |
129 | ((struct elf_backend_data *) (abfd)->xvec->backend_data) | |
130 | ||
131 | struct strtab | |
132 | { | |
133 | char *tab; | |
134 | int nentries; | |
135 | int length; | |
136 | }; | |
137 | ||
138 | /* Some private data is stashed away for future use using the tdata pointer | |
139 | in the bfd structure. */ | |
140 | ||
141 | struct elf_obj_tdata | |
142 | { | |
143 | Elf_Internal_Ehdr elf_header[1]; /* Actual data, but ref like ptr */ | |
144 | Elf_Internal_Shdr **elf_sect_ptr; | |
d79ab07c | 145 | Elf_Internal_Phdr *phdr; |
32090b8e KR |
146 | struct strtab *strtab_ptr; |
147 | int num_locals; | |
148 | int num_globals; | |
32090b8e KR |
149 | PTR raw_syms; /* Elf_External_Sym* */ |
150 | Elf_Internal_Sym *internal_syms; | |
151 | PTR symbols; /* elf_symbol_type */ | |
d24928c0 KR |
152 | Elf_Sym_Extra *sym_extra; |
153 | asymbol **section_syms; /* STT_SECTION symbols for each section */ | |
154 | int num_section_syms; /* number of section_syms allocated */ | |
32090b8e KR |
155 | Elf_Internal_Shdr symtab_hdr; |
156 | Elf_Internal_Shdr shstrtab_hdr; | |
157 | Elf_Internal_Shdr strtab_hdr; | |
158 | int symtab_section, shstrtab_section, strtab_section; | |
159 | file_ptr next_file_pos; | |
160 | void *prstatus; /* The raw /proc prstatus structure */ | |
161 | void *prpsinfo; /* The raw /proc prpsinfo structure */ | |
162 | }; | |
163 | ||
164 | #define elf_tdata(bfd) ((bfd) -> tdata.elf_obj_data) | |
165 | #define elf_elfheader(bfd) (elf_tdata(bfd) -> elf_header) | |
166 | #define elf_elfsections(bfd) (elf_tdata(bfd) -> elf_sect_ptr) | |
167 | #define elf_shstrtab(bfd) (elf_tdata(bfd) -> strtab_ptr) | |
168 | #define elf_onesymtab(bfd) (elf_tdata(bfd) -> symtab_section) | |
169 | #define elf_num_locals(bfd) (elf_tdata(bfd) -> num_locals) | |
170 | #define elf_num_globals(bfd) (elf_tdata(bfd) -> num_globals) | |
d24928c0 KR |
171 | #define elf_sym_extra(bfd) (elf_tdata(bfd) -> sym_extra) |
172 | #define elf_section_syms(bfd) (elf_tdata(bfd) -> section_syms) | |
173 | #define elf_num_section_syms(bfd) (elf_tdata(bfd) -> num_section_syms) | |
32090b8e KR |
174 | #define core_prpsinfo(bfd) (elf_tdata(bfd) -> prpsinfo) |
175 | #define core_prstatus(bfd) (elf_tdata(bfd) -> prstatus) | |
176 | #define obj_symbols(bfd) ((elf_symbol_type*)(elf_tdata(bfd) -> symbols)) | |
177 | #define obj_raw_syms(bfd) ((Elf_External_Sym*)(elf_tdata(bfd) -> raw_syms)) | |
178 | #define obj_internal_syms(bfd) (elf_tdata(bfd) -> internal_syms) | |
179 | ||
180 | extern char * elf_string_from_elf_section PARAMS ((bfd *, unsigned, unsigned)); | |
181 | extern char * elf_get_str_section PARAMS ((bfd *, unsigned)); | |
182 | ||
183 | #define bfd_elf32_mkobject bfd_elf_mkobject | |
184 | #define bfd_elf64_mkobject bfd_elf_mkobject | |
185 | #define elf_mkobject bfd_elf_mkobject | |
186 | ||
153cb9ad | 187 | extern unsigned long bfd_elf_hash PARAMS ((CONST unsigned char *)); |
7e37f9ff | 188 | |
32090b8e KR |
189 | extern bfd_reloc_status_type bfd_elf_generic_reloc PARAMS ((bfd *, |
190 | arelent *, | |
191 | asymbol *, | |
192 | PTR, | |
193 | asection *, | |
194 | bfd *)); | |
998ce1e0 | 195 | extern boolean bfd_elf_mkobject PARAMS ((bfd *)); |
9942e684 | 196 | extern boolean bfd_elf32_write_object_contents PARAMS ((bfd *)); |
32090b8e KR |
197 | extern boolean bfd_elf64_write_object_contents PARAMS ((bfd *)); |
198 | ||
199 | extern bfd_target *bfd_elf32_object_p PARAMS ((bfd *)); | |
200 | extern bfd_target *bfd_elf32_core_file_p PARAMS ((bfd *)); | |
9942e684 KR |
201 | extern char *bfd_elf32_core_file_failing_command PARAMS ((bfd *)); |
202 | extern int bfd_elf32_core_file_failing_signal PARAMS ((bfd *)); | |
203 | extern boolean bfd_elf32_core_file_matches_executable_p PARAMS ((bfd *, | |
204 | bfd *)); | |
205 | extern boolean bfd_elf32_set_section_contents PARAMS ((bfd *, sec_ptr, PTR, | |
206 | file_ptr, | |
207 | bfd_size_type)); | |
7050286d | 208 | |
9942e684 KR |
209 | extern unsigned int bfd_elf32_get_symtab_upper_bound PARAMS ((bfd *)); |
210 | extern unsigned int bfd_elf32_get_symtab PARAMS ((bfd *, asymbol **)); | |
211 | extern unsigned int bfd_elf32_get_reloc_upper_bound PARAMS ((bfd *, sec_ptr)); | |
212 | extern unsigned int bfd_elf32_canonicalize_reloc PARAMS ((bfd *, sec_ptr, | |
213 | arelent **, | |
214 | asymbol **)); | |
215 | extern asymbol *bfd_elf32_make_empty_symbol PARAMS ((bfd *)); | |
216 | extern void bfd_elf32_print_symbol PARAMS ((bfd *, PTR, asymbol *, | |
217 | bfd_print_symbol_type)); | |
218 | extern void bfd_elf32_get_symbol_info PARAMS ((bfd *, asymbol *, | |
7050286d | 219 | symbol_info *)); |
9942e684 KR |
220 | extern alent *bfd_elf32_get_lineno PARAMS ((bfd *, asymbol *)); |
221 | extern boolean bfd_elf32_set_arch_mach PARAMS ((bfd *, enum bfd_architecture, | |
222 | unsigned long)); | |
223 | extern boolean bfd_elf32_find_nearest_line PARAMS ((bfd *, asection *, | |
224 | asymbol **, | |
225 | bfd_vma, CONST char **, | |
226 | CONST char **, | |
227 | unsigned int *)); | |
228 | extern int bfd_elf32_sizeof_headers PARAMS ((bfd *, boolean)); | |
32090b8e | 229 | extern void bfd_elf32__write_relocs PARAMS ((bfd *, asection *, PTR)); |
e6858d1b | 230 | extern boolean bfd_elf32_new_section_hook PARAMS ((bfd *, asection *)); |
81187b54 KR |
231 | |
232 | /* If the target doesn't have reloc handling written yet: */ | |
9942e684 KR |
233 | extern void bfd_elf32_no_info_to_howto PARAMS ((bfd *, arelent *, |
234 | Elf32_Internal_Rela *)); | |
db232882 | 235 | |
7d9bb6da KR |
236 | extern bfd_target *bfd_elf64_object_p PARAMS ((bfd *)); |
237 | extern bfd_target *bfd_elf64_core_file_p PARAMS ((bfd *)); | |
7d9bb6da KR |
238 | extern char *bfd_elf64_core_file_failing_command PARAMS ((bfd *)); |
239 | extern int bfd_elf64_core_file_failing_signal PARAMS ((bfd *)); | |
240 | extern boolean bfd_elf64_core_file_matches_executable_p PARAMS ((bfd *, | |
241 | bfd *)); | |
242 | extern boolean bfd_elf64_set_section_contents PARAMS ((bfd *, sec_ptr, PTR, | |
243 | file_ptr, | |
244 | bfd_size_type)); | |
245 | ||
246 | extern unsigned int bfd_elf64_get_symtab_upper_bound PARAMS ((bfd *)); | |
247 | extern unsigned int bfd_elf64_get_symtab PARAMS ((bfd *, asymbol **)); | |
248 | extern unsigned int bfd_elf64_get_reloc_upper_bound PARAMS ((bfd *, sec_ptr)); | |
249 | extern unsigned int bfd_elf64_canonicalize_reloc PARAMS ((bfd *, sec_ptr, | |
250 | arelent **, | |
251 | asymbol **)); | |
252 | extern asymbol *bfd_elf64_make_empty_symbol PARAMS ((bfd *)); | |
253 | extern void bfd_elf64_print_symbol PARAMS ((bfd *, PTR, asymbol *, | |
254 | bfd_print_symbol_type)); | |
255 | extern void bfd_elf64_get_symbol_info PARAMS ((bfd *, asymbol *, | |
256 | symbol_info *)); | |
257 | extern alent *bfd_elf64_get_lineno PARAMS ((bfd *, asymbol *)); | |
258 | extern boolean bfd_elf64_set_arch_mach PARAMS ((bfd *, enum bfd_architecture, | |
259 | unsigned long)); | |
260 | extern boolean bfd_elf64_find_nearest_line PARAMS ((bfd *, asection *, | |
261 | asymbol **, | |
262 | bfd_vma, CONST char **, | |
263 | CONST char **, | |
264 | unsigned int *)); | |
265 | extern int bfd_elf64_sizeof_headers PARAMS ((bfd *, boolean)); | |
32090b8e | 266 | extern void bfd_elf64__write_relocs PARAMS ((bfd *, asection *, PTR)); |
7d9bb6da KR |
267 | extern boolean bfd_elf64_new_section_hook PARAMS ((bfd *, asection *)); |
268 | ||
269 | /* If the target doesn't have reloc handling written yet: */ | |
270 | extern void bfd_elf64_no_info_to_howto PARAMS ((bfd *, arelent *, | |
271 | Elf64_Internal_Rela *)); | |
272 | ||
db232882 | 273 | #endif /* _LIBELF_H_ */ |