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