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