133965Sjdp/* libbfd.h -- Declarations used by bfd library *implementation*. 233965Sjdp (This include file is not for users of the library.) 3130561Sobrien 4130561Sobrien Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 5218822Sdim 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 6218822Sdim Free Software Foundation, Inc. 7130561Sobrien 833965Sjdp Written by Cygnus Support. 933965Sjdp 1033965SjdpThis file is part of BFD, the Binary File Descriptor library. 1133965Sjdp 1233965SjdpThis program is free software; you can redistribute it and/or modify 1333965Sjdpit under the terms of the GNU General Public License as published by 1433965Sjdpthe Free Software Foundation; either version 2 of the License, or 1533965Sjdp(at your option) any later version. 1633965Sjdp 1733965SjdpThis program is distributed in the hope that it will be useful, 1833965Sjdpbut WITHOUT ANY WARRANTY; without even the implied warranty of 1933965SjdpMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2033965SjdpGNU General Public License for more details. 2133965Sjdp 2233965SjdpYou should have received a copy of the GNU General Public License 2333965Sjdpalong with this program; if not, write to the Free Software 24218822SdimFoundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ 2533965Sjdp 26218822Sdim#include "hashtab.h" 27218822Sdim 2833965Sjdp/* Align an address upward to a boundary, expressed as a number of bytes. 2938889Sjdp E.g. align to an 8-byte boundary with argument of 8. Take care never 3038889Sjdp to wrap around if the address is within boundary-1 of the end of the 3138889Sjdp address space. */ 3289857Sobrien#define BFD_ALIGN(this, boundary) \ 3389857Sobrien ((((bfd_vma) (this) + (boundary) - 1) >= (bfd_vma) (this)) \ 3489857Sobrien ? (((bfd_vma) (this) + ((boundary) - 1)) & ~ (bfd_vma) ((boundary)-1)) \ 3538889Sjdp : ~ (bfd_vma) 0) 3633965Sjdp 3733965Sjdp/* If you want to read and write large blocks, you might want to do it 3833965Sjdp in quanta of this amount */ 3933965Sjdp#define DEFAULT_BUFFERSIZE 8192 4033965Sjdp 4133965Sjdp/* Set a tdata field. Can't use the other macros for this, since they 4233965Sjdp do casts, and casting to the left of assignment isn't portable. */ 43130561Sobrien#define set_tdata(bfd, v) ((bfd)->tdata.any = (v)) 4433965Sjdp 4533965Sjdp/* If BFD_IN_MEMORY is set for a BFD, then the iostream fields points 4633965Sjdp to an instance of this structure. */ 4733965Sjdp 4833965Sjdpstruct bfd_in_memory 4933965Sjdp{ 5033965Sjdp /* Size of buffer. */ 5133965Sjdp bfd_size_type size; 5233965Sjdp /* Buffer holding contents of BFD. */ 5333965Sjdp bfd_byte *buffer; 5433965Sjdp}; 5533965Sjdp 56218822Sdimstruct section_hash_entry 57218822Sdim{ 58218822Sdim struct bfd_hash_entry root; 59218822Sdim asection section; 60218822Sdim}; 61218822Sdim 6233965Sjdp/* tdata for an archive. For an input archive, cache 6333965Sjdp needs to be free()'d. For an output archive, symdefs do. */ 6433965Sjdp 6533965Sjdpstruct artdata { 6633965Sjdp file_ptr first_file_filepos; 6733965Sjdp /* Speed up searching the armap */ 68218822Sdim htab_t cache; 6977298Sobrien bfd *archive_head; /* Only interesting in output routines */ 7033965Sjdp carsym *symdefs; /* the symdef entries */ 7177298Sobrien symindex symdef_count; /* how many there are */ 7233965Sjdp char *extended_names; /* clever intel extension */ 73218822Sdim bfd_size_type extended_names_size; /* Size of extended names */ 74251227Spfg /* when more compilers are standard C, this can be a time_t */ 75251227Spfg long armap_timestamp; /* Timestamp value written into armap. 7633965Sjdp This is used for BSD archives to check 7733965Sjdp that the timestamp is recent enough 7833965Sjdp for the BSD linker to not complain, 7933965Sjdp just before we finish writing an 8033965Sjdp archive. */ 8133965Sjdp file_ptr armap_datepos; /* Position within archive to seek to 8233965Sjdp rewrite the date field. */ 83130561Sobrien void *tdata; /* Backend specific information. */ 8433965Sjdp}; 8533965Sjdp 8633965Sjdp#define bfd_ardata(bfd) ((bfd)->tdata.aout_ar_data) 8733965Sjdp 8833965Sjdp/* Goes in bfd's arelt_data slot */ 8933965Sjdpstruct areltdata { 9077298Sobrien char * arch_header; /* it's actually a string */ 9177298Sobrien unsigned int parsed_size; /* octets of filesize not including ar_hdr */ 9277298Sobrien char *filename; /* null-terminated */ 9333965Sjdp}; 9433965Sjdp 9533965Sjdp#define arelt_size(bfd) (((struct areltdata *)((bfd)->arelt_data))->parsed_size) 9633965Sjdp 97130561Sobrienextern void *bfd_malloc 98130561Sobrien (bfd_size_type); 99130561Sobrienextern void *bfd_realloc 100130561Sobrien (void *, bfd_size_type); 101130561Sobrienextern void *bfd_zmalloc 102130561Sobrien (bfd_size_type); 103218822Sdimextern void *bfd_malloc2 104218822Sdim (bfd_size_type, bfd_size_type); 105218822Sdimextern void *bfd_realloc2 106218822Sdim (void *, bfd_size_type, bfd_size_type); 107218822Sdimextern void *bfd_zmalloc2 108218822Sdim (bfd_size_type, bfd_size_type); 10933965Sjdp 110218822Sdimextern void _bfd_default_error_handler (const char *s, ...); 11133965Sjdpextern bfd_error_handler_type _bfd_error_handler; 11233965Sjdp 11333965Sjdp/* These routines allocate and free things on the BFD's objalloc. */ 11433965Sjdp 115130561Sobrienextern void *bfd_alloc 116130561Sobrien (bfd *, bfd_size_type); 117130561Sobrienextern void *bfd_zalloc 118130561Sobrien (bfd *, bfd_size_type); 119218822Sdimextern void *bfd_alloc2 120218822Sdim (bfd *, bfd_size_type, bfd_size_type); 121218822Sdimextern void *bfd_zalloc2 122218822Sdim (bfd *, bfd_size_type, bfd_size_type); 123130561Sobrienextern void bfd_release 124130561Sobrien (bfd *, void *); 12533965Sjdp 126130561Sobrienbfd * _bfd_create_empty_archive_element_shell 127130561Sobrien (bfd *obfd); 128130561Sobrienbfd * _bfd_look_for_bfd_in_cache 129130561Sobrien (bfd *, file_ptr); 130130561Sobrienbfd_boolean _bfd_add_bfd_to_archive_cache 131130561Sobrien (bfd *, file_ptr, bfd *); 132130561Sobrienbfd_boolean _bfd_generic_mkarchive 133130561Sobrien (bfd *abfd); 134130561Sobrienconst bfd_target *bfd_generic_archive_p 135130561Sobrien (bfd *abfd); 136130561Sobrienbfd_boolean bfd_slurp_armap 137130561Sobrien (bfd *abfd); 138130561Sobrienbfd_boolean bfd_slurp_bsd_armap_f2 139130561Sobrien (bfd *abfd); 14033965Sjdp#define bfd_slurp_bsd_armap bfd_slurp_armap 14133965Sjdp#define bfd_slurp_coff_armap bfd_slurp_armap 142130561Sobrienbfd_boolean _bfd_slurp_extended_name_table 143130561Sobrien (bfd *abfd); 144130561Sobrienextern bfd_boolean _bfd_construct_extended_name_table 145130561Sobrien (bfd *, bfd_boolean, char **, bfd_size_type *); 146130561Sobrienbfd_boolean _bfd_write_archive_contents 147130561Sobrien (bfd *abfd); 148130561Sobrienbfd_boolean _bfd_compute_and_write_armap 149130561Sobrien (bfd *, unsigned int elength); 150130561Sobrienbfd *_bfd_get_elt_at_filepos 151130561Sobrien (bfd *archive, file_ptr filepos); 152130561Sobrienextern bfd *_bfd_generic_get_elt_at_index 153130561Sobrien (bfd *, symindex); 154130561Sobrienbfd * _bfd_new_bfd 155130561Sobrien (void); 156130561Sobrienvoid _bfd_delete_bfd 157130561Sobrien (bfd *); 158218822Sdimbfd_boolean _bfd_free_cached_info 159218822Sdim (bfd *); 16033965Sjdp 161130561Sobrienbfd_boolean bfd_false 162130561Sobrien (bfd *ignore); 163130561Sobrienbfd_boolean bfd_true 164130561Sobrien (bfd *ignore); 165130561Sobrienvoid *bfd_nullvoidptr 166130561Sobrien (bfd *ignore); 167130561Sobrienint bfd_0 168130561Sobrien (bfd *ignore); 169130561Sobrienunsigned int bfd_0u 170130561Sobrien (bfd *ignore); 171130561Sobrienlong bfd_0l 172130561Sobrien (bfd *ignore); 173130561Sobrienlong _bfd_n1 174130561Sobrien (bfd *ignore); 175130561Sobrienvoid bfd_void 176130561Sobrien (bfd *ignore); 17733965Sjdp 178130561Sobrienbfd *_bfd_new_bfd_contained_in 179130561Sobrien (bfd *); 180130561Sobrienconst bfd_target *_bfd_dummy_target 181130561Sobrien (bfd *abfd); 18233965Sjdp 183130561Sobrienvoid bfd_dont_truncate_arname 184130561Sobrien (bfd *abfd, const char *filename, char *hdr); 185130561Sobrienvoid bfd_bsd_truncate_arname 186130561Sobrien (bfd *abfd, const char *filename, char *hdr); 187130561Sobrienvoid bfd_gnu_truncate_arname 188130561Sobrien (bfd *abfd, const char *filename, char *hdr); 18933965Sjdp 190130561Sobrienbfd_boolean bsd_write_armap 191130561Sobrien (bfd *arch, unsigned int elength, struct orl *map, unsigned int orl_count, 192130561Sobrien int stridx); 19333965Sjdp 194130561Sobrienbfd_boolean coff_write_armap 195130561Sobrien (bfd *arch, unsigned int elength, struct orl *map, unsigned int orl_count, 196130561Sobrien int stridx); 19733965Sjdp 198130561Sobrienextern void *_bfd_generic_read_ar_hdr 199130561Sobrien (bfd *); 200218822Sdimextern void _bfd_ar_spacepad 201218822Sdim (char *, size_t, const char *, long); 20233965Sjdp 203130561Sobrienextern void *_bfd_generic_read_ar_hdr_mag 204130561Sobrien (bfd *, const char *); 20533965Sjdp 206130561Sobrienbfd * bfd_generic_openr_next_archived_file 207130561Sobrien (bfd *archive, bfd *last_file); 20833965Sjdp 209130561Sobrienint bfd_generic_stat_arch_elt 210130561Sobrien (bfd *, struct stat *); 21133965Sjdp 21233965Sjdp#define _bfd_read_ar_hdr(abfd) \ 21333965Sjdp BFD_SEND (abfd, _bfd_read_ar_hdr_fn, (abfd)) 21433965Sjdp 21533965Sjdp/* Generic routines to use for BFD_JUMP_TABLE_GENERIC. Use 21633965Sjdp BFD_JUMP_TABLE_GENERIC (_bfd_generic). */ 21733965Sjdp 21833965Sjdp#define _bfd_generic_close_and_cleanup bfd_true 21933965Sjdp#define _bfd_generic_bfd_free_cached_info bfd_true 220218822Sdimextern bfd_boolean _bfd_generic_new_section_hook 221218822Sdim (bfd *, asection *); 222130561Sobrienextern bfd_boolean _bfd_generic_get_section_contents 223130561Sobrien (bfd *, asection *, void *, file_ptr, bfd_size_type); 224130561Sobrienextern bfd_boolean _bfd_generic_get_section_contents_in_window 225130561Sobrien (bfd *, asection *, bfd_window *, file_ptr, bfd_size_type); 22633965Sjdp 22733965Sjdp/* Generic routines to use for BFD_JUMP_TABLE_COPY. Use 22833965Sjdp BFD_JUMP_TABLE_COPY (_bfd_generic). */ 22933965Sjdp 23033965Sjdp#define _bfd_generic_bfd_copy_private_bfd_data \ 231130561Sobrien ((bfd_boolean (*) (bfd *, bfd *)) bfd_true) 23233965Sjdp#define _bfd_generic_bfd_merge_private_bfd_data \ 233130561Sobrien ((bfd_boolean (*) (bfd *, bfd *)) bfd_true) 23433965Sjdp#define _bfd_generic_bfd_set_private_flags \ 235130561Sobrien ((bfd_boolean (*) (bfd *, flagword)) bfd_true) 23633965Sjdp#define _bfd_generic_bfd_copy_private_section_data \ 237130561Sobrien ((bfd_boolean (*) (bfd *, asection *, bfd *, asection *)) bfd_true) 23833965Sjdp#define _bfd_generic_bfd_copy_private_symbol_data \ 239130561Sobrien ((bfd_boolean (*) (bfd *, asymbol *, bfd *, asymbol *)) bfd_true) 240218822Sdim#define _bfd_generic_bfd_copy_private_header_data \ 241218822Sdim ((bfd_boolean (*) (bfd *, bfd *)) bfd_true) 24233965Sjdp#define _bfd_generic_bfd_print_private_bfd_data \ 243130561Sobrien ((bfd_boolean (*) (bfd *, void *)) bfd_true) 24433965Sjdp 245218822Sdimextern bfd_boolean _bfd_generic_init_private_section_data 246218822Sdim (bfd *, asection *, bfd *, asection *, struct bfd_link_info *); 247218822Sdim 24833965Sjdp/* Routines to use for BFD_JUMP_TABLE_CORE when there is no core file 24933965Sjdp support. Use BFD_JUMP_TABLE_CORE (_bfd_nocore). */ 25033965Sjdp 251130561Sobrienextern char *_bfd_nocore_core_file_failing_command 252130561Sobrien (bfd *); 253130561Sobrienextern int _bfd_nocore_core_file_failing_signal 254130561Sobrien (bfd *); 255130561Sobrienextern bfd_boolean _bfd_nocore_core_file_matches_executable_p 256130561Sobrien (bfd *, bfd *); 25733965Sjdp 25833965Sjdp/* Routines to use for BFD_JUMP_TABLE_ARCHIVE when there is no archive 25933965Sjdp file support. Use BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive). */ 26033965Sjdp 26133965Sjdp#define _bfd_noarchive_slurp_armap bfd_false 26233965Sjdp#define _bfd_noarchive_slurp_extended_name_table bfd_false 26333965Sjdp#define _bfd_noarchive_construct_extended_name_table \ 264130561Sobrien ((bfd_boolean (*) (bfd *, char **, bfd_size_type *, const char **)) \ 26533965Sjdp bfd_false) 26633965Sjdp#define _bfd_noarchive_truncate_arname \ 267130561Sobrien ((void (*) (bfd *, const char *, char *)) bfd_void) 26833965Sjdp#define _bfd_noarchive_write_armap \ 269130561Sobrien ((bfd_boolean (*) (bfd *, unsigned int, struct orl *, unsigned int, int)) \ 27033965Sjdp bfd_false) 27133965Sjdp#define _bfd_noarchive_read_ar_hdr bfd_nullvoidptr 27233965Sjdp#define _bfd_noarchive_openr_next_archived_file \ 273130561Sobrien ((bfd *(*) (bfd *, bfd *)) bfd_nullvoidptr) 27433965Sjdp#define _bfd_noarchive_get_elt_at_index \ 275130561Sobrien ((bfd *(*) (bfd *, symindex)) bfd_nullvoidptr) 27633965Sjdp#define _bfd_noarchive_generic_stat_arch_elt bfd_generic_stat_arch_elt 27733965Sjdp#define _bfd_noarchive_update_armap_timestamp bfd_false 27833965Sjdp 27933965Sjdp/* Routines to use for BFD_JUMP_TABLE_ARCHIVE to get BSD style 28033965Sjdp archives. Use BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_bsd). */ 28133965Sjdp 28233965Sjdp#define _bfd_archive_bsd_slurp_armap bfd_slurp_bsd_armap 28333965Sjdp#define _bfd_archive_bsd_slurp_extended_name_table \ 28433965Sjdp _bfd_slurp_extended_name_table 285130561Sobrienextern bfd_boolean _bfd_archive_bsd_construct_extended_name_table 286130561Sobrien (bfd *, char **, bfd_size_type *, const char **); 28733965Sjdp#define _bfd_archive_bsd_truncate_arname bfd_bsd_truncate_arname 28833965Sjdp#define _bfd_archive_bsd_write_armap bsd_write_armap 28933965Sjdp#define _bfd_archive_bsd_read_ar_hdr _bfd_generic_read_ar_hdr 29033965Sjdp#define _bfd_archive_bsd_openr_next_archived_file \ 29133965Sjdp bfd_generic_openr_next_archived_file 29233965Sjdp#define _bfd_archive_bsd_get_elt_at_index _bfd_generic_get_elt_at_index 29333965Sjdp#define _bfd_archive_bsd_generic_stat_arch_elt \ 29433965Sjdp bfd_generic_stat_arch_elt 295130561Sobrienextern bfd_boolean _bfd_archive_bsd_update_armap_timestamp 296130561Sobrien (bfd *); 29733965Sjdp 29833965Sjdp/* Routines to use for BFD_JUMP_TABLE_ARCHIVE to get COFF style 29933965Sjdp archives. Use BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff). */ 30033965Sjdp 30133965Sjdp#define _bfd_archive_coff_slurp_armap bfd_slurp_coff_armap 30233965Sjdp#define _bfd_archive_coff_slurp_extended_name_table \ 30333965Sjdp _bfd_slurp_extended_name_table 304130561Sobrienextern bfd_boolean _bfd_archive_coff_construct_extended_name_table 305130561Sobrien (bfd *, char **, bfd_size_type *, const char **); 30633965Sjdp#define _bfd_archive_coff_truncate_arname bfd_dont_truncate_arname 30733965Sjdp#define _bfd_archive_coff_write_armap coff_write_armap 30833965Sjdp#define _bfd_archive_coff_read_ar_hdr _bfd_generic_read_ar_hdr 30933965Sjdp#define _bfd_archive_coff_openr_next_archived_file \ 31033965Sjdp bfd_generic_openr_next_archived_file 31133965Sjdp#define _bfd_archive_coff_get_elt_at_index _bfd_generic_get_elt_at_index 31233965Sjdp#define _bfd_archive_coff_generic_stat_arch_elt \ 31333965Sjdp bfd_generic_stat_arch_elt 31433965Sjdp#define _bfd_archive_coff_update_armap_timestamp bfd_true 31533965Sjdp 31633965Sjdp/* Routines to use for BFD_JUMP_TABLE_SYMBOLS where there is no symbol 31733965Sjdp support. Use BFD_JUMP_TABLE_SYMBOLS (_bfd_nosymbols). */ 31833965Sjdp 31933965Sjdp#define _bfd_nosymbols_get_symtab_upper_bound _bfd_n1 320130561Sobrien#define _bfd_nosymbols_canonicalize_symtab \ 321130561Sobrien ((long (*) (bfd *, asymbol **)) _bfd_n1) 32289857Sobrien#define _bfd_nosymbols_make_empty_symbol _bfd_generic_make_empty_symbol 32333965Sjdp#define _bfd_nosymbols_print_symbol \ 324130561Sobrien ((void (*) (bfd *, void *, asymbol *, bfd_print_symbol_type)) bfd_void) 32533965Sjdp#define _bfd_nosymbols_get_symbol_info \ 326130561Sobrien ((void (*) (bfd *, asymbol *, symbol_info *)) bfd_void) 32733965Sjdp#define _bfd_nosymbols_bfd_is_local_label_name \ 328130561Sobrien ((bfd_boolean (*) (bfd *, const char *)) bfd_false) 329218822Sdim#define _bfd_nosymbols_bfd_is_target_special_symbol \ 330218822Sdim ((bfd_boolean (*) (bfd *, asymbol *)) bfd_false) 33133965Sjdp#define _bfd_nosymbols_get_lineno \ 332130561Sobrien ((alent *(*) (bfd *, asymbol *)) bfd_nullvoidptr) 33333965Sjdp#define _bfd_nosymbols_find_nearest_line \ 334130561Sobrien ((bfd_boolean (*) (bfd *, asection *, asymbol **, bfd_vma, const char **, \ 335130561Sobrien const char **, unsigned int *)) \ 33633965Sjdp bfd_false) 337218822Sdim#define _bfd_nosymbols_find_inliner_info \ 338218822Sdim ((bfd_boolean (*) (bfd *, const char **, const char **, unsigned int *)) \ 339218822Sdim bfd_false) 34033965Sjdp#define _bfd_nosymbols_bfd_make_debug_symbol \ 341130561Sobrien ((asymbol *(*) (bfd *, void *, unsigned long)) bfd_nullvoidptr) 34233965Sjdp#define _bfd_nosymbols_read_minisymbols \ 343130561Sobrien ((long (*) (bfd *, bfd_boolean, void **, unsigned int *)) _bfd_n1) 34433965Sjdp#define _bfd_nosymbols_minisymbol_to_symbol \ 345130561Sobrien ((asymbol *(*) (bfd *, bfd_boolean, const void *, asymbol *)) \ 34633965Sjdp bfd_nullvoidptr) 34733965Sjdp 34833965Sjdp/* Routines to use for BFD_JUMP_TABLE_RELOCS when there is no reloc 34933965Sjdp support. Use BFD_JUMP_TABLE_RELOCS (_bfd_norelocs). */ 35033965Sjdp 351218822Sdimextern long _bfd_norelocs_get_reloc_upper_bound (bfd *, asection *); 352218822Sdimextern long _bfd_norelocs_canonicalize_reloc (bfd *, asection *, 353218822Sdim arelent **, asymbol **); 35433965Sjdp#define _bfd_norelocs_bfd_reloc_type_lookup \ 355130561Sobrien ((reloc_howto_type *(*) (bfd *, bfd_reloc_code_real_type)) bfd_nullvoidptr) 356218822Sdim#define _bfd_norelocs_bfd_reloc_name_lookup \ 357218822Sdim ((reloc_howto_type *(*) (bfd *, const char *)) bfd_nullvoidptr) 35833965Sjdp 35933965Sjdp/* Routines to use for BFD_JUMP_TABLE_WRITE for targets which may not 36033965Sjdp be written. Use BFD_JUMP_TABLE_WRITE (_bfd_nowrite). */ 36133965Sjdp 36233965Sjdp#define _bfd_nowrite_set_arch_mach \ 363130561Sobrien ((bfd_boolean (*) (bfd *, enum bfd_architecture, unsigned long)) \ 36433965Sjdp bfd_false) 36533965Sjdp#define _bfd_nowrite_set_section_contents \ 366130561Sobrien ((bfd_boolean (*) (bfd *, asection *, const void *, file_ptr, bfd_size_type)) \ 36733965Sjdp bfd_false) 36833965Sjdp 36933965Sjdp/* Generic routines to use for BFD_JUMP_TABLE_WRITE. Use 37033965Sjdp BFD_JUMP_TABLE_WRITE (_bfd_generic). */ 37133965Sjdp 37233965Sjdp#define _bfd_generic_set_arch_mach bfd_default_set_arch_mach 373130561Sobrienextern bfd_boolean _bfd_generic_set_section_contents 374130561Sobrien (bfd *, asection *, const void *, file_ptr, bfd_size_type); 37533965Sjdp 37633965Sjdp/* Routines to use for BFD_JUMP_TABLE_LINK for targets which do not 37733965Sjdp support linking. Use BFD_JUMP_TABLE_LINK (_bfd_nolink). */ 37833965Sjdp 379218822Sdim#define _bfd_nolink_sizeof_headers \ 380218822Sdim ((int (*) (bfd *, struct bfd_link_info *)) bfd_0) 38133965Sjdp#define _bfd_nolink_bfd_get_relocated_section_contents \ 382130561Sobrien ((bfd_byte *(*) (bfd *, struct bfd_link_info *, struct bfd_link_order *, \ 383130561Sobrien bfd_byte *, bfd_boolean, asymbol **)) \ 38433965Sjdp bfd_nullvoidptr) 38533965Sjdp#define _bfd_nolink_bfd_relax_section \ 386130561Sobrien ((bfd_boolean (*) \ 387130561Sobrien (bfd *, asection *, struct bfd_link_info *, bfd_boolean *)) \ 38833965Sjdp bfd_false) 38960484Sobrien#define _bfd_nolink_bfd_gc_sections \ 390130561Sobrien ((bfd_boolean (*) (bfd *, struct bfd_link_info *)) \ 39160484Sobrien bfd_false) 39289857Sobrien#define _bfd_nolink_bfd_merge_sections \ 393130561Sobrien ((bfd_boolean (*) (bfd *, struct bfd_link_info *)) \ 39489857Sobrien bfd_false) 395218822Sdim#define _bfd_nolink_bfd_is_group_section \ 396218822Sdim ((bfd_boolean (*) (bfd *, const struct bfd_section *)) \ 397218822Sdim bfd_false) 398104834Sobrien#define _bfd_nolink_bfd_discard_group \ 399130561Sobrien ((bfd_boolean (*) (bfd *, struct bfd_section *)) \ 400104834Sobrien bfd_false) 40133965Sjdp#define _bfd_nolink_bfd_link_hash_table_create \ 402130561Sobrien ((struct bfd_link_hash_table *(*) (bfd *)) bfd_nullvoidptr) 403104834Sobrien#define _bfd_nolink_bfd_link_hash_table_free \ 404130561Sobrien ((void (*) (struct bfd_link_hash_table *)) bfd_void) 40533965Sjdp#define _bfd_nolink_bfd_link_add_symbols \ 406130561Sobrien ((bfd_boolean (*) (bfd *, struct bfd_link_info *)) bfd_false) 407104834Sobrien#define _bfd_nolink_bfd_link_just_syms \ 408130561Sobrien ((void (*) (asection *, struct bfd_link_info *)) bfd_void) 40933965Sjdp#define _bfd_nolink_bfd_final_link \ 410130561Sobrien ((bfd_boolean (*) (bfd *, struct bfd_link_info *)) bfd_false) 41133965Sjdp#define _bfd_nolink_bfd_link_split_section \ 412130561Sobrien ((bfd_boolean (*) (bfd *, struct bfd_section *)) bfd_false) 413218822Sdim#define _bfd_nolink_section_already_linked \ 414218822Sdim ((void (*) (bfd *, struct bfd_section *, struct bfd_link_info *)) bfd_void) 41533965Sjdp 41633965Sjdp/* Routines to use for BFD_JUMP_TABLE_DYNAMIC for targets which do not 41733965Sjdp have dynamic symbols or relocs. Use BFD_JUMP_TABLE_DYNAMIC 41833965Sjdp (_bfd_nodynamic). */ 41933965Sjdp 42033965Sjdp#define _bfd_nodynamic_get_dynamic_symtab_upper_bound _bfd_n1 42133965Sjdp#define _bfd_nodynamic_canonicalize_dynamic_symtab \ 422130561Sobrien ((long (*) (bfd *, asymbol **)) _bfd_n1) 423218822Sdim#define _bfd_nodynamic_get_synthetic_symtab \ 424218822Sdim ((long (*) (bfd *, long, asymbol **, long, asymbol **, asymbol **)) _bfd_n1) 42533965Sjdp#define _bfd_nodynamic_get_dynamic_reloc_upper_bound _bfd_n1 42633965Sjdp#define _bfd_nodynamic_canonicalize_dynamic_reloc \ 427130561Sobrien ((long (*) (bfd *, arelent **, asymbol **)) _bfd_n1) 42833965Sjdp 42933965Sjdp/* Generic routine to determine of the given symbol is a local 43033965Sjdp label. */ 431130561Sobrienextern bfd_boolean bfd_generic_is_local_label_name 432130561Sobrien (bfd *, const char *); 43333965Sjdp 43433965Sjdp/* Generic minisymbol routines. */ 43533965Sjdpextern long _bfd_generic_read_minisymbols 436130561Sobrien (bfd *, bfd_boolean, void **, unsigned int *); 43733965Sjdpextern asymbol *_bfd_generic_minisymbol_to_symbol 438130561Sobrien (bfd *, bfd_boolean, const void *, asymbol *); 43933965Sjdp 44033965Sjdp/* Find the nearest line using .stab/.stabstr sections. */ 441130561Sobrienextern bfd_boolean _bfd_stab_section_find_nearest_line 442130561Sobrien (bfd *, asymbol **, asection *, bfd_vma, bfd_boolean *, 443130561Sobrien const char **, const char **, unsigned int *, void **); 44433965Sjdp 445218822Sdim/* Find the nearest line using DWARF 1 debugging information. */ 446130561Sobrienextern bfd_boolean _bfd_dwarf1_find_nearest_line 447130561Sobrien (bfd *, asection *, asymbol **, bfd_vma, const char **, 448130561Sobrien const char **, unsigned int *); 44960484Sobrien 45038889Sjdp/* Find the nearest line using DWARF 2 debugging information. */ 451130561Sobrienextern bfd_boolean _bfd_dwarf2_find_nearest_line 452130561Sobrien (bfd *, asection *, asymbol **, bfd_vma, const char **, const char **, 453130561Sobrien unsigned int *, unsigned int, void **); 45438889Sjdp 455218822Sdim/* Find the line using DWARF 2 debugging information. */ 456218822Sdimextern bfd_boolean _bfd_dwarf2_find_line 457218822Sdim (bfd *, asymbol **, asymbol *, const char **, 458218822Sdim unsigned int *, unsigned int, void **); 459218822Sdim 460218822Sdimbfd_boolean _bfd_generic_find_line 461218822Sdim (bfd *, asymbol **, asymbol *, const char **, unsigned int *); 462218822Sdim 463218822Sdim/* Find inliner info after calling bfd_find_nearest_line. */ 464218822Sdimextern bfd_boolean _bfd_dwarf2_find_inliner_info 465218822Sdim (bfd *, const char **, const char **, unsigned int *, void **); 466218822Sdim 46789857Sobrien/* Create a new section entry. */ 46889857Sobrienextern struct bfd_hash_entry *bfd_section_hash_newfunc 469130561Sobrien (struct bfd_hash_entry *, struct bfd_hash_table *, const char *); 47089857Sobrien 47133965Sjdp/* A routine to create entries for a bfd_link_hash_table. */ 47233965Sjdpextern struct bfd_hash_entry *_bfd_link_hash_newfunc 473130561Sobrien (struct bfd_hash_entry *entry, struct bfd_hash_table *table, 474130561Sobrien const char *string); 47533965Sjdp 47633965Sjdp/* Initialize a bfd_link_hash_table. */ 477130561Sobrienextern bfd_boolean _bfd_link_hash_table_init 478130561Sobrien (struct bfd_link_hash_table *, bfd *, 479130561Sobrien struct bfd_hash_entry *(*) (struct bfd_hash_entry *, 480130561Sobrien struct bfd_hash_table *, 481218822Sdim const char *), 482218822Sdim unsigned int); 48333965Sjdp 48433965Sjdp/* Generic link hash table creation routine. */ 48533965Sjdpextern struct bfd_link_hash_table *_bfd_generic_link_hash_table_create 486130561Sobrien (bfd *); 48733965Sjdp 488104834Sobrien/* Generic link hash table destruction routine. */ 489104834Sobrienextern void _bfd_generic_link_hash_table_free 490130561Sobrien (struct bfd_link_hash_table *); 491104834Sobrien 49233965Sjdp/* Generic add symbol routine. */ 493130561Sobrienextern bfd_boolean _bfd_generic_link_add_symbols 494130561Sobrien (bfd *, struct bfd_link_info *); 49533965Sjdp 49633965Sjdp/* Generic add symbol routine. This version is used by targets for 49733965Sjdp which the linker must collect constructors and destructors by name, 49833965Sjdp as the collect2 program does. */ 499130561Sobrienextern bfd_boolean _bfd_generic_link_add_symbols_collect 500130561Sobrien (bfd *, struct bfd_link_info *); 50133965Sjdp 50233965Sjdp/* Generic archive add symbol routine. */ 503130561Sobrienextern bfd_boolean _bfd_generic_link_add_archive_symbols 504130561Sobrien (bfd *, struct bfd_link_info *, 505130561Sobrien bfd_boolean (*) (bfd *, struct bfd_link_info *, bfd_boolean *)); 50633965Sjdp 50733965Sjdp/* Forward declaration to avoid prototype errors. */ 50833965Sjdptypedef struct bfd_link_hash_entry _bfd_link_hash_entry; 50933965Sjdp 51033965Sjdp/* Generic routine to add a single symbol. */ 511130561Sobrienextern bfd_boolean _bfd_generic_link_add_one_symbol 512130561Sobrien (struct bfd_link_info *, bfd *, const char *name, flagword, 513130561Sobrien asection *, bfd_vma, const char *, bfd_boolean copy, 514130561Sobrien bfd_boolean constructor, struct bfd_link_hash_entry **); 51533965Sjdp 516104834Sobrien/* Generic routine to mark section as supplying symbols only. */ 517104834Sobrienextern void _bfd_generic_link_just_syms 518130561Sobrien (asection *, struct bfd_link_info *); 519104834Sobrien 52033965Sjdp/* Generic link routine. */ 521130561Sobrienextern bfd_boolean _bfd_generic_final_link 522130561Sobrien (bfd *, struct bfd_link_info *); 52333965Sjdp 524130561Sobrienextern bfd_boolean _bfd_generic_link_split_section 525130561Sobrien (bfd *, struct bfd_section *); 52633965Sjdp 527218822Sdimextern void _bfd_generic_section_already_linked 528218822Sdim (bfd *, struct bfd_section *, struct bfd_link_info *); 529218822Sdim 53033965Sjdp/* Generic reloc_link_order processing routine. */ 531130561Sobrienextern bfd_boolean _bfd_generic_reloc_link_order 532130561Sobrien (bfd *, struct bfd_link_info *, asection *, struct bfd_link_order *); 53333965Sjdp 53433965Sjdp/* Default link order processing routine. */ 535130561Sobrienextern bfd_boolean _bfd_default_link_order 536130561Sobrien (bfd *, struct bfd_link_info *, asection *, struct bfd_link_order *); 53733965Sjdp 53833965Sjdp/* Count the number of reloc entries in a link order list. */ 53933965Sjdpextern unsigned int _bfd_count_link_order_relocs 540130561Sobrien (struct bfd_link_order *); 54133965Sjdp 54233965Sjdp/* Final link relocation routine. */ 54333965Sjdpextern bfd_reloc_status_type _bfd_final_link_relocate 544130561Sobrien (reloc_howto_type *, bfd *, asection *, bfd_byte *, 545130561Sobrien bfd_vma, bfd_vma, bfd_vma); 54633965Sjdp 54733965Sjdp/* Relocate a particular location by a howto and a value. */ 54833965Sjdpextern bfd_reloc_status_type _bfd_relocate_contents 549130561Sobrien (reloc_howto_type *, bfd *, bfd_vma, bfd_byte *); 55033965Sjdp 551218822Sdim/* Clear a given location using a given howto. */ 552218822Sdimextern void _bfd_clear_contents (reloc_howto_type *howto, bfd *input_bfd, 553218822Sdim bfd_byte *location); 554218822Sdim 55533965Sjdp/* Link stabs in sections in the first pass. */ 55633965Sjdp 557130561Sobrienextern bfd_boolean _bfd_link_section_stabs 558218822Sdim (bfd *, struct stab_info *, asection *, asection *, void **, 559218822Sdim bfd_size_type *); 56033965Sjdp 56189857Sobrien/* Eliminate stabs for discarded functions and symbols. */ 562130561Sobrienextern bfd_boolean _bfd_discard_section_stabs 563130561Sobrien (bfd *, asection *, void *, bfd_boolean (*) (bfd_vma, void *), void *); 56489857Sobrien 56533965Sjdp/* Write out the .stab section when linking stabs in sections. */ 56633965Sjdp 567130561Sobrienextern bfd_boolean _bfd_write_section_stabs 568218822Sdim (bfd *, struct stab_info *, asection *, void **, bfd_byte *); 56933965Sjdp 57033965Sjdp/* Write out the .stabstr string table when linking stabs in sections. */ 57133965Sjdp 572130561Sobrienextern bfd_boolean _bfd_write_stab_strings 573218822Sdim (bfd *, struct stab_info *); 57433965Sjdp 57533965Sjdp/* Find an offset within a .stab section when linking stabs in 57633965Sjdp sections. */ 57733965Sjdp 57833965Sjdpextern bfd_vma _bfd_stab_section_offset 579218822Sdim (asection *, void *, bfd_vma); 58033965Sjdp 581218822Sdim/* Register a SEC_MERGE section as a candidate for merging. */ 58289857Sobrien 583218822Sdimextern bfd_boolean _bfd_add_merge_section 584130561Sobrien (bfd *, void **, asection *, void **); 58589857Sobrien 58689857Sobrien/* Attempt to merge SEC_MERGE sections. */ 58789857Sobrien 588130561Sobrienextern bfd_boolean _bfd_merge_sections 589218822Sdim (bfd *, struct bfd_link_info *, void *, void (*) (bfd *, asection *)); 59089857Sobrien 59189857Sobrien/* Write out a merged section. */ 59289857Sobrien 593130561Sobrienextern bfd_boolean _bfd_write_merged_section 594130561Sobrien (bfd *, asection *, void *); 59589857Sobrien 59689857Sobrien/* Find an offset within a modified SEC_MERGE section. */ 59789857Sobrien 59889857Sobrienextern bfd_vma _bfd_merged_section_offset 599218822Sdim (bfd *, asection **, void *, bfd_vma); 60089857Sobrien 60133965Sjdp/* Create a string table. */ 602130561Sobrienextern struct bfd_strtab_hash *_bfd_stringtab_init 603130561Sobrien (void); 60433965Sjdp 60533965Sjdp/* Create an XCOFF .debug section style string table. */ 606130561Sobrienextern struct bfd_strtab_hash *_bfd_xcoff_stringtab_init 607130561Sobrien (void); 60833965Sjdp 60933965Sjdp/* Free a string table. */ 610130561Sobrienextern void _bfd_stringtab_free 611130561Sobrien (struct bfd_strtab_hash *); 61233965Sjdp 61333965Sjdp/* Get the size of a string table. */ 614130561Sobrienextern bfd_size_type _bfd_stringtab_size 615130561Sobrien (struct bfd_strtab_hash *); 61633965Sjdp 61733965Sjdp/* Add a string to a string table. */ 61833965Sjdpextern bfd_size_type _bfd_stringtab_add 619130561Sobrien (struct bfd_strtab_hash *, const char *, bfd_boolean hash, bfd_boolean copy); 62033965Sjdp 62133965Sjdp/* Write out a string table. */ 622130561Sobrienextern bfd_boolean _bfd_stringtab_emit 623130561Sobrien (bfd *, struct bfd_strtab_hash *); 62460484Sobrien 62560484Sobrien/* Check that endianness of input and output file match. */ 626130561Sobrienextern bfd_boolean _bfd_generic_verify_endian_match 627130561Sobrien (bfd *, bfd *); 62833965Sjdp 62933965Sjdp/* Macros to tell if bfds are read or write enabled. 63033965Sjdp 63133965Sjdp Note that bfds open for read may be scribbled into if the fd passed 63233965Sjdp to bfd_fdopenr is actually open both for read and write 63333965Sjdp simultaneously. However an output bfd will never be open for 63433965Sjdp read. Therefore sometimes you want to check bfd_read_p or 63533965Sjdp !bfd_read_p, and only sometimes bfd_write_p. 63633965Sjdp*/ 63733965Sjdp 638130561Sobrien#define bfd_read_p(abfd) \ 639130561Sobrien ((abfd)->direction == read_direction || (abfd)->direction == both_direction) 640130561Sobrien#define bfd_write_p(abfd) \ 641130561Sobrien ((abfd)->direction == write_direction || (abfd)->direction == both_direction) 64233965Sjdp 643130561Sobrienvoid bfd_assert 644130561Sobrien (const char*,int); 64533965Sjdp 64633965Sjdp#define BFD_ASSERT(x) \ 647218822Sdim do { if (!(x)) bfd_assert(__FILE__,__LINE__); } while (0) 64833965Sjdp 64933965Sjdp#define BFD_FAIL() \ 650218822Sdim do { bfd_assert(__FILE__,__LINE__); } while (0) 65133965Sjdp 652130561Sobrienextern void _bfd_abort 653130561Sobrien (const char *, int, const char *) ATTRIBUTE_NORETURN; 65460484Sobrien 65560484Sobrien/* if gcc >= 2.6, we can give a function name, too */ 65660484Sobrien#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 6) 65760484Sobrien#define __PRETTY_FUNCTION__ ((char *) NULL) 65860484Sobrien#endif 65960484Sobrien 66060484Sobrien#undef abort 66160484Sobrien#define abort() _bfd_abort (__FILE__, __LINE__, __PRETTY_FUNCTION__) 66260484Sobrien 663130561Sobrien/* Manipulate a system FILE but using BFD's "file_ptr", rather than 664130561Sobrien the system "off_t" or "off64_t", as the offset. */ 665130561Sobrienextern file_ptr real_ftell (FILE *file); 666130561Sobrienextern int real_fseek (FILE *file, file_ptr offset, int whence); 667218822Sdimextern FILE *real_fopen (const char *filename, const char *modes); 66833965Sjdp 66933965Sjdp/* List of supported target vectors, and the default vector (if 67033965Sjdp bfd_default_vector[0] is NULL, there is no default). */ 67178828Sobrienextern const bfd_target * const *bfd_target_vector; 67233965Sjdpextern const bfd_target *bfd_default_vector[]; 67333965Sjdp 674130561Sobrien/* List of associated target vectors. */ 675130561Sobrienextern const bfd_target * const *bfd_associated_vector; 676130561Sobrien 67733965Sjdp/* Functions shared by the ECOFF and MIPS ELF backends, which have no 67833965Sjdp other common header files. */ 67933965Sjdp 68033965Sjdp#if defined(__STDC__) || defined(ALMOST_STDC) 68133965Sjdpstruct ecoff_find_line; 68233965Sjdp#endif 68333965Sjdp 684130561Sobrienextern bfd_boolean _bfd_ecoff_locate_line 685130561Sobrien (bfd *, asection *, bfd_vma, struct ecoff_debug_info * const, 686130561Sobrien const struct ecoff_debug_swap * const, struct ecoff_find_line *, 687130561Sobrien const char **, const char **, unsigned int *); 688130561Sobrienextern bfd_boolean _bfd_ecoff_get_accumulated_pdr 689130561Sobrien (void *, bfd_byte *); 690130561Sobrienextern bfd_boolean _bfd_ecoff_get_accumulated_sym 691130561Sobrien (void *, bfd_byte *); 692130561Sobrienextern bfd_boolean _bfd_ecoff_get_accumulated_ss 693130561Sobrien (void *, bfd_byte *); 69433965Sjdp 695130561Sobrienextern bfd_vma _bfd_get_gp_value 696130561Sobrien (bfd *); 697130561Sobrienextern void _bfd_set_gp_value 698130561Sobrien (bfd *, bfd_vma); 69933965Sjdp 70033965Sjdp/* Function shared by the COFF and ELF SH backends, which have no 70133965Sjdp other common header files. */ 70233965Sjdp 703130561Sobrien#ifndef _bfd_sh_align_load_span 704130561Sobrienextern bfd_boolean _bfd_sh_align_load_span 705130561Sobrien (bfd *, asection *, bfd_byte *, 706130561Sobrien bfd_boolean (*) (bfd *, asection *, void *, bfd_byte *, bfd_vma), 707130561Sobrien void *, bfd_vma **, bfd_vma *, bfd_vma, bfd_vma, bfd_boolean *); 708130561Sobrien#endif 709218822Sdim 710218822Sdim/* This is the shape of the elements inside the already_linked hash 711218822Sdim table. It maps a name onto a list of already_linked elements with 712218822Sdim the same name. */ 713218822Sdim 714218822Sdimstruct bfd_section_already_linked_hash_entry 715218822Sdim{ 716218822Sdim struct bfd_hash_entry root; 717218822Sdim struct bfd_section_already_linked *entry; 718218822Sdim}; 719218822Sdim 720218822Sdimstruct bfd_section_already_linked 721218822Sdim{ 722218822Sdim struct bfd_section_already_linked *next; 723218822Sdim asection *sec; 724218822Sdim}; 725218822Sdim 726218822Sdimextern struct bfd_section_already_linked_hash_entry * 727218822Sdim bfd_section_already_linked_table_lookup (const char *); 728218822Sdimextern void bfd_section_already_linked_table_insert 729218822Sdim (struct bfd_section_already_linked_hash_entry *, asection *); 730218822Sdimextern void bfd_section_already_linked_table_traverse 731218822Sdim (bfd_boolean (*) (struct bfd_section_already_linked_hash_entry *, 732218822Sdim void *), void *); 733218822Sdim 734218822Sdimextern bfd_vma read_unsigned_leb128 (bfd *, bfd_byte *, unsigned int *); 735218822Sdimextern bfd_signed_vma read_signed_leb128 (bfd *, bfd_byte *, unsigned int *); 736218822Sdim 737