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