xref: /netbsd-src/external/gpl3/gdb/dist/bfd/libbfd-in.h (revision a98fd9fedc59047f86335703dc9412a2a1de84ff)
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
254    BFD_JUMP_TABLE_GENERIC (_bfd_generic).  */
255 
256 #define _bfd_generic_close_and_cleanup _bfd_archive_close_and_cleanup
257 extern bool _bfd_archive_close_and_cleanup
258   (bfd *) ATTRIBUTE_HIDDEN;
259 extern void _bfd_unlink_from_archive_parent (bfd *) ATTRIBUTE_HIDDEN;
260 #define _bfd_generic_bfd_free_cached_info _bfd_free_cached_info
261 extern bool _bfd_generic_new_section_hook
262   (bfd *, asection *) ATTRIBUTE_HIDDEN;
263 extern bool _bfd_generic_get_section_contents
264   (bfd *, asection *, void *, file_ptr, bfd_size_type) ATTRIBUTE_HIDDEN;
265 
266 /* Generic routines to use for BFD_JUMP_TABLE_COPY.  Use
267    BFD_JUMP_TABLE_COPY (_bfd_generic).  */
268 
269 #define _bfd_generic_bfd_copy_private_bfd_data _bfd_bool_bfd_bfd_true
270 #define _bfd_generic_bfd_merge_private_bfd_data \
271   _bfd_bool_bfd_link_true
272 #define _bfd_generic_bfd_set_private_flags _bfd_bool_bfd_uint_true
273 #define _bfd_generic_bfd_copy_private_section_data \
274   _bfd_bool_bfd_asection_bfd_asection_true
275 #define _bfd_generic_bfd_copy_private_symbol_data \
276   _bfd_bool_bfd_asymbol_bfd_asymbol_true
277 #define _bfd_generic_bfd_copy_private_header_data _bfd_bool_bfd_bfd_true
278 #define _bfd_generic_bfd_print_private_bfd_data _bfd_bool_bfd_ptr_true
279 
280 extern bool _bfd_generic_init_private_section_data
281   (bfd *, asection *, bfd *, asection *, struct bfd_link_info *)
282   ATTRIBUTE_HIDDEN;
283 
284 /* Routines to use for BFD_JUMP_TABLE_CORE when there is no core file
285    support.  Use BFD_JUMP_TABLE_CORE (_bfd_nocore).  */
286 
287 extern char *_bfd_nocore_core_file_failing_command
288   (bfd *) ATTRIBUTE_HIDDEN;
289 extern int _bfd_nocore_core_file_failing_signal
290   (bfd *) ATTRIBUTE_HIDDEN;
291 extern bool _bfd_nocore_core_file_matches_executable_p
292   (bfd *, bfd *) ATTRIBUTE_HIDDEN;
293 extern int _bfd_nocore_core_file_pid
294   (bfd *) ATTRIBUTE_HIDDEN;
295 
296 /* Routines to use for BFD_JUMP_TABLE_ARCHIVE when there is no archive
297    file support.  Use BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive).  */
298 
299 #define _bfd_noarchive_slurp_armap _bfd_bool_bfd_false_error
300 #define _bfd_noarchive_slurp_extended_name_table _bfd_bool_bfd_false_error
301 extern bool _bfd_noarchive_construct_extended_name_table
302   (bfd *, char **, bfd_size_type *, const char **) ATTRIBUTE_HIDDEN;
303 extern void _bfd_noarchive_truncate_arname
304   (bfd *, const char *, char *) ATTRIBUTE_HIDDEN;
305 extern bool _bfd_noarchive_write_armap
306   (bfd *, unsigned int, struct orl *, unsigned int, int) ATTRIBUTE_HIDDEN;
307 #define _bfd_noarchive_read_ar_hdr _bfd_ptr_bfd_null_error
308 extern bool _bfd_noarchive_write_ar_hdr
309   (bfd *, bfd *) ATTRIBUTE_HIDDEN;
310 extern bfd *
311 _bfd_noarchive_openr_next_archived_file
312   (bfd *, bfd *) ATTRIBUTE_HIDDEN;
313 extern bfd * _bfd_noarchive_get_elt_at_index
314   (bfd *, symindex) ATTRIBUTE_HIDDEN;
315 #define _bfd_noarchive_generic_stat_arch_elt bfd_generic_stat_arch_elt
316 #define _bfd_noarchive_update_armap_timestamp _bfd_bool_bfd_false_error
317 
318 /* Routines to use for BFD_JUMP_TABLE_ARCHIVE to get BSD style
319    archives.  Use BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_bsd).  */
320 
321 #define _bfd_archive_bsd_slurp_armap bfd_slurp_bsd_armap
322 #define _bfd_archive_bsd_slurp_extended_name_table \
323   _bfd_slurp_extended_name_table
324 extern bool _bfd_archive_bsd_construct_extended_name_table
325   (bfd *, char **, bfd_size_type *, const char **) ATTRIBUTE_HIDDEN;
326 #define _bfd_archive_bsd_truncate_arname bfd_bsd_truncate_arname
327 #define _bfd_archive_bsd_write_armap _bfd_bsd_write_armap
328 #define _bfd_archive_bsd_read_ar_hdr _bfd_generic_read_ar_hdr
329 #define _bfd_archive_bsd_write_ar_hdr _bfd_generic_write_ar_hdr
330 #define _bfd_archive_bsd_openr_next_archived_file \
331   bfd_generic_openr_next_archived_file
332 #define _bfd_archive_bsd_get_elt_at_index _bfd_generic_get_elt_at_index
333 #define _bfd_archive_bsd_generic_stat_arch_elt \
334   bfd_generic_stat_arch_elt
335 extern bool _bfd_archive_bsd_update_armap_timestamp
336   (bfd *) ATTRIBUTE_HIDDEN;
337 
338 /* Routines to use for BFD_JUMP_TABLE_ARCHIVE to get COFF style
339    archives.  Use BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff).  */
340 
341 #define _bfd_archive_coff_slurp_armap bfd_slurp_coff_armap
342 #define _bfd_archive_coff_slurp_extended_name_table \
343   _bfd_slurp_extended_name_table
344 extern bool _bfd_archive_coff_construct_extended_name_table
345   (bfd *, char **, bfd_size_type *, const char **) ATTRIBUTE_HIDDEN;
346 #define _bfd_archive_coff_truncate_arname bfd_dont_truncate_arname
347 #define _bfd_archive_coff_write_armap _bfd_coff_write_armap
348 #define _bfd_archive_coff_read_ar_hdr _bfd_generic_read_ar_hdr
349 #define _bfd_archive_coff_write_ar_hdr _bfd_generic_write_ar_hdr
350 #define _bfd_archive_coff_openr_next_archived_file \
351   bfd_generic_openr_next_archived_file
352 #define _bfd_archive_coff_get_elt_at_index _bfd_generic_get_elt_at_index
353 #define _bfd_archive_coff_generic_stat_arch_elt \
354   bfd_generic_stat_arch_elt
355 #define _bfd_archive_coff_update_armap_timestamp _bfd_bool_bfd_true
356 
357 /* Routines to use for BFD_JUMP_TABLE_ARCHIVE to get BSD4.4 style
358    archives.  Use BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_bsd44).  */
359 
360 #define _bfd_archive_bsd44_slurp_armap bfd_slurp_bsd_armap
361 #define _bfd_archive_bsd44_slurp_extended_name_table \
362   _bfd_slurp_extended_name_table
363 extern bool _bfd_archive_bsd44_construct_extended_name_table
364   (bfd *, char **, bfd_size_type *, const char **) ATTRIBUTE_HIDDEN;
365 #define _bfd_archive_bsd44_truncate_arname bfd_bsd_truncate_arname
366 #define _bfd_archive_bsd44_write_armap _bfd_bsd_write_armap
367 #define _bfd_archive_bsd44_read_ar_hdr _bfd_generic_read_ar_hdr
368 #define _bfd_archive_bsd44_write_ar_hdr _bfd_bsd44_write_ar_hdr
369 #define _bfd_archive_bsd44_openr_next_archived_file \
370   bfd_generic_openr_next_archived_file
371 #define _bfd_archive_bsd44_get_elt_at_index _bfd_generic_get_elt_at_index
372 #define _bfd_archive_bsd44_generic_stat_arch_elt \
373   bfd_generic_stat_arch_elt
374 #define _bfd_archive_bsd44_update_armap_timestamp \
375   _bfd_archive_bsd_update_armap_timestamp
376 
377 /* Routines to use for BFD_JUMP_TABLE_ARCHIVE to get VMS style
378    archives.  Use BFD_JUMP_TABLE_ARCHIVE (_bfd_vms_lib).  Some of them
379    are irrelevant.  */
380 
381 extern bool _bfd_vms_lib_write_archive_contents
382   (bfd *) ATTRIBUTE_HIDDEN;
383 #define _bfd_vms_lib_slurp_armap _bfd_noarchive_slurp_armap
384 #define _bfd_vms_lib_slurp_extended_name_table \
385   _bfd_noarchive_slurp_extended_name_table
386 #define _bfd_vms_lib_construct_extended_name_table \
387   _bfd_noarchive_construct_extended_name_table
388 #define _bfd_vms_lib_truncate_arname _bfd_noarchive_truncate_arname
389 #define _bfd_vms_lib_write_armap _bfd_noarchive_write_armap
390 #define _bfd_vms_lib_read_ar_hdr _bfd_noarchive_read_ar_hdr
391 #define _bfd_vms_lib_write_ar_hdr _bfd_noarchive_write_ar_hdr
392 extern bfd *_bfd_vms_lib_openr_next_archived_file
393   (bfd *, bfd *) ATTRIBUTE_HIDDEN;
394 extern bfd *_bfd_vms_lib_get_elt_at_index
395   (bfd *, symindex) ATTRIBUTE_HIDDEN;
396 extern int _bfd_vms_lib_generic_stat_arch_elt
397   (bfd *, struct stat *) ATTRIBUTE_HIDDEN;
398 #define _bfd_vms_lib_update_armap_timestamp _bfd_bool_bfd_true
399 
400 /* Extra routines for VMS style archives.  */
401 
402 extern symindex _bfd_vms_lib_find_symbol
403   (bfd *, const char *) ATTRIBUTE_HIDDEN;
404 extern bfd *_bfd_vms_lib_get_imagelib_file
405   (bfd *) ATTRIBUTE_HIDDEN;
406 extern bfd_cleanup _bfd_vms_lib_alpha_archive_p
407   (bfd *) ATTRIBUTE_HIDDEN;
408 extern bfd_cleanup _bfd_vms_lib_ia64_archive_p
409   (bfd *) ATTRIBUTE_HIDDEN;
410 extern bool _bfd_vms_lib_alpha_mkarchive
411   (bfd *) ATTRIBUTE_HIDDEN;
412 extern bool _bfd_vms_lib_ia64_mkarchive
413   (bfd *) ATTRIBUTE_HIDDEN;
414 
415 /* Routines to use for BFD_JUMP_TABLE_SYMBOLS where there is no symbol
416    support.  Use BFD_JUMP_TABLE_SYMBOLS (_bfd_nosymbols).  */
417 
418 #define _bfd_nosymbols_get_symtab_upper_bound _bfd_long_bfd_n1_error
419 extern long _bfd_nosymbols_canonicalize_symtab
420   (bfd *, asymbol **) ATTRIBUTE_HIDDEN;
421 #define _bfd_nosymbols_make_empty_symbol _bfd_generic_make_empty_symbol
422 extern void _bfd_nosymbols_print_symbol
423   (bfd *, void *, asymbol *, bfd_print_symbol_type) ATTRIBUTE_HIDDEN;
424 extern void _bfd_nosymbols_get_symbol_info
425   (bfd *, asymbol *, symbol_info *) ATTRIBUTE_HIDDEN;
426 extern const char * _bfd_nosymbols_get_symbol_version_string
427   (bfd *, asymbol *, bool, bool *) ATTRIBUTE_HIDDEN;
428 extern bool _bfd_nosymbols_bfd_is_local_label_name
429   (bfd *, const char *) ATTRIBUTE_HIDDEN;
430 #define _bfd_nosymbols_bfd_is_target_special_symbol _bfd_bool_bfd_asymbol_false
431 extern alent *_bfd_nosymbols_get_lineno
432   (bfd *, asymbol *) ATTRIBUTE_HIDDEN;
433 extern bool _bfd_nosymbols_find_nearest_line
434   (bfd *, asymbol **, asection *, bfd_vma,
435    const char **, const char **, unsigned int *, unsigned int *)
436   ATTRIBUTE_HIDDEN;
437 extern bool _bfd_nosymbols_find_nearest_line_with_alt
438   (bfd *, const char *, asymbol **, asection *, bfd_vma,
439    const char **, const char **, unsigned int *, unsigned int *)
440   ATTRIBUTE_HIDDEN;
441 extern bool _bfd_nosymbols_find_line
442   (bfd *, asymbol **, asymbol *, const char **, unsigned int *)
443   ATTRIBUTE_HIDDEN;
444 extern bool _bfd_nosymbols_find_inliner_info
445   (bfd *, const char **, const char **, unsigned int *) ATTRIBUTE_HIDDEN;
446 extern asymbol *_bfd_nosymbols_bfd_make_debug_symbol
447   (bfd *) ATTRIBUTE_HIDDEN;
448 extern long _bfd_nosymbols_read_minisymbols
449   (bfd *, bool, void **, unsigned int *) ATTRIBUTE_HIDDEN;
450 extern asymbol *_bfd_nosymbols_minisymbol_to_symbol
451   (bfd *, bool, const void *, asymbol *) ATTRIBUTE_HIDDEN;
452 
453 /* Routines to use for BFD_JUMP_TABLE_RELOCS when there is no reloc
454    support.  Use BFD_JUMP_TABLE_RELOCS (_bfd_norelocs).  */
455 
456 extern long _bfd_norelocs_get_reloc_upper_bound
457   (bfd *, asection *) ATTRIBUTE_HIDDEN;
458 extern long _bfd_norelocs_canonicalize_reloc
459   (bfd *, asection *, arelent **, asymbol **) ATTRIBUTE_HIDDEN;
460 extern void _bfd_norelocs_set_reloc
461   (bfd *, asection *, arelent **, unsigned int) ATTRIBUTE_HIDDEN;
462 extern reloc_howto_type *_bfd_norelocs_bfd_reloc_type_lookup
463   (bfd *, bfd_reloc_code_real_type) ATTRIBUTE_HIDDEN;
464 extern reloc_howto_type *_bfd_norelocs_bfd_reloc_name_lookup
465   (bfd *, const char *) ATTRIBUTE_HIDDEN;
466 
467 /* Routines to use for BFD_JUMP_TABLE_WRITE for targets which may not
468    be written.  Use BFD_JUMP_TABLE_WRITE (_bfd_nowrite).  */
469 
470 extern bool _bfd_nowrite_set_arch_mach
471   (bfd *, enum bfd_architecture, unsigned long) ATTRIBUTE_HIDDEN;
472 extern bool _bfd_nowrite_set_section_contents
473   (bfd *, asection *, const void *, file_ptr, bfd_size_type) ATTRIBUTE_HIDDEN;
474 
475 /* Generic routines to use for BFD_JUMP_TABLE_WRITE.  Use
476    BFD_JUMP_TABLE_WRITE (_bfd_generic).  */
477 
478 #define _bfd_generic_set_arch_mach bfd_default_set_arch_mach
479 extern bool _bfd_generic_set_section_contents
480   (bfd *, asection *, const void *, file_ptr, bfd_size_type) ATTRIBUTE_HIDDEN;
481 
482 /* Routines to use for BFD_JUMP_TABLE_LINK for targets which do not
483    support linking.  Use BFD_JUMP_TABLE_LINK (_bfd_nolink).  */
484 
485 extern int _bfd_nolink_sizeof_headers
486   (bfd *, struct bfd_link_info *) ATTRIBUTE_HIDDEN;
487 extern bfd_byte *_bfd_nolink_bfd_get_relocated_section_contents
488   (bfd *, struct bfd_link_info *, struct bfd_link_order *,
489    bfd_byte *, bool, asymbol **) ATTRIBUTE_HIDDEN;
490 extern bool _bfd_nolink_bfd_relax_section
491   (bfd *, asection *, struct bfd_link_info *, bool *) ATTRIBUTE_HIDDEN;
492 #define _bfd_nolink_bfd_gc_sections _bfd_bool_bfd_link_false_error
493 extern bool _bfd_nolink_bfd_lookup_section_flags
494   (struct bfd_link_info *, struct flag_info *, asection *) ATTRIBUTE_HIDDEN;
495 #define _bfd_nolink_bfd_merge_sections _bfd_bool_bfd_link_false_error
496 extern bool _bfd_nolink_bfd_is_group_section
497   (bfd *, const asection *) ATTRIBUTE_HIDDEN;
498 extern const char *_bfd_nolink_bfd_group_name
499   (bfd *, const asection *) ATTRIBUTE_HIDDEN;
500 extern bool _bfd_nolink_bfd_discard_group
501   (bfd *, asection *) ATTRIBUTE_HIDDEN;
502 extern struct bfd_link_hash_table *_bfd_nolink_bfd_link_hash_table_create
503   (bfd *) ATTRIBUTE_HIDDEN;
504 #define _bfd_nolink_bfd_link_add_symbols _bfd_bool_bfd_link_false_error
505 extern void _bfd_nolink_bfd_link_just_syms
506   (asection *, struct bfd_link_info *) ATTRIBUTE_HIDDEN;
507 extern void _bfd_nolink_bfd_copy_link_hash_symbol_type
508   (bfd *, struct bfd_link_hash_entry *, struct bfd_link_hash_entry *)
509   ATTRIBUTE_HIDDEN;
510 #define _bfd_nolink_bfd_final_link _bfd_bool_bfd_link_false_error
511 extern bool _bfd_nolink_bfd_link_split_section
512   (bfd *, struct bfd_section *) ATTRIBUTE_HIDDEN;
513 extern bool _bfd_nolink_section_already_linked
514   (bfd *, asection *, struct bfd_link_info *) ATTRIBUTE_HIDDEN;
515 extern bool _bfd_nolink_bfd_define_common_symbol
516   (bfd *, struct bfd_link_info *, struct bfd_link_hash_entry *)
517   ATTRIBUTE_HIDDEN;
518 #define _bfd_nolink_bfd_link_hide_symbol \
519   _bfd_generic_link_hide_symbol
520 extern struct bfd_link_hash_entry *_bfd_nolink_bfd_define_start_stop
521   (struct bfd_link_info *, const char *, asection *) ATTRIBUTE_HIDDEN;
522 #define _bfd_nolink_bfd_link_check_relocs \
523   _bfd_generic_link_check_relocs
524 
525 /* Routines to use for BFD_JUMP_TABLE_DYNAMIC for targets which do not
526    have dynamic symbols or relocs.  Use BFD_JUMP_TABLE_DYNAMIC
527    (_bfd_nodynamic).  */
528 
529 #define _bfd_nodynamic_get_dynamic_symtab_upper_bound _bfd_long_bfd_n1_error
530 #define _bfd_nodynamic_canonicalize_dynamic_symtab \
531   _bfd_nosymbols_canonicalize_symtab
532 extern long _bfd_nodynamic_get_synthetic_symtab
533   (bfd *, long, asymbol **, long, asymbol **, asymbol **) ATTRIBUTE_HIDDEN;
534 #define _bfd_nodynamic_get_dynamic_reloc_upper_bound _bfd_long_bfd_n1_error
535 extern long _bfd_nodynamic_canonicalize_dynamic_reloc
536   (bfd *, arelent **, asymbol **) ATTRIBUTE_HIDDEN;
537 
538 /* Generic routine to determine of the given symbol is a local
539    label.  */
540 extern bool bfd_generic_is_local_label_name
541   (bfd *, const char *) ATTRIBUTE_HIDDEN;
542 
543 /* Generic minisymbol routines.  */
544 extern long _bfd_generic_read_minisymbols
545   (bfd *, bool, void **, unsigned int *) ATTRIBUTE_HIDDEN;
546 extern asymbol *_bfd_generic_minisymbol_to_symbol
547   (bfd *, bool, const void *, asymbol *) ATTRIBUTE_HIDDEN;
548 
549 /* Find the nearest line using .stab/.stabstr sections.  */
550 extern bool _bfd_stab_section_find_nearest_line
551   (bfd *, asymbol **, asection *, bfd_vma, bool *,
552    const char **, const char **, unsigned int *, void **) ATTRIBUTE_HIDDEN;
553 
554 /* Find the nearest line using DWARF 1 debugging information.  */
555 extern bool _bfd_dwarf1_find_nearest_line
556   (bfd *, asymbol **, asection *, bfd_vma,
557    const char **, const char **, unsigned int *) ATTRIBUTE_HIDDEN;
558 
559 /* Clean up the data used to handle DWARF 1 debugging information. */
560 extern void _bfd_dwarf1_cleanup_debug_info
561   (bfd *, void **) ATTRIBUTE_HIDDEN;
562 
563 struct dwarf_debug_section
564 {
565   const char * uncompressed_name;
566   const char * compressed_name;
567 };
568 
569 /* Map of uncompressed DWARF debug section name to compressed one.  It
570    is terminated by NULL uncompressed_name.  */
571 
572 extern const struct dwarf_debug_section dwarf_debug_sections[] ATTRIBUTE_HIDDEN;
573 
574 /* Find the nearest line using DWARF 2 debugging information.  */
575 extern int _bfd_dwarf2_find_nearest_line
576   (bfd *, asymbol **, asymbol *, asection *, bfd_vma,
577    const char **, const char **, unsigned int *, unsigned int *,
578    const struct dwarf_debug_section *, void **) ATTRIBUTE_HIDDEN;
579 
580 /* Find the nearest line using DWARF 2 debugging information, with
581    the option of specifying a .gnu_debugaltlink file.  */
582 extern int _bfd_dwarf2_find_nearest_line_with_alt
583   (bfd *, const char *, asymbol **, asymbol *, asection *, bfd_vma,
584    const char **, const char **, unsigned int *, unsigned int *,
585    const struct dwarf_debug_section *, void **) ATTRIBUTE_HIDDEN;
586 
587 /* Find the bias between DWARF addresses and real addresses.  */
588 extern bfd_signed_vma _bfd_dwarf2_find_symbol_bias
589   (asymbol **, void **) ATTRIBUTE_HIDDEN;
590 
591 /* Find inliner info after calling bfd_find_nearest_line. */
592 extern bool _bfd_dwarf2_find_inliner_info
593   (bfd *, const char **, const char **, unsigned int *, void **)
594   ATTRIBUTE_HIDDEN;
595 
596 /* Read DWARF 2 debugging information. */
597 extern bool _bfd_dwarf2_slurp_debug_info
598   (bfd *, bfd *, const struct dwarf_debug_section *, asymbol **, void **,
599    bool) ATTRIBUTE_HIDDEN;
600 
601 /* Clean up the data used to handle DWARF 2 debugging information. */
602 extern void _bfd_dwarf2_cleanup_debug_info
603   (bfd *, void **) ATTRIBUTE_HIDDEN;
604 
605 extern void _bfd_stab_cleanup
606   (bfd *, void **) ATTRIBUTE_HIDDEN;
607 
608 /* Create a new section entry.  */
609 extern struct bfd_hash_entry *bfd_section_hash_newfunc
610   (struct bfd_hash_entry *, struct bfd_hash_table *, const char *)
611   ATTRIBUTE_HIDDEN;
612 
613 /* A routine to create entries for a bfd_link_hash_table.  */
614 extern struct bfd_hash_entry *_bfd_link_hash_newfunc
615   (struct bfd_hash_entry *entry, struct bfd_hash_table *table,
616    const char *string) ATTRIBUTE_HIDDEN;
617 
618 /* Initialize a bfd_link_hash_table.  */
619 extern bool _bfd_link_hash_table_init
620   (struct bfd_link_hash_table *, bfd *,
621    struct bfd_hash_entry *(*) (struct bfd_hash_entry *,
622 			       struct bfd_hash_table *,
623 			       const char *),
624    unsigned int) ATTRIBUTE_HIDDEN;
625 
626 /* Generic link hash table creation routine.  */
627 extern struct bfd_link_hash_table *_bfd_generic_link_hash_table_create
628   (bfd *) ATTRIBUTE_HIDDEN;
629 
630 /* Generic link hash table destruction routine.  */
631 extern void _bfd_generic_link_hash_table_free
632   (bfd *) ATTRIBUTE_HIDDEN;
633 
634 /* Generic add symbol routine.  */
635 extern bool _bfd_generic_link_add_symbols
636   (bfd *, struct bfd_link_info *) ATTRIBUTE_HIDDEN;
637 
638 /* Generic archive add symbol routine.  */
639 extern bool _bfd_generic_link_add_archive_symbols
640   (bfd *, struct bfd_link_info *,
641    bool (*) (bfd *, struct bfd_link_info *,
642 		    struct bfd_link_hash_entry *, const char *,
643 		    bool *)) ATTRIBUTE_HIDDEN;
644 
645 /* Forward declaration to avoid prototype errors.  */
646 typedef struct bfd_link_hash_entry _bfd_link_hash_entry;
647 
648 /* Generic routine to add a single symbol.  */
649 extern bool _bfd_generic_link_add_one_symbol
650   (struct bfd_link_info *, bfd *, const char *name, flagword,
651    asection *, bfd_vma, const char *, bool copy,
652    bool constructor, struct bfd_link_hash_entry **) ATTRIBUTE_HIDDEN;
653 
654 /* Generic routine to mark section as supplying symbols only.  */
655 extern void _bfd_generic_link_just_syms
656   (asection *, struct bfd_link_info *) ATTRIBUTE_HIDDEN;
657 
658 /* Generic routine that does nothing.  */
659 extern void _bfd_generic_copy_link_hash_symbol_type
660   (bfd *, struct bfd_link_hash_entry *, struct bfd_link_hash_entry *)
661   ATTRIBUTE_HIDDEN;
662 
663 /* Generic link routine.  */
664 extern bool _bfd_generic_final_link
665   (bfd *, struct bfd_link_info *) ATTRIBUTE_HIDDEN;
666 
667 extern bool _bfd_generic_link_split_section
668   (bfd *, struct bfd_section *) ATTRIBUTE_HIDDEN;
669 
670 extern bool _bfd_generic_section_already_linked
671   (bfd *, asection *, struct bfd_link_info *) ATTRIBUTE_HIDDEN;
672 
673 /* Generic reloc_link_order processing routine.  */
674 extern bool _bfd_generic_reloc_link_order
675   (bfd *, struct bfd_link_info *, asection *, struct bfd_link_order *)
676   ATTRIBUTE_HIDDEN;
677 
678 /* Default link order processing routine.  */
679 extern bool _bfd_default_link_order
680   (bfd *, struct bfd_link_info *, asection *, struct bfd_link_order *)
681   ATTRIBUTE_HIDDEN;
682 
683 /* Count the number of reloc entries in a link order list.  */
684 extern unsigned int _bfd_count_link_order_relocs
685   (struct bfd_link_order *) ATTRIBUTE_HIDDEN;
686 
687 /* Final link relocation routine.  */
688 extern bfd_reloc_status_type _bfd_final_link_relocate
689   (reloc_howto_type *, bfd *, asection *, bfd_byte *,
690    bfd_vma, bfd_vma, bfd_vma) ATTRIBUTE_HIDDEN;
691 
692 /* Relocate a particular location by a howto and a value.  */
693 extern bfd_reloc_status_type _bfd_relocate_contents
694   (reloc_howto_type *, bfd *, bfd_vma, bfd_byte *) ATTRIBUTE_HIDDEN;
695 
696 /* Clear a given location using a given howto.  */
697 extern bfd_reloc_status_type _bfd_clear_contents
698   (reloc_howto_type *, bfd *, asection *, bfd_byte *, bfd_vma) ATTRIBUTE_HIDDEN;
699 
700 /* Register a SEC_MERGE section as a candidate for merging.  */
701 
702 extern bool _bfd_add_merge_section
703   (bfd *, void **, asection *, void **) ATTRIBUTE_HIDDEN;
704 
705 /* Attempt to merge SEC_MERGE sections.  */
706 
707 extern bool _bfd_merge_sections
708   (bfd *, struct bfd_link_info *, void *, void (*) (bfd *, asection *))
709   ATTRIBUTE_HIDDEN;
710 
711 /* Write out a merged section.  */
712 
713 extern bool _bfd_write_merged_section
714   (bfd *, asection *, void *) ATTRIBUTE_HIDDEN;
715 
716 /* Find an offset within a modified SEC_MERGE section.  */
717 
718 extern bfd_vma _bfd_merged_section_offset
719   (bfd *, asection **, void *, bfd_vma) ATTRIBUTE_HIDDEN;
720 
721 /* Tidy up when done.  */
722 
723 extern void _bfd_merge_sections_free (void *) ATTRIBUTE_HIDDEN;
724 
725 /* Macros to tell if bfds are read or write enabled.
726 
727    Note that bfds open for read may be scribbled into if the fd passed
728    to bfd_fdopenr is actually open both for read and write
729    simultaneously.  However an output bfd will never be open for
730    read.  Therefore sometimes you want to check bfd_read_p or
731    !bfd_read_p, and only sometimes bfd_write_p.
732 */
733 
734 #define	bfd_read_p(abfd) \
735   ((abfd)->direction == read_direction || (abfd)->direction == both_direction)
736 #define	bfd_write_p(abfd) \
737   ((abfd)->direction == write_direction || (abfd)->direction == both_direction)
738 
739 extern void bfd_assert
740   (const char*,int) ATTRIBUTE_HIDDEN;
741 
742 #define BFD_ASSERT(x) \
743   do { if (!(x)) bfd_assert(__FILE__,__LINE__); } while (0)
744 
745 #define BFD_FAIL() \
746   do { bfd_assert(__FILE__,__LINE__); } while (0)
747 
748 extern void _bfd_abort
749   (const char *, int, const char *) ATTRIBUTE_NORETURN ATTRIBUTE_HIDDEN;
750 
751 /* if gcc >= 2.6, we can give a function name, too */
752 #if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 6)
753 #define __PRETTY_FUNCTION__  ((char *) NULL)
754 #endif
755 
756 #undef abort
757 #define abort() _bfd_abort (__FILE__, __LINE__, __PRETTY_FUNCTION__)
758 
759 /* Manipulate a system FILE but using BFD's "file_ptr", rather than
760    the system "off_t" or "off64_t", as the offset.  */
761 extern file_ptr _bfd_real_ftell
762   (FILE *) ATTRIBUTE_HIDDEN;
763 extern int _bfd_real_fseek
764   (FILE *, file_ptr, int) ATTRIBUTE_HIDDEN;
765 extern FILE *_bfd_real_fopen
766   (const char *, const char *) ATTRIBUTE_HIDDEN;
767 
768 /* List of supported target vectors, and the default vector (if
769    bfd_default_vector[0] is NULL, there is no default).  */
770 extern const bfd_target *const *const bfd_target_vector ATTRIBUTE_HIDDEN;
771 extern const bfd_target *bfd_default_vector[] ATTRIBUTE_HIDDEN;
772 
773 /* List of associated target vectors.  */
774 extern const bfd_target *const *const bfd_associated_vector ATTRIBUTE_HIDDEN;
775 
776 /* Functions shared by the ECOFF and MIPS ELF backends, which have no
777    other common header files.  */
778 
779 struct ecoff_debug_info;
780 struct ecoff_debug_swap;
781 struct ecoff_extr;
782 struct ecoff_find_line;
783 
784 extern void _bfd_ecoff_free_ecoff_debug_info
785   (struct ecoff_debug_info *debug);
786 extern bool _bfd_ecoff_locate_line
787   (bfd *, asection *, bfd_vma, struct ecoff_debug_info * const,
788    const struct ecoff_debug_swap * const, struct ecoff_find_line *,
789    const char **, const char **, unsigned int *) ATTRIBUTE_HIDDEN;
790 extern bool _bfd_ecoff_get_accumulated_pdr
791   (void *, bfd_byte *) ATTRIBUTE_HIDDEN;
792 extern bool _bfd_ecoff_get_accumulated_sym
793   (void *, bfd_byte *) ATTRIBUTE_HIDDEN;
794 extern bool _bfd_ecoff_get_accumulated_ss
795   (void *, bfd_byte *) ATTRIBUTE_HIDDEN;
796 
797 extern bfd_vma _bfd_get_gp_value
798   (bfd *) ATTRIBUTE_HIDDEN;
799 extern void _bfd_set_gp_value
800   (bfd *, bfd_vma) ATTRIBUTE_HIDDEN;
801 
802 /* Function shared by the COFF and ELF SH backends, which have no
803    other common header files.  */
804 
805 #ifndef _bfd_sh_align_load_span
806 extern bool _bfd_sh_align_load_span
807   (bfd *, asection *, bfd_byte *,
808    bool (*) (bfd *, asection *, void *, bfd_byte *, bfd_vma),
809    void *, bfd_vma **, bfd_vma *, bfd_vma, bfd_vma, bool *) ATTRIBUTE_HIDDEN;
810 #endif
811 
812 /* This is the shape of the elements inside the already_linked hash
813    table. It maps a name onto a list of already_linked elements with
814    the same name.  */
815 
816 struct bfd_section_already_linked_hash_entry
817 {
818   struct bfd_hash_entry root;
819   struct bfd_section_already_linked *entry;
820 };
821 
822 struct bfd_section_already_linked
823 {
824   struct bfd_section_already_linked *next;
825   asection *sec;
826 };
827 
828 extern struct bfd_section_already_linked_hash_entry *
829   bfd_section_already_linked_table_lookup (const char *) ATTRIBUTE_HIDDEN;
830 extern bool bfd_section_already_linked_table_insert
831   (struct bfd_section_already_linked_hash_entry *, asection *)
832   ATTRIBUTE_HIDDEN;
833 extern void bfd_section_already_linked_table_traverse
834   (bool (*) (struct bfd_section_already_linked_hash_entry *,
835 		    void *), void *) ATTRIBUTE_HIDDEN;
836 
837 extern bfd_vma _bfd_read_unsigned_leb128
838   (bfd *, bfd_byte *, unsigned int *) ATTRIBUTE_HIDDEN;
839 extern bfd_signed_vma _bfd_read_signed_leb128
840   (bfd *, bfd_byte *, unsigned int *) ATTRIBUTE_HIDDEN;
841 extern bfd_vma _bfd_safe_read_leb128
842   (bfd *, bfd_byte **, bool, const bfd_byte * const) ATTRIBUTE_HIDDEN;
843 extern bfd_byte * _bfd_write_unsigned_leb128
844   (bfd_byte *, bfd_byte *, bfd_vma) ATTRIBUTE_HIDDEN;
845 
846 extern struct bfd_link_info *_bfd_get_link_info (bfd *)
847   ATTRIBUTE_HIDDEN;
848 
849 #ifdef HAVE_MMAP
850 extern uintptr_t _bfd_pagesize ATTRIBUTE_HIDDEN;
851 extern uintptr_t _bfd_pagesize_m1 ATTRIBUTE_HIDDEN;
852 extern uintptr_t _bfd_minimum_mmap_size ATTRIBUTE_HIDDEN;
853 #endif
854 
855 #if GCC_VERSION >= 7000
856 #define _bfd_mul_overflow(a, b, res) __builtin_mul_overflow (a, b, res)
857 #else
858 /* Assumes unsigned values.  Careful!  Args evaluated multiple times.  */
859 #define _bfd_mul_overflow(a, b, res) \
860   ((*res) = (a), (*res) *= (b), (b) != 0 && (*res) / (b) != (a))
861 #endif
862 
863 #ifdef __GNUC__
864 #define _bfd_constant_p(v) __builtin_constant_p (v)
865 #else
866 #define _bfd_constant_p(v) 0
867 #endif
868 
869 static inline void *
870 _bfd_alloc_and_read (bfd *abfd, bfd_size_type asize, bfd_size_type rsize)
871 {
872   void *mem;
873   if (!_bfd_constant_p (rsize))
874     {
875       ufile_ptr filesize = bfd_get_file_size (abfd);
876       if (filesize != 0 && rsize > filesize)
877 	{
878 	  bfd_set_error (bfd_error_file_truncated);
879 	  return NULL;
880 	}
881     }
882   mem = bfd_alloc (abfd, asize);
883   if (mem != NULL)
884     {
885       if (bfd_read (mem, rsize, abfd) == rsize)
886 	return mem;
887       bfd_release (abfd, mem);
888     }
889   return NULL;
890 }
891 
892 #ifdef USE_MMAP
893 extern void *_bfd_mmap_readonly_persistent
894   (bfd *, size_t) ATTRIBUTE_HIDDEN;
895 extern void *_bfd_mmap_readonly_temporary
896   (bfd *, size_t, void **, size_t *) ATTRIBUTE_HIDDEN;
897 extern void _bfd_munmap_readonly_temporary
898   (void *, size_t) ATTRIBUTE_HIDDEN;
899 #else
900 #define _bfd_mmap_readonly_persistent(abfd, rsize) \
901   _bfd_alloc_and_read (abfd, rsize, rsize)
902 #define _bfd_munmap_readonly_temporary(ptr, rsize) free (ptr)
903 #endif
904 
905 extern bool _bfd_mmap_read_temporary
906   (void **, size_t *, void **, bfd *, bool) ATTRIBUTE_HIDDEN;
907 
908 static inline void *
909 _bfd_malloc_and_read (bfd *abfd, bfd_size_type asize, bfd_size_type rsize)
910 {
911   void *mem;
912   if (!_bfd_constant_p (rsize))
913     {
914       ufile_ptr filesize = bfd_get_file_size (abfd);
915       if (filesize != 0 && rsize > filesize)
916 	{
917 	  bfd_set_error (bfd_error_file_truncated);
918 	  return NULL;
919 	}
920     }
921   mem = bfd_malloc (asize);
922   if (mem != NULL)
923     {
924       if (bfd_read (mem, rsize, abfd) == rsize)
925 	return mem;
926       free (mem);
927     }
928   return NULL;
929 }
930 
931 #ifndef USE_MMAP
932 static inline void *
933 _bfd_mmap_readonly_temporary (bfd *abfd, size_t rsize, void **map_addr,
934 			      size_t *map_size)
935 {
936   void *mem = _bfd_malloc_and_read (abfd, rsize, rsize);
937   *map_addr = mem;
938   *map_size = rsize;
939   return mem;
940 }
941 #endif
942