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