Home | History | Annotate | Line # | Download | only in bfd
libbfd-in.h revision 1.11
      1 /* libbfd.h -- Declarations used by bfd library *implementation*.
      2    (This include file is not for users of the library.)
      3 
      4    Copyright (C) 1990-2024 Free Software Foundation, Inc.
      5 
      6    Written by Cygnus Support.
      7 
      8    This file is part of BFD, the Binary File Descriptor library.
      9 
     10    This program is free software; you can redistribute it and/or modify
     11    it under the terms of the GNU General Public License as published by
     12    the Free Software Foundation; either version 3 of the License, or
     13    (at your option) any later version.
     14 
     15    This program is distributed in the hope that it will be useful,
     16    but WITHOUT ANY WARRANTY; without even the implied warranty of
     17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     18    GNU General Public License for more details.
     19 
     20    You should have received a copy of the GNU General Public License
     21    along with this program; if not, write to the Free Software
     22    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
     23    MA 02110-1301, USA.  */
     24 
     25 #ifndef _LIBBFD_H
     26 #define _LIBBFD_H 1
     27 
     28 #ifndef ATTRIBUTE_HIDDEN
     29 #if HAVE_HIDDEN
     30 #define ATTRIBUTE_HIDDEN __attribute__ ((__visibility__ ("hidden")))
     31 #else
     32 #define ATTRIBUTE_HIDDEN
     33 #endif
     34 #endif
     35 
     36 #include "hashtab.h"
     37 
     38 #ifdef __cplusplus
     39 extern "C" {
     40 #endif
     41 
     42 /* Set a tdata field.  Can't use the other macros for this, since they
     43    do casts, and casting to the left of assignment isn't portable.  */
     44 #define set_tdata(bfd, v) ((bfd)->tdata.any = (v))
     45 
     46 /* If BFD_IN_MEMORY is set for a BFD, then the iostream fields points
     47    to an instance of this structure.  */
     48 
     49 struct bfd_in_memory
     50 {
     51   /* Size of buffer.  */
     52   bfd_size_type size;
     53   /* Buffer holding contents of BFD.  */
     54   bfd_byte *buffer;
     55 };
     56 
     57 struct section_hash_entry
     58 {
     59   struct bfd_hash_entry root;
     60   asection section;
     61 };
     62 
     63 /* Unique section id.  */
     64 extern unsigned int _bfd_section_id ATTRIBUTE_HIDDEN;
     65 
     66 /* tdata for an archive.  For an input archive, cache
     67    needs to be free()'d.  For an output archive, symdefs do.  */
     68 
     69 struct artdata
     70 {
     71   ufile_ptr first_file_filepos;
     72   /* Speed up searching the armap */
     73   htab_t cache;
     74   carsym *symdefs;		/* The symdef entries.  */
     75   symindex symdef_count;	/* How many there are.  */
     76   char *extended_names;		/* Clever intel extension.  */
     77   bfd_size_type extended_names_size; /* Size of extended names.  */
     78   /* When more compilers are standard C, this can be a time_t.  */
     79   long  armap_timestamp;	/* Timestamp value written into armap.
     80 				   This is used for BSD archives to check
     81 				   that the timestamp is recent enough
     82 				   for the BSD linker to not complain,
     83 				   just before we finish writing an
     84 				   archive.  */
     85   file_ptr armap_datepos;	/* Position within archive to seek to
     86 				   rewrite the date field.  */
     87   void *tdata;			/* Backend specific information.  */
     88 };
     89 
     90 #define bfd_ardata(bfd) ((bfd)->tdata.aout_ar_data)
     91 
     92 /* Goes in bfd's arelt_data slot */
     93 struct areltdata
     94 {
     95   char * arch_header;		/* It's actually a string.  */
     96   bfd_size_type parsed_size;	/* Octets of filesize not including ar_hdr.  */
     97   bfd_size_type extra_size;	/* BSD4.4: extra bytes after the header.  */
     98   char *filename;		/* Null-terminated.  */
     99   file_ptr origin;		/* For element of a thin archive.  */
    100   void *parent_cache;		/* Where and how to find this member.  */
    101   file_ptr key;
    102 };
    103 
    104 #define arelt_size(bfd) (((struct areltdata *)((bfd)->arelt_data))->parsed_size)
    105 
    106 extern void *bfd_malloc
    107   (bfd_size_type) ATTRIBUTE_HIDDEN;
    108 
    109 static inline char *
    110 bfd_strdup (const char *str)
    111 {
    112   size_t len = strlen (str) + 1;
    113   char *buf = bfd_malloc (len);
    114   if (buf != NULL)
    115     memcpy (buf, str, len);
    116   return buf;
    117 }
    118 
    119 extern bfd * _bfd_create_empty_archive_element_shell
    120   (bfd *) ATTRIBUTE_HIDDEN;
    121 extern bfd * _bfd_look_for_bfd_in_cache
    122   (bfd *, file_ptr) ATTRIBUTE_HIDDEN;
    123 extern bool _bfd_add_bfd_to_archive_cache
    124   (bfd *, file_ptr, bfd *) ATTRIBUTE_HIDDEN;
    125 extern bool _bfd_generic_mkarchive
    126   (bfd *) ATTRIBUTE_HIDDEN;
    127 extern char *_bfd_append_relative_path
    128   (bfd *, char *) ATTRIBUTE_HIDDEN;
    129 extern bfd_cleanup bfd_generic_archive_p
    130   (bfd *) ATTRIBUTE_HIDDEN;
    131 extern bool bfd_slurp_armap
    132   (bfd *) ATTRIBUTE_HIDDEN;
    133 #define bfd_slurp_bsd_armap bfd_slurp_armap
    134 #define bfd_slurp_coff_armap bfd_slurp_armap
    135 extern bool _bfd_archive_64_bit_slurp_armap
    136   (bfd *) ATTRIBUTE_HIDDEN;
    137 extern bool _bfd_archive_64_bit_write_armap
    138   (bfd *, unsigned int, struct orl *, unsigned int, int) ATTRIBUTE_HIDDEN;
    139 #define _bfd_archive_64_bit_slurp_extended_name_table \
    140   _bfd_slurp_extended_name_table
    141 #define _bfd_archive_64_bit_construct_extended_name_table \
    142   _bfd_archive_coff_construct_extended_name_table
    143 #define _bfd_archive_64_bit_truncate_arname \
    144   bfd_dont_truncate_arname
    145 #define _bfd_archive_64_bit_read_ar_hdr \
    146   _bfd_generic_read_ar_hdr
    147 #define _bfd_archive_64_bit_write_ar_hdr \
    148   _bfd_generic_write_ar_hdr
    149 #define _bfd_archive_64_bit_openr_next_archived_file \
    150   bfd_generic_openr_next_archived_file
    151 #define _bfd_archive_64_bit_get_elt_at_index \
    152   _bfd_generic_get_elt_at_index
    153 #define _bfd_archive_64_bit_generic_stat_arch_elt \
    154   bfd_generic_stat_arch_elt
    155 #define _bfd_archive_64_bit_update_armap_timestamp _bfd_bool_bfd_true
    156 
    157 extern bool _bfd_slurp_extended_name_table
    158   (bfd *) ATTRIBUTE_HIDDEN;
    159 extern bool _bfd_construct_extended_name_table
    160   (bfd *, bool, char **, bfd_size_type *) ATTRIBUTE_HIDDEN;
    161 extern bool _bfd_write_archive_contents
    162   (bfd *) ATTRIBUTE_HIDDEN;
    163 extern bool _bfd_compute_and_write_armap
    164   (bfd *, unsigned int) ATTRIBUTE_HIDDEN;
    165 extern bfd *_bfd_get_elt_at_filepos
    166   (bfd *, file_ptr, struct bfd_link_info *) ATTRIBUTE_HIDDEN;
    167 extern bfd *_bfd_generic_get_elt_at_index
    168   (bfd *, symindex) ATTRIBUTE_HIDDEN;
    169 
    170 extern bool _bfd_bool_bfd_false
    171   (bfd *) ATTRIBUTE_HIDDEN;
    172 extern bool _bfd_bool_bfd_asymbol_false
    173   (bfd *, asymbol *) ATTRIBUTE_HIDDEN;
    174 extern bool _bfd_bool_bfd_false_error
    175   (bfd *) ATTRIBUTE_HIDDEN;
    176 extern bool _bfd_bool_bfd_link_false_error
    177   (bfd *, struct bfd_link_info *) ATTRIBUTE_HIDDEN;
    178 extern bool _bfd_bool_bfd_true
    179   (bfd *) ATTRIBUTE_HIDDEN;
    180 extern bool _bfd_bool_bfd_link_true
    181   (bfd *, struct bfd_link_info *) ATTRIBUTE_HIDDEN;
    182 extern bool _bfd_bool_bfd_bfd_true
    183   (bfd *, bfd *) ATTRIBUTE_HIDDEN;
    184 extern bool _bfd_bool_bfd_uint_true
    185   (bfd *, unsigned int) ATTRIBUTE_HIDDEN;
    186 extern bool _bfd_bool_bfd_asection_bfd_asection_true
    187   (bfd *, asection *, bfd *, asection *) ATTRIBUTE_HIDDEN;
    188 extern bool _bfd_bool_bfd_asymbol_bfd_asymbol_true
    189   (bfd *, asymbol *, bfd *, asymbol *) ATTRIBUTE_HIDDEN;
    190 extern bool _bfd_bool_bfd_ptr_true
    191   (bfd *, void *) ATTRIBUTE_HIDDEN;
    192 extern void *_bfd_ptr_bfd_null_error
    193   (bfd *) ATTRIBUTE_HIDDEN;
    194 extern int _bfd_int_bfd_0
    195   (bfd *) ATTRIBUTE_HIDDEN;
    196 extern unsigned int _bfd_uint_bfd_0
    197   (bfd *) ATTRIBUTE_HIDDEN;
    198 extern long _bfd_long_bfd_0
    199   (bfd *) ATTRIBUTE_HIDDEN;
    200 extern long _bfd_long_bfd_n1_error
    201   (bfd *) ATTRIBUTE_HIDDEN;
    202 extern void _bfd_void_bfd
    203   (bfd *) ATTRIBUTE_HIDDEN;
    204 extern void _bfd_void_bfd_link
    205   (bfd *, struct bfd_link_info *) ATTRIBUTE_HIDDEN;
    206 extern void _bfd_void_bfd_asection
    207   (bfd *, asection *) ATTRIBUTE_HIDDEN;
    208 
    209 extern bfd_cleanup _bfd_dummy_target
    210   (bfd *) ATTRIBUTE_HIDDEN;
    211 #define _bfd_no_cleanup _bfd_void_bfd
    212 
    213 extern void bfd_dont_truncate_arname
    214   (bfd *, const char *, char *) ATTRIBUTE_HIDDEN;
    215 extern void bfd_bsd_truncate_arname
    216   (bfd *, const char *, char *) ATTRIBUTE_HIDDEN;
    217 extern void bfd_gnu_truncate_arname
    218   (bfd *, const char *, char *) ATTRIBUTE_HIDDEN;
    219 
    220 extern bool _bfd_bsd_write_armap
    221   (bfd *, unsigned int, struct orl *, unsigned int, int) ATTRIBUTE_HIDDEN;
    222 
    223 extern bool _bfd_coff_write_armap
    224   (bfd *, unsigned int, struct orl *, unsigned int, int) ATTRIBUTE_HIDDEN;
    225 
    226 extern void *_bfd_generic_read_ar_hdr
    227   (bfd *) ATTRIBUTE_HIDDEN;
    228 extern void _bfd_ar_spacepad
    229   (char *, size_t, const char *, long) ATTRIBUTE_HIDDEN;
    230 extern bool _bfd_ar_sizepad
    231   (char *, size_t, bfd_size_type) ATTRIBUTE_HIDDEN;
    232 
    233 extern void *_bfd_generic_read_ar_hdr_mag
    234   (bfd *, const char *) ATTRIBUTE_HIDDEN;
    235 
    236 extern bool _bfd_generic_write_ar_hdr
    237   (bfd *, bfd *) ATTRIBUTE_HIDDEN;
    238 
    239 extern bool _bfd_bsd44_write_ar_hdr
    240   (bfd *, bfd *) ATTRIBUTE_HIDDEN;
    241 
    242 extern bfd * bfd_generic_openr_next_archived_file
    243   (bfd *, bfd *) ATTRIBUTE_HIDDEN;
    244 
    245 extern int bfd_generic_stat_arch_elt
    246   (bfd *, struct stat *) ATTRIBUTE_HIDDEN;
    247 
    248 #define _bfd_read_ar_hdr(abfd) \
    249 	BFD_SEND (abfd, _bfd_read_ar_hdr_fn, (abfd))
    250 #define _bfd_write_ar_hdr(archive, abfd)	 \
    251 	BFD_SEND (abfd, _bfd_write_ar_hdr_fn, (archive, abfd))
    252 
    253 /* Generic routines to use for BFD_JUMP_TABLE_GENERIC.  Use
    255    BFD_JUMP_TABLE_GENERIC (_bfd_generic).  */
    256 
    257 #define _bfd_generic_close_and_cleanup _bfd_archive_close_and_cleanup
    258 extern bool _bfd_archive_close_and_cleanup
    259   (bfd *) ATTRIBUTE_HIDDEN;
    260 extern void _bfd_unlink_from_archive_parent (bfd *) ATTRIBUTE_HIDDEN;
    261 #define _bfd_generic_bfd_free_cached_info _bfd_free_cached_info
    262 extern bool _bfd_generic_new_section_hook
    263   (bfd *, asection *) ATTRIBUTE_HIDDEN;
    264 extern bool _bfd_generic_get_section_contents
    265   (bfd *, asection *, void *, file_ptr, bfd_size_type) ATTRIBUTE_HIDDEN;
    266 
    267 /* Generic routines to use for BFD_JUMP_TABLE_COPY.  Use
    268    BFD_JUMP_TABLE_COPY (_bfd_generic).  */
    269 
    270 #define _bfd_generic_bfd_copy_private_bfd_data _bfd_bool_bfd_bfd_true
    271 #define _bfd_generic_bfd_merge_private_bfd_data \
    272   _bfd_bool_bfd_link_true
    273 #define _bfd_generic_bfd_set_private_flags _bfd_bool_bfd_uint_true
    274 #define _bfd_generic_bfd_copy_private_section_data \
    275   _bfd_bool_bfd_asection_bfd_asection_true
    276 #define _bfd_generic_bfd_copy_private_symbol_data \
    277   _bfd_bool_bfd_asymbol_bfd_asymbol_true
    278 #define _bfd_generic_bfd_copy_private_header_data _bfd_bool_bfd_bfd_true
    279 #define _bfd_generic_bfd_print_private_bfd_data _bfd_bool_bfd_ptr_true
    280 
    281 extern bool _bfd_generic_init_private_section_data
    282   (bfd *, asection *, bfd *, asection *, struct bfd_link_info *)
    283   ATTRIBUTE_HIDDEN;
    284 
    285 /* Routines to use for BFD_JUMP_TABLE_CORE when there is no core file
    286    support.  Use BFD_JUMP_TABLE_CORE (_bfd_nocore).  */
    287 
    288 extern char *_bfd_nocore_core_file_failing_command
    289   (bfd *) ATTRIBUTE_HIDDEN;
    290 extern int _bfd_nocore_core_file_failing_signal
    291   (bfd *) ATTRIBUTE_HIDDEN;
    292 extern bool _bfd_nocore_core_file_matches_executable_p
    293   (bfd *, bfd *) ATTRIBUTE_HIDDEN;
    294 extern int _bfd_nocore_core_file_pid
    295   (bfd *) ATTRIBUTE_HIDDEN;
    296 
    297 /* Routines to use for BFD_JUMP_TABLE_ARCHIVE when there is no archive
    298    file support.  Use BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive).  */
    299 
    300 #define _bfd_noarchive_slurp_armap _bfd_bool_bfd_false_error
    301 #define _bfd_noarchive_slurp_extended_name_table _bfd_bool_bfd_false_error
    302 extern bool _bfd_noarchive_construct_extended_name_table
    303   (bfd *, char **, bfd_size_type *, const char **) ATTRIBUTE_HIDDEN;
    304 extern void _bfd_noarchive_truncate_arname
    305   (bfd *, const char *, char *) ATTRIBUTE_HIDDEN;
    306 extern bool _bfd_noarchive_write_armap
    307   (bfd *, unsigned int, struct orl *, unsigned int, int) ATTRIBUTE_HIDDEN;
    308 #define _bfd_noarchive_read_ar_hdr _bfd_ptr_bfd_null_error
    309 extern bool _bfd_noarchive_write_ar_hdr
    310   (bfd *, bfd *) ATTRIBUTE_HIDDEN;
    311 extern bfd *
    312 _bfd_noarchive_openr_next_archived_file
    313   (bfd *, bfd *) ATTRIBUTE_HIDDEN;
    314 extern bfd * _bfd_noarchive_get_elt_at_index
    315   (bfd *, symindex) ATTRIBUTE_HIDDEN;
    316 #define _bfd_noarchive_generic_stat_arch_elt bfd_generic_stat_arch_elt
    317 #define _bfd_noarchive_update_armap_timestamp _bfd_bool_bfd_false_error
    318 
    319 /* Routines to use for BFD_JUMP_TABLE_ARCHIVE to get BSD style
    320    archives.  Use BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_bsd).  */
    321 
    322 #define _bfd_archive_bsd_slurp_armap bfd_slurp_bsd_armap
    323 #define _bfd_archive_bsd_slurp_extended_name_table \
    324   _bfd_slurp_extended_name_table
    325 extern bool _bfd_archive_bsd_construct_extended_name_table
    326   (bfd *, char **, bfd_size_type *, const char **) ATTRIBUTE_HIDDEN;
    327 #define _bfd_archive_bsd_truncate_arname bfd_bsd_truncate_arname
    328 #define _bfd_archive_bsd_write_armap _bfd_bsd_write_armap
    329 #define _bfd_archive_bsd_read_ar_hdr _bfd_generic_read_ar_hdr
    330 #define _bfd_archive_bsd_write_ar_hdr _bfd_generic_write_ar_hdr
    331 #define _bfd_archive_bsd_openr_next_archived_file \
    332   bfd_generic_openr_next_archived_file
    333 #define _bfd_archive_bsd_get_elt_at_index _bfd_generic_get_elt_at_index
    334 #define _bfd_archive_bsd_generic_stat_arch_elt \
    335   bfd_generic_stat_arch_elt
    336 extern bool _bfd_archive_bsd_update_armap_timestamp
    337   (bfd *) ATTRIBUTE_HIDDEN;
    338 
    339 /* Routines to use for BFD_JUMP_TABLE_ARCHIVE to get COFF style
    340    archives.  Use BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff).  */
    341 
    342 #define _bfd_archive_coff_slurp_armap bfd_slurp_coff_armap
    343 #define _bfd_archive_coff_slurp_extended_name_table \
    344   _bfd_slurp_extended_name_table
    345 extern bool _bfd_archive_coff_construct_extended_name_table
    346   (bfd *, char **, bfd_size_type *, const char **) ATTRIBUTE_HIDDEN;
    347 #define _bfd_archive_coff_truncate_arname bfd_dont_truncate_arname
    348 #define _bfd_archive_coff_write_armap _bfd_coff_write_armap
    349 #define _bfd_archive_coff_read_ar_hdr _bfd_generic_read_ar_hdr
    350 #define _bfd_archive_coff_write_ar_hdr _bfd_generic_write_ar_hdr
    351 #define _bfd_archive_coff_openr_next_archived_file \
    352   bfd_generic_openr_next_archived_file
    353 #define _bfd_archive_coff_get_elt_at_index _bfd_generic_get_elt_at_index
    354 #define _bfd_archive_coff_generic_stat_arch_elt \
    355   bfd_generic_stat_arch_elt
    356 #define _bfd_archive_coff_update_armap_timestamp _bfd_bool_bfd_true
    357 
    358 /* Routines to use for BFD_JUMP_TABLE_ARCHIVE to get BSD4.4 style
    359    archives.  Use BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_bsd44).  */
    360 
    361 #define _bfd_archive_bsd44_slurp_armap bfd_slurp_bsd_armap
    362 #define _bfd_archive_bsd44_slurp_extended_name_table \
    363   _bfd_slurp_extended_name_table
    364 extern bool _bfd_archive_bsd44_construct_extended_name_table
    365   (bfd *, char **, bfd_size_type *, const char **) ATTRIBUTE_HIDDEN;
    366 #define _bfd_archive_bsd44_truncate_arname bfd_bsd_truncate_arname
    367 #define _bfd_archive_bsd44_write_armap _bfd_bsd_write_armap
    368 #define _bfd_archive_bsd44_read_ar_hdr _bfd_generic_read_ar_hdr
    369 #define _bfd_archive_bsd44_write_ar_hdr _bfd_bsd44_write_ar_hdr
    370 #define _bfd_archive_bsd44_openr_next_archived_file \
    371   bfd_generic_openr_next_archived_file
    372 #define _bfd_archive_bsd44_get_elt_at_index _bfd_generic_get_elt_at_index
    373 #define _bfd_archive_bsd44_generic_stat_arch_elt \
    374   bfd_generic_stat_arch_elt
    375 #define _bfd_archive_bsd44_update_armap_timestamp \
    376   _bfd_archive_bsd_update_armap_timestamp
    377 
    378 /* Routines to use for BFD_JUMP_TABLE_ARCHIVE to get VMS style
    379    archives.  Use BFD_JUMP_TABLE_ARCHIVE (_bfd_vms_lib).  Some of them
    380    are irrelevant.  */
    381 
    382 extern bool _bfd_vms_lib_write_archive_contents
    383   (bfd *) ATTRIBUTE_HIDDEN;
    384 #define _bfd_vms_lib_slurp_armap _bfd_noarchive_slurp_armap
    385 #define _bfd_vms_lib_slurp_extended_name_table \
    386   _bfd_noarchive_slurp_extended_name_table
    387 #define _bfd_vms_lib_construct_extended_name_table \
    388   _bfd_noarchive_construct_extended_name_table
    389 #define _bfd_vms_lib_truncate_arname _bfd_noarchive_truncate_arname
    390 #define _bfd_vms_lib_write_armap _bfd_noarchive_write_armap
    391 #define _bfd_vms_lib_read_ar_hdr _bfd_noarchive_read_ar_hdr
    392 #define _bfd_vms_lib_write_ar_hdr _bfd_noarchive_write_ar_hdr
    393 extern bfd *_bfd_vms_lib_openr_next_archived_file
    394   (bfd *, bfd *) ATTRIBUTE_HIDDEN;
    395 extern bfd *_bfd_vms_lib_get_elt_at_index
    396   (bfd *, symindex) ATTRIBUTE_HIDDEN;
    397 extern int _bfd_vms_lib_generic_stat_arch_elt
    398   (bfd *, struct stat *) ATTRIBUTE_HIDDEN;
    399 #define _bfd_vms_lib_update_armap_timestamp _bfd_bool_bfd_true
    400 
    401 /* Extra routines for VMS style archives.  */
    402 
    403 extern symindex _bfd_vms_lib_find_symbol
    404   (bfd *, const char *) ATTRIBUTE_HIDDEN;
    405 extern bfd *_bfd_vms_lib_get_imagelib_file
    406   (bfd *) ATTRIBUTE_HIDDEN;
    407 extern bfd_cleanup _bfd_vms_lib_alpha_archive_p
    408   (bfd *) ATTRIBUTE_HIDDEN;
    409 extern bfd_cleanup _bfd_vms_lib_ia64_archive_p
    410   (bfd *) ATTRIBUTE_HIDDEN;
    411 extern bool _bfd_vms_lib_alpha_mkarchive
    412   (bfd *) ATTRIBUTE_HIDDEN;
    413 extern bool _bfd_vms_lib_ia64_mkarchive
    414   (bfd *) ATTRIBUTE_HIDDEN;
    415 
    416 /* Routines to use for BFD_JUMP_TABLE_SYMBOLS where there is no symbol
    417    support.  Use BFD_JUMP_TABLE_SYMBOLS (_bfd_nosymbols).  */
    418 
    419 #define _bfd_nosymbols_get_symtab_upper_bound _bfd_long_bfd_n1_error
    420 extern long _bfd_nosymbols_canonicalize_symtab
    421   (bfd *, asymbol **) ATTRIBUTE_HIDDEN;
    422 #define _bfd_nosymbols_make_empty_symbol _bfd_generic_make_empty_symbol
    423 extern void _bfd_nosymbols_print_symbol
    424   (bfd *, void *, asymbol *, bfd_print_symbol_type) ATTRIBUTE_HIDDEN;
    425 extern void _bfd_nosymbols_get_symbol_info
    426   (bfd *, asymbol *, symbol_info *) ATTRIBUTE_HIDDEN;
    427 extern const char * _bfd_nosymbols_get_symbol_version_string
    428   (bfd *, asymbol *, bool, bool *) ATTRIBUTE_HIDDEN;
    429 extern bool _bfd_nosymbols_bfd_is_local_label_name
    430   (bfd *, const char *) ATTRIBUTE_HIDDEN;
    431 #define _bfd_nosymbols_bfd_is_target_special_symbol _bfd_bool_bfd_asymbol_false
    432 extern alent *_bfd_nosymbols_get_lineno
    433   (bfd *, asymbol *) ATTRIBUTE_HIDDEN;
    434 extern bool _bfd_nosymbols_find_nearest_line
    435   (bfd *, asymbol **, asection *, bfd_vma,
    436    const char **, const char **, unsigned int *, unsigned int *)
    437   ATTRIBUTE_HIDDEN;
    438 extern bool _bfd_nosymbols_find_nearest_line_with_alt
    439   (bfd *, const char *, asymbol **, asection *, bfd_vma,
    440    const char **, const char **, unsigned int *, unsigned int *)
    441   ATTRIBUTE_HIDDEN;
    442 extern bool _bfd_nosymbols_find_line
    443   (bfd *, asymbol **, asymbol *, const char **, unsigned int *)
    444   ATTRIBUTE_HIDDEN;
    445 extern bool _bfd_nosymbols_find_inliner_info
    446   (bfd *, const char **, const char **, unsigned int *) ATTRIBUTE_HIDDEN;
    447 extern asymbol *_bfd_nosymbols_bfd_make_debug_symbol
    448   (bfd *) ATTRIBUTE_HIDDEN;
    449 extern long _bfd_nosymbols_read_minisymbols
    450   (bfd *, bool, void **, unsigned int *) ATTRIBUTE_HIDDEN;
    451 extern asymbol *_bfd_nosymbols_minisymbol_to_symbol
    452   (bfd *, bool, const void *, asymbol *) ATTRIBUTE_HIDDEN;
    453 
    454 /* Routines to use for BFD_JUMP_TABLE_RELOCS when there is no reloc
    455    support.  Use BFD_JUMP_TABLE_RELOCS (_bfd_norelocs).  */
    456 
    457 extern long _bfd_norelocs_get_reloc_upper_bound
    458   (bfd *, asection *) ATTRIBUTE_HIDDEN;
    459 extern long _bfd_norelocs_canonicalize_reloc
    460   (bfd *, asection *, arelent **, asymbol **) ATTRIBUTE_HIDDEN;
    461 extern void _bfd_norelocs_set_reloc
    462   (bfd *, asection *, arelent **, unsigned int) ATTRIBUTE_HIDDEN;
    463 extern reloc_howto_type *_bfd_norelocs_bfd_reloc_type_lookup
    464   (bfd *, bfd_reloc_code_real_type) ATTRIBUTE_HIDDEN;
    465 extern reloc_howto_type *_bfd_norelocs_bfd_reloc_name_lookup
    466   (bfd *, const char *) ATTRIBUTE_HIDDEN;
    467 
    468 /* Routines to use for BFD_JUMP_TABLE_WRITE for targets which may not
    469    be written.  Use BFD_JUMP_TABLE_WRITE (_bfd_nowrite).  */
    470 
    471 extern bool _bfd_nowrite_set_arch_mach
    472   (bfd *, enum bfd_architecture, unsigned long) ATTRIBUTE_HIDDEN;
    473 extern bool _bfd_nowrite_set_section_contents
    474   (bfd *, asection *, const void *, file_ptr, bfd_size_type) ATTRIBUTE_HIDDEN;
    475 
    476 /* Generic routines to use for BFD_JUMP_TABLE_WRITE.  Use
    477    BFD_JUMP_TABLE_WRITE (_bfd_generic).  */
    478 
    479 #define _bfd_generic_set_arch_mach bfd_default_set_arch_mach
    480 extern bool _bfd_generic_set_section_contents
    481   (bfd *, asection *, const void *, file_ptr, bfd_size_type) ATTRIBUTE_HIDDEN;
    482 
    483 /* Routines to use for BFD_JUMP_TABLE_LINK for targets which do not
    484    support linking.  Use BFD_JUMP_TABLE_LINK (_bfd_nolink).  */
    485 
    486 extern int _bfd_nolink_sizeof_headers
    487   (bfd *, struct bfd_link_info *) ATTRIBUTE_HIDDEN;
    488 extern bfd_byte *_bfd_nolink_bfd_get_relocated_section_contents
    489   (bfd *, struct bfd_link_info *, struct bfd_link_order *,
    490    bfd_byte *, bool, asymbol **) ATTRIBUTE_HIDDEN;
    491 extern bool _bfd_nolink_bfd_relax_section
    492   (bfd *, asection *, struct bfd_link_info *, bool *) ATTRIBUTE_HIDDEN;
    493 #define _bfd_nolink_bfd_gc_sections _bfd_bool_bfd_link_false_error
    494 extern bool _bfd_nolink_bfd_lookup_section_flags
    495   (struct bfd_link_info *, struct flag_info *, asection *) ATTRIBUTE_HIDDEN;
    496 #define _bfd_nolink_bfd_merge_sections _bfd_bool_bfd_link_false_error
    497 extern bool _bfd_nolink_bfd_is_group_section
    498   (bfd *, const asection *) ATTRIBUTE_HIDDEN;
    499 extern const char *_bfd_nolink_bfd_group_name
    500   (bfd *, const asection *) ATTRIBUTE_HIDDEN;
    501 extern bool _bfd_nolink_bfd_discard_group
    502   (bfd *, asection *) ATTRIBUTE_HIDDEN;
    503 extern struct bfd_link_hash_table *_bfd_nolink_bfd_link_hash_table_create
    504   (bfd *) ATTRIBUTE_HIDDEN;
    505 #define _bfd_nolink_bfd_link_add_symbols _bfd_bool_bfd_link_false_error
    506 extern void _bfd_nolink_bfd_link_just_syms
    507   (asection *, struct bfd_link_info *) ATTRIBUTE_HIDDEN;
    508 extern void _bfd_nolink_bfd_copy_link_hash_symbol_type
    509   (bfd *, struct bfd_link_hash_entry *, struct bfd_link_hash_entry *)
    510   ATTRIBUTE_HIDDEN;
    511 #define _bfd_nolink_bfd_final_link _bfd_bool_bfd_link_false_error
    512 extern bool _bfd_nolink_bfd_link_split_section
    513   (bfd *, struct bfd_section *) ATTRIBUTE_HIDDEN;
    514 extern bool _bfd_nolink_section_already_linked
    515   (bfd *, asection *, struct bfd_link_info *) ATTRIBUTE_HIDDEN;
    516 extern bool _bfd_nolink_bfd_define_common_symbol
    517   (bfd *, struct bfd_link_info *, struct bfd_link_hash_entry *)
    518   ATTRIBUTE_HIDDEN;
    519 #define _bfd_nolink_bfd_link_hide_symbol \
    520   _bfd_generic_link_hide_symbol
    521 extern struct bfd_link_hash_entry *_bfd_nolink_bfd_define_start_stop
    522   (struct bfd_link_info *, const char *, asection *) ATTRIBUTE_HIDDEN;
    523 #define _bfd_nolink_bfd_link_check_relocs \
    524   _bfd_generic_link_check_relocs
    525 
    526 /* Routines to use for BFD_JUMP_TABLE_DYNAMIC for targets which do not
    527    have dynamic symbols or relocs.  Use BFD_JUMP_TABLE_DYNAMIC
    528    (_bfd_nodynamic).  */
    529 
    530 #define _bfd_nodynamic_get_dynamic_symtab_upper_bound _bfd_long_bfd_n1_error
    531 #define _bfd_nodynamic_canonicalize_dynamic_symtab \
    532   _bfd_nosymbols_canonicalize_symtab
    533 extern long _bfd_nodynamic_get_synthetic_symtab
    534   (bfd *, long, asymbol **, long, asymbol **, asymbol **) ATTRIBUTE_HIDDEN;
    535 #define _bfd_nodynamic_get_dynamic_reloc_upper_bound _bfd_long_bfd_n1_error
    536 extern long _bfd_nodynamic_canonicalize_dynamic_reloc
    537   (bfd *, arelent **, asymbol **) ATTRIBUTE_HIDDEN;
    538 
    539 /* Generic routine to determine of the given symbol is a local
    541    label.  */
    542 extern bool bfd_generic_is_local_label_name
    543   (bfd *, const char *) ATTRIBUTE_HIDDEN;
    544 
    545 /* Generic minisymbol routines.  */
    546 extern long _bfd_generic_read_minisymbols
    547   (bfd *, bool, void **, unsigned int *) ATTRIBUTE_HIDDEN;
    548 extern asymbol *_bfd_generic_minisymbol_to_symbol
    549   (bfd *, bool, const void *, asymbol *) ATTRIBUTE_HIDDEN;
    550 
    551 /* Find the nearest line using .stab/.stabstr sections.  */
    552 extern bool _bfd_stab_section_find_nearest_line
    553   (bfd *, asymbol **, asection *, bfd_vma, bool *,
    554    const char **, const char **, unsigned int *, void **) ATTRIBUTE_HIDDEN;
    555 
    556 /* Find the nearest line using DWARF 1 debugging information.  */
    557 extern bool _bfd_dwarf1_find_nearest_line
    558   (bfd *, asymbol **, asection *, bfd_vma,
    559    const char **, const char **, unsigned int *) ATTRIBUTE_HIDDEN;
    560 
    561 /* Clean up the data used to handle DWARF 1 debugging information. */
    562 extern void _bfd_dwarf1_cleanup_debug_info
    563   (bfd *, void **) ATTRIBUTE_HIDDEN;
    564 
    565 struct dwarf_debug_section
    566 {
    567   const char * uncompressed_name;
    568   const char * compressed_name;
    569 };
    570 
    571 /* Map of uncompressed DWARF debug section name to compressed one.  It
    572    is terminated by NULL uncompressed_name.  */
    573 
    574 extern const struct dwarf_debug_section dwarf_debug_sections[] ATTRIBUTE_HIDDEN;
    575 
    576 /* Find the nearest line using DWARF 2 debugging information.  */
    577 extern int _bfd_dwarf2_find_nearest_line
    578   (bfd *, asymbol **, asymbol *, asection *, bfd_vma,
    579    const char **, const char **, unsigned int *, unsigned int *,
    580    const struct dwarf_debug_section *, void **) ATTRIBUTE_HIDDEN;
    581 
    582 /* Find the nearest line using DWARF 2 debugging information, with
    583    the option of specifying a .gnu_debugaltlink file.  */
    584 extern int _bfd_dwarf2_find_nearest_line_with_alt
    585   (bfd *, const char *, asymbol **, asymbol *, asection *, bfd_vma,
    586    const char **, const char **, unsigned int *, unsigned int *,
    587    const struct dwarf_debug_section *, void **) ATTRIBUTE_HIDDEN;
    588 
    589 /* Find the bias between DWARF addresses and real addresses.  */
    590 extern bfd_signed_vma _bfd_dwarf2_find_symbol_bias
    591   (asymbol **, void **) ATTRIBUTE_HIDDEN;
    592 
    593 /* Find inliner info after calling bfd_find_nearest_line. */
    594 extern bool _bfd_dwarf2_find_inliner_info
    595   (bfd *, const char **, const char **, unsigned int *, void **)
    596   ATTRIBUTE_HIDDEN;
    597 
    598 /* Read DWARF 2 debugging information. */
    599 extern bool _bfd_dwarf2_slurp_debug_info
    600   (bfd *, bfd *, const struct dwarf_debug_section *, asymbol **, void **,
    601    bool) ATTRIBUTE_HIDDEN;
    602 
    603 /* Clean up the data used to handle DWARF 2 debugging information. */
    604 extern void _bfd_dwarf2_cleanup_debug_info
    605   (bfd *, void **) ATTRIBUTE_HIDDEN;
    606 
    607 extern void _bfd_stab_cleanup
    608   (bfd *, void **) ATTRIBUTE_HIDDEN;
    609 
    610 /* Create a new section entry.  */
    611 extern struct bfd_hash_entry *bfd_section_hash_newfunc
    612   (struct bfd_hash_entry *, struct bfd_hash_table *, const char *)
    613   ATTRIBUTE_HIDDEN;
    614 
    615 /* A routine to create entries for a bfd_link_hash_table.  */
    616 extern struct bfd_hash_entry *_bfd_link_hash_newfunc
    617   (struct bfd_hash_entry *entry, struct bfd_hash_table *table,
    618    const char *string) ATTRIBUTE_HIDDEN;
    619 
    620 /* Initialize a bfd_link_hash_table.  */
    621 extern bool _bfd_link_hash_table_init
    622   (struct bfd_link_hash_table *, bfd *,
    623    struct bfd_hash_entry *(*) (struct bfd_hash_entry *,
    624 			       struct bfd_hash_table *,
    625 			       const char *),
    626    unsigned int) ATTRIBUTE_HIDDEN;
    627 
    628 /* Generic link hash table creation routine.  */
    629 extern struct bfd_link_hash_table *_bfd_generic_link_hash_table_create
    630   (bfd *) ATTRIBUTE_HIDDEN;
    631 
    632 /* Generic link hash table destruction routine.  */
    633 extern void _bfd_generic_link_hash_table_free
    634   (bfd *) ATTRIBUTE_HIDDEN;
    635 
    636 /* Generic add symbol routine.  */
    637 extern bool _bfd_generic_link_add_symbols
    638   (bfd *, struct bfd_link_info *) ATTRIBUTE_HIDDEN;
    639 
    640 /* Generic archive add symbol routine.  */
    641 extern bool _bfd_generic_link_add_archive_symbols
    642   (bfd *, struct bfd_link_info *,
    643    bool (*) (bfd *, struct bfd_link_info *,
    644 		    struct bfd_link_hash_entry *, const char *,
    645 		    bool *)) ATTRIBUTE_HIDDEN;
    646 
    647 /* Forward declaration to avoid prototype errors.  */
    648 typedef struct bfd_link_hash_entry _bfd_link_hash_entry;
    649 
    650 /* Generic routine to add a single symbol.  */
    651 extern bool _bfd_generic_link_add_one_symbol
    652   (struct bfd_link_info *, bfd *, const char *name, flagword,
    653    asection *, bfd_vma, const char *, bool copy,
    654    bool constructor, struct bfd_link_hash_entry **) ATTRIBUTE_HIDDEN;
    655 
    656 /* Generic routine to mark section as supplying symbols only.  */
    657 extern void _bfd_generic_link_just_syms
    658   (asection *, struct bfd_link_info *) ATTRIBUTE_HIDDEN;
    659 
    660 /* Generic routine that does nothing.  */
    661 extern void _bfd_generic_copy_link_hash_symbol_type
    662   (bfd *, struct bfd_link_hash_entry *, struct bfd_link_hash_entry *)
    663   ATTRIBUTE_HIDDEN;
    664 
    665 /* Generic link routine.  */
    666 extern bool _bfd_generic_final_link
    667   (bfd *, struct bfd_link_info *) ATTRIBUTE_HIDDEN;
    668 
    669 extern bool _bfd_generic_link_split_section
    670   (bfd *, struct bfd_section *) ATTRIBUTE_HIDDEN;
    671 
    672 extern bool _bfd_generic_section_already_linked
    673   (bfd *, asection *, struct bfd_link_info *) ATTRIBUTE_HIDDEN;
    674 
    675 /* Generic reloc_link_order processing routine.  */
    676 extern bool _bfd_generic_reloc_link_order
    677   (bfd *, struct bfd_link_info *, asection *, struct bfd_link_order *)
    678   ATTRIBUTE_HIDDEN;
    679 
    680 /* Default link order processing routine.  */
    681 extern bool _bfd_default_link_order
    682   (bfd *, struct bfd_link_info *, asection *, struct bfd_link_order *)
    683   ATTRIBUTE_HIDDEN;
    684 
    685 /* Count the number of reloc entries in a link order list.  */
    686 extern unsigned int _bfd_count_link_order_relocs
    687   (struct bfd_link_order *) ATTRIBUTE_HIDDEN;
    688 
    689 /* Final link relocation routine.  */
    690 extern bfd_reloc_status_type _bfd_final_link_relocate
    691   (reloc_howto_type *, bfd *, asection *, bfd_byte *,
    692    bfd_vma, bfd_vma, bfd_vma) ATTRIBUTE_HIDDEN;
    693 
    694 /* Relocate a particular location by a howto and a value.  */
    695 extern bfd_reloc_status_type _bfd_relocate_contents
    696   (reloc_howto_type *, bfd *, bfd_vma, bfd_byte *) ATTRIBUTE_HIDDEN;
    697 
    698 /* Clear a given location using a given howto.  */
    699 extern bfd_reloc_status_type _bfd_clear_contents
    700   (reloc_howto_type *, bfd *, asection *, bfd_byte *, bfd_vma) ATTRIBUTE_HIDDEN;
    701 
    702 /* Register a SEC_MERGE section as a candidate for merging.  */
    703 
    704 extern bool _bfd_add_merge_section
    705   (bfd *, void **, asection *, void **) ATTRIBUTE_HIDDEN;
    706 
    707 /* Attempt to merge SEC_MERGE sections.  */
    708 
    709 extern bool _bfd_merge_sections
    710   (bfd *, struct bfd_link_info *, void *, void (*) (bfd *, asection *))
    711   ATTRIBUTE_HIDDEN;
    712 
    713 /* Write out a merged section.  */
    714 
    715 extern bool _bfd_write_merged_section
    716   (bfd *, asection *, void *) ATTRIBUTE_HIDDEN;
    717 
    718 /* Find an offset within a modified SEC_MERGE section.  */
    719 
    720 extern bfd_vma _bfd_merged_section_offset
    721   (bfd *, asection **, void *, bfd_vma) ATTRIBUTE_HIDDEN;
    722 
    723 /* Tidy up when done.  */
    724 
    725 extern void _bfd_merge_sections_free (void *) ATTRIBUTE_HIDDEN;
    726 
    727 /* Macros to tell if bfds are read or write enabled.
    728 
    729    Note that bfds open for read may be scribbled into if the fd passed
    730    to bfd_fdopenr is actually open both for read and write
    731    simultaneously.  However an output bfd will never be open for
    732    read.  Therefore sometimes you want to check bfd_read_p or
    733    !bfd_read_p, and only sometimes bfd_write_p.
    734 */
    735 
    736 #define	bfd_read_p(abfd) \
    737   ((abfd)->direction == read_direction || (abfd)->direction == both_direction)
    738 #define	bfd_write_p(abfd) \
    739   ((abfd)->direction == write_direction || (abfd)->direction == both_direction)
    740 
    741 extern void bfd_assert
    742   (const char*,int) ATTRIBUTE_HIDDEN;
    743 
    744 #define BFD_ASSERT(x) \
    745   do { if (!(x)) bfd_assert(__FILE__,__LINE__); } while (0)
    746 
    747 #define BFD_FAIL() \
    748   do { bfd_assert(__FILE__,__LINE__); } while (0)
    749 
    750 extern void _bfd_abort
    751   (const char *, int, const char *) ATTRIBUTE_NORETURN ATTRIBUTE_HIDDEN;
    752 
    753 /* if gcc >= 2.6, we can give a function name, too */
    754 #if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 6)
    755 #define __PRETTY_FUNCTION__  ((char *) NULL)
    756 #endif
    757 
    758 #undef abort
    759 #define abort() _bfd_abort (__FILE__, __LINE__, __PRETTY_FUNCTION__)
    760 
    761 /* Manipulate a system FILE but using BFD's "file_ptr", rather than
    762    the system "off_t" or "off64_t", as the offset.  */
    763 extern file_ptr _bfd_real_ftell
    764   (FILE *) ATTRIBUTE_HIDDEN;
    765 extern int _bfd_real_fseek
    766   (FILE *, file_ptr, int) ATTRIBUTE_HIDDEN;
    767 extern FILE *_bfd_real_fopen
    768   (const char *, const char *) ATTRIBUTE_HIDDEN;
    769 
    770 /* List of supported target vectors, and the default vector (if
    771    bfd_default_vector[0] is NULL, there is no default).  */
    772 extern const bfd_target *const *const bfd_target_vector ATTRIBUTE_HIDDEN;
    773 extern const bfd_target *bfd_default_vector[] ATTRIBUTE_HIDDEN;
    774 
    775 /* List of associated target vectors.  */
    776 extern const bfd_target *const *const bfd_associated_vector ATTRIBUTE_HIDDEN;
    777 
    778 /* Functions shared by the ECOFF and MIPS ELF backends, which have no
    779    other common header files.  */
    780 
    781 struct ecoff_debug_info;
    782 struct ecoff_debug_swap;
    783 struct ecoff_extr;
    784 struct ecoff_find_line;
    785 
    786 extern void _bfd_ecoff_free_ecoff_debug_info
    787   (struct ecoff_debug_info *debug);
    788 extern bool _bfd_ecoff_locate_line
    789   (bfd *, asection *, bfd_vma, struct ecoff_debug_info * const,
    790    const struct ecoff_debug_swap * const, struct ecoff_find_line *,
    791    const char **, const char **, unsigned int *) ATTRIBUTE_HIDDEN;
    792 extern bool _bfd_ecoff_get_accumulated_pdr
    793   (void *, bfd_byte *) ATTRIBUTE_HIDDEN;
    794 extern bool _bfd_ecoff_get_accumulated_sym
    795   (void *, bfd_byte *) ATTRIBUTE_HIDDEN;
    796 extern bool _bfd_ecoff_get_accumulated_ss
    797   (void *, bfd_byte *) ATTRIBUTE_HIDDEN;
    798 
    799 extern bfd_vma _bfd_get_gp_value
    800   (bfd *) ATTRIBUTE_HIDDEN;
    801 extern void _bfd_set_gp_value
    802   (bfd *, bfd_vma) ATTRIBUTE_HIDDEN;
    803 
    804 /* Function shared by the COFF and ELF SH backends, which have no
    805    other common header files.  */
    806 
    807 #ifndef _bfd_sh_align_load_span
    808 extern bool _bfd_sh_align_load_span
    809   (bfd *, asection *, bfd_byte *,
    810    bool (*) (bfd *, asection *, void *, bfd_byte *, bfd_vma),
    811    void *, bfd_vma **, bfd_vma *, bfd_vma, bfd_vma, bool *) ATTRIBUTE_HIDDEN;
    812 #endif
    813 
    814 /* This is the shape of the elements inside the already_linked hash
    815    table. It maps a name onto a list of already_linked elements with
    816    the same name.  */
    817 
    818 struct bfd_section_already_linked_hash_entry
    819 {
    820   struct bfd_hash_entry root;
    821   struct bfd_section_already_linked *entry;
    822 };
    823 
    824 struct bfd_section_already_linked
    825 {
    826   struct bfd_section_already_linked *next;
    827   asection *sec;
    828 };
    829 
    830 extern struct bfd_section_already_linked_hash_entry *
    831   bfd_section_already_linked_table_lookup (const char *) ATTRIBUTE_HIDDEN;
    832 extern bool bfd_section_already_linked_table_insert
    833   (struct bfd_section_already_linked_hash_entry *, asection *)
    834   ATTRIBUTE_HIDDEN;
    835 extern void bfd_section_already_linked_table_traverse
    836   (bool (*) (struct bfd_section_already_linked_hash_entry *,
    837 		    void *), void *) ATTRIBUTE_HIDDEN;
    838 
    839 extern bfd_vma _bfd_read_unsigned_leb128
    840   (bfd *, bfd_byte *, unsigned int *) ATTRIBUTE_HIDDEN;
    841 extern bfd_signed_vma _bfd_read_signed_leb128
    842   (bfd *, bfd_byte *, unsigned int *) ATTRIBUTE_HIDDEN;
    843 extern bfd_vma _bfd_safe_read_leb128
    844   (bfd *, bfd_byte **, bool, const bfd_byte * const) ATTRIBUTE_HIDDEN;
    845 extern bfd_byte * _bfd_write_unsigned_leb128
    846   (bfd_byte *, bfd_byte *, bfd_vma) ATTRIBUTE_HIDDEN;
    847 
    848 extern struct bfd_link_info *_bfd_get_link_info (bfd *)
    849   ATTRIBUTE_HIDDEN;
    850 
    851 #ifdef HAVE_MMAP
    852 extern uintptr_t _bfd_pagesize ATTRIBUTE_HIDDEN;
    853 extern uintptr_t _bfd_pagesize_m1 ATTRIBUTE_HIDDEN;
    854 extern uintptr_t _bfd_minimum_mmap_size ATTRIBUTE_HIDDEN;
    855 #endif
    856 
    857 #if GCC_VERSION >= 7000
    858 #define _bfd_mul_overflow(a, b, res) __builtin_mul_overflow (a, b, res)
    859 #else
    860 /* Assumes unsigned values.  Careful!  Args evaluated multiple times.  */
    861 #define _bfd_mul_overflow(a, b, res) \
    862   ((*res) = (a), (*res) *= (b), (b) != 0 && (*res) / (b) != (a))
    863 #endif
    864 
    865 #ifdef __GNUC__
    866 #define _bfd_constant_p(v) __builtin_constant_p (v)
    867 #else
    868 #define _bfd_constant_p(v) 0
    869 #endif
    870 
    871 static inline void *
    872 _bfd_alloc_and_read (bfd *abfd, bfd_size_type asize, bfd_size_type rsize)
    873 {
    874   void *mem;
    875   if (!_bfd_constant_p (rsize))
    876     {
    877       ufile_ptr filesize = bfd_get_file_size (abfd);
    878       if (filesize != 0 && rsize > filesize)
    879 	{
    880 	  bfd_set_error (bfd_error_file_truncated);
    881 	  return NULL;
    882 	}
    883     }
    884   mem = bfd_alloc (abfd, asize);
    885   if (mem != NULL)
    886     {
    887       if (bfd_read (mem, rsize, abfd) == rsize)
    888 	return mem;
    889       bfd_release (abfd, mem);
    890     }
    891   return NULL;
    892 }
    893 
    894 #ifdef USE_MMAP
    895 extern void *_bfd_mmap_readonly_persistent
    896   (bfd *, size_t) ATTRIBUTE_HIDDEN;
    897 extern void *_bfd_mmap_readonly_temporary
    898   (bfd *, size_t, void **, size_t *) ATTRIBUTE_HIDDEN;
    899 extern void _bfd_munmap_readonly_temporary
    900   (void *, size_t) ATTRIBUTE_HIDDEN;
    901 #else
    902 #define _bfd_mmap_readonly_persistent(abfd, rsize) \
    903   _bfd_alloc_and_read (abfd, rsize, rsize)
    904 #define _bfd_munmap_readonly_temporary(ptr, rsize) free (ptr)
    905 #endif
    906 
    907 extern bool _bfd_mmap_read_temporary
    908   (void **, size_t *, void **, bfd *, bool) ATTRIBUTE_HIDDEN;
    909 
    910 static inline void *
    911 _bfd_malloc_and_read (bfd *abfd, bfd_size_type asize, bfd_size_type rsize)
    912 {
    913   void *mem;
    914   if (!_bfd_constant_p (rsize))
    915     {
    916       ufile_ptr filesize = bfd_get_file_size (abfd);
    917       if (filesize != 0 && rsize > filesize)
    918 	{
    919 	  bfd_set_error (bfd_error_file_truncated);
    920 	  return NULL;
    921 	}
    922     }
    923   mem = bfd_malloc (asize);
    924   if (mem != NULL)
    925     {
    926       if (bfd_read (mem, rsize, abfd) == rsize)
    927 	return mem;
    928       free (mem);
    929     }
    930   return NULL;
    931 }
    932 
    933 #ifndef USE_MMAP
    934 static inline void *
    935 _bfd_mmap_readonly_temporary (bfd *abfd, size_t rsize, void **map_addr,
    936 			      size_t *map_size)
    937 {
    938   void *mem = _bfd_malloc_and_read (abfd, rsize, rsize);
    939   *map_addr = mem;
    940   *map_size = rsize;
    941   return mem;
    942 }
    943 #endif
    944