Fix: Null pointer dereference in elf32-i386.c
[binutils-gdb.git] / bfd / libbfd-in.h
blob153587c974acea2e80ed9c261e4f7fe4fd769ed1
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 /* 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))
46 /* If BFD_IN_MEMORY is set for a BFD, then the iostream fields points
47 to an instance of this structure. */
49 struct bfd_in_memory
51 /* Size of buffer. */
52 bfd_size_type size;
53 /* Buffer holding contents of BFD. */
54 bfd_byte *buffer;
57 struct section_hash_entry
59 struct bfd_hash_entry root;
60 asection section;
63 /* Unique section id. */
64 extern unsigned int _bfd_section_id ATTRIBUTE_HIDDEN;
66 /* tdata for an archive. For an input archive, cache
67 needs to be free()'d. For an output archive, symdefs do. */
69 struct artdata
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. */
90 #define bfd_ardata(bfd) ((bfd)->tdata.aout_ar_data)
92 /* Goes in bfd's arelt_data slot */
93 struct areltdata
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;
104 #define arelt_size(bfd) (((struct areltdata *)((bfd)->arelt_data))->parsed_size)
106 extern void *bfd_malloc
107 (bfd_size_type) ATTRIBUTE_HIDDEN;
109 static inline char *
110 bfd_strdup (const char *str)
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;
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
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;
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;
209 extern bfd_cleanup _bfd_dummy_target
210 (bfd *) ATTRIBUTE_HIDDEN;
211 #define _bfd_no_cleanup _bfd_void_bfd
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;
220 extern bool _bfd_bsd_write_armap
221 (bfd *, unsigned int, struct orl *, unsigned int, int) ATTRIBUTE_HIDDEN;
223 extern bool _bfd_coff_write_armap
224 (bfd *, unsigned int, struct orl *, unsigned int, int) ATTRIBUTE_HIDDEN;
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;
233 extern void *_bfd_generic_read_ar_hdr_mag
234 (bfd *, const char *) ATTRIBUTE_HIDDEN;
236 extern bool _bfd_generic_write_ar_hdr
237 (bfd *, bfd *) ATTRIBUTE_HIDDEN;
239 extern bool _bfd_bsd44_write_ar_hdr
240 (bfd *, bfd *) ATTRIBUTE_HIDDEN;
242 extern bfd * bfd_generic_openr_next_archived_file
243 (bfd *, bfd *) ATTRIBUTE_HIDDEN;
245 extern int bfd_generic_stat_arch_elt
246 (bfd *, struct stat *) ATTRIBUTE_HIDDEN;
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))
253 /* Generic routines to use for BFD_JUMP_TABLE_GENERIC. Use
254 BFD_JUMP_TABLE_GENERIC (_bfd_generic). */
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 extern bool _bfd_generic_get_section_contents_in_window
266 (bfd *, asection *, bfd_window *, file_ptr, bfd_size_type) ATTRIBUTE_HIDDEN;
268 /* Generic routines to use for BFD_JUMP_TABLE_COPY. Use
269 BFD_JUMP_TABLE_COPY (_bfd_generic). */
271 #define _bfd_generic_bfd_copy_private_bfd_data _bfd_bool_bfd_bfd_true
272 #define _bfd_generic_bfd_merge_private_bfd_data \
273 _bfd_bool_bfd_link_true
274 #define _bfd_generic_bfd_set_private_flags _bfd_bool_bfd_uint_true
275 #define _bfd_generic_bfd_copy_private_section_data \
276 _bfd_bool_bfd_asection_bfd_asection_true
277 #define _bfd_generic_bfd_copy_private_symbol_data \
278 _bfd_bool_bfd_asymbol_bfd_asymbol_true
279 #define _bfd_generic_bfd_copy_private_header_data _bfd_bool_bfd_bfd_true
280 #define _bfd_generic_bfd_print_private_bfd_data _bfd_bool_bfd_ptr_true
282 extern bool _bfd_generic_init_private_section_data
283 (bfd *, asection *, bfd *, asection *, struct bfd_link_info *)
284 ATTRIBUTE_HIDDEN;
286 /* Routines to use for BFD_JUMP_TABLE_CORE when there is no core file
287 support. Use BFD_JUMP_TABLE_CORE (_bfd_nocore). */
289 extern char *_bfd_nocore_core_file_failing_command
290 (bfd *) ATTRIBUTE_HIDDEN;
291 extern int _bfd_nocore_core_file_failing_signal
292 (bfd *) ATTRIBUTE_HIDDEN;
293 extern bool _bfd_nocore_core_file_matches_executable_p
294 (bfd *, bfd *) ATTRIBUTE_HIDDEN;
295 extern int _bfd_nocore_core_file_pid
296 (bfd *) ATTRIBUTE_HIDDEN;
298 /* Routines to use for BFD_JUMP_TABLE_ARCHIVE when there is no archive
299 file support. Use BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive). */
301 #define _bfd_noarchive_slurp_armap _bfd_bool_bfd_false_error
302 #define _bfd_noarchive_slurp_extended_name_table _bfd_bool_bfd_false_error
303 extern bool _bfd_noarchive_construct_extended_name_table
304 (bfd *, char **, bfd_size_type *, const char **) ATTRIBUTE_HIDDEN;
305 extern void _bfd_noarchive_truncate_arname
306 (bfd *, const char *, char *) ATTRIBUTE_HIDDEN;
307 extern bool _bfd_noarchive_write_armap
308 (bfd *, unsigned int, struct orl *, unsigned int, int) ATTRIBUTE_HIDDEN;
309 #define _bfd_noarchive_read_ar_hdr _bfd_ptr_bfd_null_error
310 extern bool _bfd_noarchive_write_ar_hdr
311 (bfd *, bfd *) ATTRIBUTE_HIDDEN;
312 extern bfd *
313 _bfd_noarchive_openr_next_archived_file
314 (bfd *, bfd *) ATTRIBUTE_HIDDEN;
315 extern bfd * _bfd_noarchive_get_elt_at_index
316 (bfd *, symindex) ATTRIBUTE_HIDDEN;
317 #define _bfd_noarchive_generic_stat_arch_elt bfd_generic_stat_arch_elt
318 #define _bfd_noarchive_update_armap_timestamp _bfd_bool_bfd_false_error
320 /* Routines to use for BFD_JUMP_TABLE_ARCHIVE to get BSD style
321 archives. Use BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_bsd). */
323 #define _bfd_archive_bsd_slurp_armap bfd_slurp_bsd_armap
324 #define _bfd_archive_bsd_slurp_extended_name_table \
325 _bfd_slurp_extended_name_table
326 extern bool _bfd_archive_bsd_construct_extended_name_table
327 (bfd *, char **, bfd_size_type *, const char **) ATTRIBUTE_HIDDEN;
328 #define _bfd_archive_bsd_truncate_arname bfd_bsd_truncate_arname
329 #define _bfd_archive_bsd_write_armap _bfd_bsd_write_armap
330 #define _bfd_archive_bsd_read_ar_hdr _bfd_generic_read_ar_hdr
331 #define _bfd_archive_bsd_write_ar_hdr _bfd_generic_write_ar_hdr
332 #define _bfd_archive_bsd_openr_next_archived_file \
333 bfd_generic_openr_next_archived_file
334 #define _bfd_archive_bsd_get_elt_at_index _bfd_generic_get_elt_at_index
335 #define _bfd_archive_bsd_generic_stat_arch_elt \
336 bfd_generic_stat_arch_elt
337 extern bool _bfd_archive_bsd_update_armap_timestamp
338 (bfd *) ATTRIBUTE_HIDDEN;
340 /* Routines to use for BFD_JUMP_TABLE_ARCHIVE to get COFF style
341 archives. Use BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff). */
343 #define _bfd_archive_coff_slurp_armap bfd_slurp_coff_armap
344 #define _bfd_archive_coff_slurp_extended_name_table \
345 _bfd_slurp_extended_name_table
346 extern bool _bfd_archive_coff_construct_extended_name_table
347 (bfd *, char **, bfd_size_type *, const char **) ATTRIBUTE_HIDDEN;
348 #define _bfd_archive_coff_truncate_arname bfd_dont_truncate_arname
349 #define _bfd_archive_coff_write_armap _bfd_coff_write_armap
350 #define _bfd_archive_coff_read_ar_hdr _bfd_generic_read_ar_hdr
351 #define _bfd_archive_coff_write_ar_hdr _bfd_generic_write_ar_hdr
352 #define _bfd_archive_coff_openr_next_archived_file \
353 bfd_generic_openr_next_archived_file
354 #define _bfd_archive_coff_get_elt_at_index _bfd_generic_get_elt_at_index
355 #define _bfd_archive_coff_generic_stat_arch_elt \
356 bfd_generic_stat_arch_elt
357 #define _bfd_archive_coff_update_armap_timestamp _bfd_bool_bfd_true
359 /* Routines to use for BFD_JUMP_TABLE_ARCHIVE to get BSD4.4 style
360 archives. Use BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_bsd44). */
362 #define _bfd_archive_bsd44_slurp_armap bfd_slurp_bsd_armap
363 #define _bfd_archive_bsd44_slurp_extended_name_table \
364 _bfd_slurp_extended_name_table
365 extern bool _bfd_archive_bsd44_construct_extended_name_table
366 (bfd *, char **, bfd_size_type *, const char **) ATTRIBUTE_HIDDEN;
367 #define _bfd_archive_bsd44_truncate_arname bfd_bsd_truncate_arname
368 #define _bfd_archive_bsd44_write_armap _bfd_bsd_write_armap
369 #define _bfd_archive_bsd44_read_ar_hdr _bfd_generic_read_ar_hdr
370 #define _bfd_archive_bsd44_write_ar_hdr _bfd_bsd44_write_ar_hdr
371 #define _bfd_archive_bsd44_openr_next_archived_file \
372 bfd_generic_openr_next_archived_file
373 #define _bfd_archive_bsd44_get_elt_at_index _bfd_generic_get_elt_at_index
374 #define _bfd_archive_bsd44_generic_stat_arch_elt \
375 bfd_generic_stat_arch_elt
376 #define _bfd_archive_bsd44_update_armap_timestamp \
377 _bfd_archive_bsd_update_armap_timestamp
379 /* Routines to use for BFD_JUMP_TABLE_ARCHIVE to get VMS style
380 archives. Use BFD_JUMP_TABLE_ARCHIVE (_bfd_vms_lib). Some of them
381 are irrelevant. */
383 extern bool _bfd_vms_lib_write_archive_contents
384 (bfd *) ATTRIBUTE_HIDDEN;
385 #define _bfd_vms_lib_slurp_armap _bfd_noarchive_slurp_armap
386 #define _bfd_vms_lib_slurp_extended_name_table \
387 _bfd_noarchive_slurp_extended_name_table
388 #define _bfd_vms_lib_construct_extended_name_table \
389 _bfd_noarchive_construct_extended_name_table
390 #define _bfd_vms_lib_truncate_arname _bfd_noarchive_truncate_arname
391 #define _bfd_vms_lib_write_armap _bfd_noarchive_write_armap
392 #define _bfd_vms_lib_read_ar_hdr _bfd_noarchive_read_ar_hdr
393 #define _bfd_vms_lib_write_ar_hdr _bfd_noarchive_write_ar_hdr
394 extern bfd *_bfd_vms_lib_openr_next_archived_file
395 (bfd *, bfd *) ATTRIBUTE_HIDDEN;
396 extern bfd *_bfd_vms_lib_get_elt_at_index
397 (bfd *, symindex) ATTRIBUTE_HIDDEN;
398 extern int _bfd_vms_lib_generic_stat_arch_elt
399 (bfd *, struct stat *) ATTRIBUTE_HIDDEN;
400 #define _bfd_vms_lib_update_armap_timestamp _bfd_bool_bfd_true
402 /* Extra routines for VMS style archives. */
404 extern symindex _bfd_vms_lib_find_symbol
405 (bfd *, const char *) ATTRIBUTE_HIDDEN;
406 extern bfd *_bfd_vms_lib_get_imagelib_file
407 (bfd *) ATTRIBUTE_HIDDEN;
408 extern bfd_cleanup _bfd_vms_lib_alpha_archive_p
409 (bfd *) ATTRIBUTE_HIDDEN;
410 extern bfd_cleanup _bfd_vms_lib_ia64_archive_p
411 (bfd *) ATTRIBUTE_HIDDEN;
412 extern bool _bfd_vms_lib_alpha_mkarchive
413 (bfd *) ATTRIBUTE_HIDDEN;
414 extern bool _bfd_vms_lib_ia64_mkarchive
415 (bfd *) ATTRIBUTE_HIDDEN;
417 /* Routines to use for BFD_JUMP_TABLE_SYMBOLS where there is no symbol
418 support. Use BFD_JUMP_TABLE_SYMBOLS (_bfd_nosymbols). */
420 #define _bfd_nosymbols_get_symtab_upper_bound _bfd_long_bfd_n1_error
421 extern long _bfd_nosymbols_canonicalize_symtab
422 (bfd *, asymbol **) ATTRIBUTE_HIDDEN;
423 #define _bfd_nosymbols_make_empty_symbol _bfd_generic_make_empty_symbol
424 extern void _bfd_nosymbols_print_symbol
425 (bfd *, void *, asymbol *, bfd_print_symbol_type) ATTRIBUTE_HIDDEN;
426 extern void _bfd_nosymbols_get_symbol_info
427 (bfd *, asymbol *, symbol_info *) ATTRIBUTE_HIDDEN;
428 extern const char * _bfd_nosymbols_get_symbol_version_string
429 (bfd *, asymbol *, bool, bool *) ATTRIBUTE_HIDDEN;
430 extern bool _bfd_nosymbols_bfd_is_local_label_name
431 (bfd *, const char *) ATTRIBUTE_HIDDEN;
432 #define _bfd_nosymbols_bfd_is_target_special_symbol _bfd_bool_bfd_asymbol_false
433 extern alent *_bfd_nosymbols_get_lineno
434 (bfd *, asymbol *) ATTRIBUTE_HIDDEN;
435 extern bool _bfd_nosymbols_find_nearest_line
436 (bfd *, asymbol **, asection *, bfd_vma,
437 const char **, const char **, unsigned int *, unsigned int *)
438 ATTRIBUTE_HIDDEN;
439 extern bool _bfd_nosymbols_find_nearest_line_with_alt
440 (bfd *, const char *, asymbol **, asection *, bfd_vma,
441 const char **, const char **, unsigned int *, unsigned int *)
442 ATTRIBUTE_HIDDEN;
443 extern bool _bfd_nosymbols_find_line
444 (bfd *, asymbol **, asymbol *, const char **, unsigned int *)
445 ATTRIBUTE_HIDDEN;
446 extern bool _bfd_nosymbols_find_inliner_info
447 (bfd *, const char **, const char **, unsigned int *) ATTRIBUTE_HIDDEN;
448 extern asymbol *_bfd_nosymbols_bfd_make_debug_symbol
449 (bfd *) ATTRIBUTE_HIDDEN;
450 extern long _bfd_nosymbols_read_minisymbols
451 (bfd *, bool, void **, unsigned int *) ATTRIBUTE_HIDDEN;
452 extern asymbol *_bfd_nosymbols_minisymbol_to_symbol
453 (bfd *, bool, const void *, asymbol *) ATTRIBUTE_HIDDEN;
455 /* Routines to use for BFD_JUMP_TABLE_RELOCS when there is no reloc
456 support. Use BFD_JUMP_TABLE_RELOCS (_bfd_norelocs). */
458 extern long _bfd_norelocs_get_reloc_upper_bound
459 (bfd *, asection *) ATTRIBUTE_HIDDEN;
460 extern long _bfd_norelocs_canonicalize_reloc
461 (bfd *, asection *, arelent **, asymbol **) ATTRIBUTE_HIDDEN;
462 extern void _bfd_norelocs_set_reloc
463 (bfd *, asection *, arelent **, unsigned int) ATTRIBUTE_HIDDEN;
464 extern reloc_howto_type *_bfd_norelocs_bfd_reloc_type_lookup
465 (bfd *, bfd_reloc_code_real_type) ATTRIBUTE_HIDDEN;
466 extern reloc_howto_type *_bfd_norelocs_bfd_reloc_name_lookup
467 (bfd *, const char *) ATTRIBUTE_HIDDEN;
469 /* Routines to use for BFD_JUMP_TABLE_WRITE for targets which may not
470 be written. Use BFD_JUMP_TABLE_WRITE (_bfd_nowrite). */
472 extern bool _bfd_nowrite_set_arch_mach
473 (bfd *, enum bfd_architecture, unsigned long) ATTRIBUTE_HIDDEN;
474 extern bool _bfd_nowrite_set_section_contents
475 (bfd *, asection *, const void *, file_ptr, bfd_size_type) ATTRIBUTE_HIDDEN;
477 /* Generic routines to use for BFD_JUMP_TABLE_WRITE. Use
478 BFD_JUMP_TABLE_WRITE (_bfd_generic). */
480 #define _bfd_generic_set_arch_mach bfd_default_set_arch_mach
481 extern bool _bfd_generic_set_section_contents
482 (bfd *, asection *, const void *, file_ptr, bfd_size_type) ATTRIBUTE_HIDDEN;
484 /* Routines to use for BFD_JUMP_TABLE_LINK for targets which do not
485 support linking. Use BFD_JUMP_TABLE_LINK (_bfd_nolink). */
487 extern int _bfd_nolink_sizeof_headers
488 (bfd *, struct bfd_link_info *) ATTRIBUTE_HIDDEN;
489 extern bfd_byte *_bfd_nolink_bfd_get_relocated_section_contents
490 (bfd *, struct bfd_link_info *, struct bfd_link_order *,
491 bfd_byte *, bool, asymbol **) ATTRIBUTE_HIDDEN;
492 extern bool _bfd_nolink_bfd_relax_section
493 (bfd *, asection *, struct bfd_link_info *, bool *) ATTRIBUTE_HIDDEN;
494 #define _bfd_nolink_bfd_gc_sections _bfd_bool_bfd_link_false_error
495 extern bool _bfd_nolink_bfd_lookup_section_flags
496 (struct bfd_link_info *, struct flag_info *, asection *) ATTRIBUTE_HIDDEN;
497 #define _bfd_nolink_bfd_merge_sections _bfd_bool_bfd_link_false_error
498 extern bool _bfd_nolink_bfd_is_group_section
499 (bfd *, const asection *) ATTRIBUTE_HIDDEN;
500 extern const char *_bfd_nolink_bfd_group_name
501 (bfd *, const asection *) ATTRIBUTE_HIDDEN;
502 extern bool _bfd_nolink_bfd_discard_group
503 (bfd *, asection *) ATTRIBUTE_HIDDEN;
504 extern struct bfd_link_hash_table *_bfd_nolink_bfd_link_hash_table_create
505 (bfd *) ATTRIBUTE_HIDDEN;
506 #define _bfd_nolink_bfd_link_add_symbols _bfd_bool_bfd_link_false_error
507 extern void _bfd_nolink_bfd_link_just_syms
508 (asection *, struct bfd_link_info *) ATTRIBUTE_HIDDEN;
509 extern void _bfd_nolink_bfd_copy_link_hash_symbol_type
510 (bfd *, struct bfd_link_hash_entry *, struct bfd_link_hash_entry *)
511 ATTRIBUTE_HIDDEN;
512 #define _bfd_nolink_bfd_final_link _bfd_bool_bfd_link_false_error
513 extern bool _bfd_nolink_bfd_link_split_section
514 (bfd *, struct bfd_section *) ATTRIBUTE_HIDDEN;
515 extern bool _bfd_nolink_section_already_linked
516 (bfd *, asection *, struct bfd_link_info *) ATTRIBUTE_HIDDEN;
517 extern bool _bfd_nolink_bfd_define_common_symbol
518 (bfd *, struct bfd_link_info *, struct bfd_link_hash_entry *)
519 ATTRIBUTE_HIDDEN;
520 #define _bfd_nolink_bfd_link_hide_symbol \
521 _bfd_generic_link_hide_symbol
522 extern struct bfd_link_hash_entry *_bfd_nolink_bfd_define_start_stop
523 (struct bfd_link_info *, const char *, asection *) ATTRIBUTE_HIDDEN;
524 #define _bfd_nolink_bfd_link_check_relocs \
525 _bfd_generic_link_check_relocs
527 /* Routines to use for BFD_JUMP_TABLE_DYNAMIC for targets which do not
528 have dynamic symbols or relocs. Use BFD_JUMP_TABLE_DYNAMIC
529 (_bfd_nodynamic). */
531 #define _bfd_nodynamic_get_dynamic_symtab_upper_bound _bfd_long_bfd_n1_error
532 #define _bfd_nodynamic_canonicalize_dynamic_symtab \
533 _bfd_nosymbols_canonicalize_symtab
534 extern long _bfd_nodynamic_get_synthetic_symtab
535 (bfd *, long, asymbol **, long, asymbol **, asymbol **) ATTRIBUTE_HIDDEN;
536 #define _bfd_nodynamic_get_dynamic_reloc_upper_bound _bfd_long_bfd_n1_error
537 extern long _bfd_nodynamic_canonicalize_dynamic_reloc
538 (bfd *, arelent **, asymbol **) ATTRIBUTE_HIDDEN;
540 /* Generic routine to determine of the given symbol is a local
541 label. */
542 extern bool bfd_generic_is_local_label_name
543 (bfd *, const char *) ATTRIBUTE_HIDDEN;
545 /* Generic minisymbol routines. */
546 extern long _bfd_generic_read_minisymbols
547 (bfd *, bool, void **, unsigned int *) ATTRIBUTE_HIDDEN;
548 extern asymbol *_bfd_generic_minisymbol_to_symbol
549 (bfd *, bool, const void *, asymbol *) ATTRIBUTE_HIDDEN;
551 /* Find the nearest line using .stab/.stabstr sections. */
552 extern bool _bfd_stab_section_find_nearest_line
553 (bfd *, asymbol **, asection *, bfd_vma, bool *,
554 const char **, const char **, unsigned int *, void **) ATTRIBUTE_HIDDEN;
556 /* Find the nearest line using DWARF 1 debugging information. */
557 extern bool _bfd_dwarf1_find_nearest_line
558 (bfd *, asymbol **, asection *, bfd_vma,
559 const char **, const char **, unsigned int *) ATTRIBUTE_HIDDEN;
561 /* Clean up the data used to handle DWARF 1 debugging information. */
562 extern void _bfd_dwarf1_cleanup_debug_info
563 (bfd *, void **) ATTRIBUTE_HIDDEN;
565 struct dwarf_debug_section
567 const char * uncompressed_name;
568 const char * compressed_name;
571 /* Map of uncompressed DWARF debug section name to compressed one. It
572 is terminated by NULL uncompressed_name. */
574 extern const struct dwarf_debug_section dwarf_debug_sections[] ATTRIBUTE_HIDDEN;
576 /* Find the nearest line using DWARF 2 debugging information. */
577 extern int _bfd_dwarf2_find_nearest_line
578 (bfd *, asymbol **, asymbol *, asection *, bfd_vma,
579 const char **, const char **, unsigned int *, unsigned int *,
580 const struct dwarf_debug_section *, void **) ATTRIBUTE_HIDDEN;
582 /* Find the nearest line using DWARF 2 debugging information, with
583 the option of specifying a .gnu_debugaltlink file. */
584 extern int _bfd_dwarf2_find_nearest_line_with_alt
585 (bfd *, const char *, asymbol **, asymbol *, asection *, bfd_vma,
586 const char **, const char **, unsigned int *, unsigned int *,
587 const struct dwarf_debug_section *, void **) ATTRIBUTE_HIDDEN;
589 /* Find the bias between DWARF addresses and real addresses. */
590 extern bfd_signed_vma _bfd_dwarf2_find_symbol_bias
591 (asymbol **, void **) ATTRIBUTE_HIDDEN;
593 /* Find inliner info after calling bfd_find_nearest_line. */
594 extern bool _bfd_dwarf2_find_inliner_info
595 (bfd *, const char **, const char **, unsigned int *, void **)
596 ATTRIBUTE_HIDDEN;
598 /* Read DWARF 2 debugging information. */
599 extern bool _bfd_dwarf2_slurp_debug_info
600 (bfd *, bfd *, const struct dwarf_debug_section *, asymbol **, void **,
601 bool) ATTRIBUTE_HIDDEN;
603 /* Clean up the data used to handle DWARF 2 debugging information. */
604 extern void _bfd_dwarf2_cleanup_debug_info
605 (bfd *, void **) ATTRIBUTE_HIDDEN;
607 extern void _bfd_stab_cleanup
608 (bfd *, void **) ATTRIBUTE_HIDDEN;
610 /* Create a new section entry. */
611 extern struct bfd_hash_entry *bfd_section_hash_newfunc
612 (struct bfd_hash_entry *, struct bfd_hash_table *, const char *)
613 ATTRIBUTE_HIDDEN;
615 /* A routine to create entries for a bfd_link_hash_table. */
616 extern struct bfd_hash_entry *_bfd_link_hash_newfunc
617 (struct bfd_hash_entry *entry, struct bfd_hash_table *table,
618 const char *string) ATTRIBUTE_HIDDEN;
620 /* Initialize a bfd_link_hash_table. */
621 extern bool _bfd_link_hash_table_init
622 (struct bfd_link_hash_table *, bfd *,
623 struct bfd_hash_entry *(*) (struct bfd_hash_entry *,
624 struct bfd_hash_table *,
625 const char *),
626 unsigned int) ATTRIBUTE_HIDDEN;
628 /* Generic link hash table creation routine. */
629 extern struct bfd_link_hash_table *_bfd_generic_link_hash_table_create
630 (bfd *) ATTRIBUTE_HIDDEN;
632 /* Generic link hash table destruction routine. */
633 extern void _bfd_generic_link_hash_table_free
634 (bfd *) ATTRIBUTE_HIDDEN;
636 /* Generic add symbol routine. */
637 extern bool _bfd_generic_link_add_symbols
638 (bfd *, struct bfd_link_info *) ATTRIBUTE_HIDDEN;
640 /* Generic archive add symbol routine. */
641 extern bool _bfd_generic_link_add_archive_symbols
642 (bfd *, struct bfd_link_info *,
643 bool (*) (bfd *, struct bfd_link_info *,
644 struct bfd_link_hash_entry *, const char *,
645 bool *)) ATTRIBUTE_HIDDEN;
647 /* Forward declaration to avoid prototype errors. */
648 typedef struct bfd_link_hash_entry _bfd_link_hash_entry;
650 /* Generic routine to add a single symbol. */
651 extern bool _bfd_generic_link_add_one_symbol
652 (struct bfd_link_info *, bfd *, const char *name, flagword,
653 asection *, bfd_vma, const char *, bool copy,
654 bool constructor, struct bfd_link_hash_entry **) ATTRIBUTE_HIDDEN;
656 /* Generic routine to mark section as supplying symbols only. */
657 extern void _bfd_generic_link_just_syms
658 (asection *, struct bfd_link_info *) ATTRIBUTE_HIDDEN;
660 /* Generic routine that does nothing. */
661 extern void _bfd_generic_copy_link_hash_symbol_type
662 (bfd *, struct bfd_link_hash_entry *, struct bfd_link_hash_entry *)
663 ATTRIBUTE_HIDDEN;
665 /* Generic link routine. */
666 extern bool _bfd_generic_final_link
667 (bfd *, struct bfd_link_info *) ATTRIBUTE_HIDDEN;
669 extern bool _bfd_generic_link_split_section
670 (bfd *, struct bfd_section *) ATTRIBUTE_HIDDEN;
672 extern bool _bfd_generic_section_already_linked
673 (bfd *, asection *, struct bfd_link_info *) ATTRIBUTE_HIDDEN;
675 /* Generic reloc_link_order processing routine. */
676 extern bool _bfd_generic_reloc_link_order
677 (bfd *, struct bfd_link_info *, asection *, struct bfd_link_order *)
678 ATTRIBUTE_HIDDEN;
680 /* Default link order processing routine. */
681 extern bool _bfd_default_link_order
682 (bfd *, struct bfd_link_info *, asection *, struct bfd_link_order *)
683 ATTRIBUTE_HIDDEN;
685 /* Count the number of reloc entries in a link order list. */
686 extern unsigned int _bfd_count_link_order_relocs
687 (struct bfd_link_order *) ATTRIBUTE_HIDDEN;
689 /* Final link relocation routine. */
690 extern bfd_reloc_status_type _bfd_final_link_relocate
691 (reloc_howto_type *, bfd *, asection *, bfd_byte *,
692 bfd_vma, bfd_vma, bfd_vma) ATTRIBUTE_HIDDEN;
694 /* Relocate a particular location by a howto and a value. */
695 extern bfd_reloc_status_type _bfd_relocate_contents
696 (reloc_howto_type *, bfd *, bfd_vma, bfd_byte *) ATTRIBUTE_HIDDEN;
698 /* Clear a given location using a given howto. */
699 extern bfd_reloc_status_type _bfd_clear_contents
700 (reloc_howto_type *, bfd *, asection *, bfd_byte *, bfd_vma) ATTRIBUTE_HIDDEN;
702 /* Register a SEC_MERGE section as a candidate for merging. */
704 extern bool _bfd_add_merge_section
705 (bfd *, void **, asection *, void **) ATTRIBUTE_HIDDEN;
707 /* Attempt to merge SEC_MERGE sections. */
709 extern bool _bfd_merge_sections
710 (bfd *, struct bfd_link_info *, void *, void (*) (bfd *, asection *))
711 ATTRIBUTE_HIDDEN;
713 /* Write out a merged section. */
715 extern bool _bfd_write_merged_section
716 (bfd *, asection *, void *) ATTRIBUTE_HIDDEN;
718 /* Find an offset within a modified SEC_MERGE section. */
720 extern bfd_vma _bfd_merged_section_offset
721 (bfd *, asection **, void *, bfd_vma) ATTRIBUTE_HIDDEN;
723 /* Tidy up when done. */
725 extern void _bfd_merge_sections_free (void *) ATTRIBUTE_HIDDEN;
727 /* Macros to tell if bfds are read or write enabled.
729 Note that bfds open for read may be scribbled into if the fd passed
730 to bfd_fdopenr is actually open both for read and write
731 simultaneously. However an output bfd will never be open for
732 read. Therefore sometimes you want to check bfd_read_p or
733 !bfd_read_p, and only sometimes bfd_write_p.
736 #define bfd_read_p(abfd) \
737 ((abfd)->direction == read_direction || (abfd)->direction == both_direction)
738 #define bfd_write_p(abfd) \
739 ((abfd)->direction == write_direction || (abfd)->direction == both_direction)
741 extern void bfd_assert
742 (const char*,int) ATTRIBUTE_HIDDEN;
744 #define BFD_ASSERT(x) \
745 do { if (!(x)) bfd_assert(__FILE__,__LINE__); } while (0)
747 #define BFD_FAIL() \
748 do { bfd_assert(__FILE__,__LINE__); } while (0)
750 extern void _bfd_abort
751 (const char *, int, const char *) ATTRIBUTE_NORETURN ATTRIBUTE_HIDDEN;
753 /* if gcc >= 2.6, we can give a function name, too */
754 #if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 6)
755 #define __PRETTY_FUNCTION__ ((char *) NULL)
756 #endif
758 #undef abort
759 #define abort() _bfd_abort (__FILE__, __LINE__, __PRETTY_FUNCTION__)
761 /* Manipulate a system FILE but using BFD's "file_ptr", rather than
762 the system "off_t" or "off64_t", as the offset. */
763 extern file_ptr _bfd_real_ftell
764 (FILE *) ATTRIBUTE_HIDDEN;
765 extern int _bfd_real_fseek
766 (FILE *, file_ptr, int) ATTRIBUTE_HIDDEN;
767 extern FILE *_bfd_real_fopen
768 (const char *, const char *) ATTRIBUTE_HIDDEN;
770 /* List of supported target vectors, and the default vector (if
771 bfd_default_vector[0] is NULL, there is no default). */
772 extern const bfd_target *const *const bfd_target_vector ATTRIBUTE_HIDDEN;
773 extern const bfd_target *bfd_default_vector[] ATTRIBUTE_HIDDEN;
775 /* List of associated target vectors. */
776 extern const bfd_target *const *const bfd_associated_vector ATTRIBUTE_HIDDEN;
778 /* Functions shared by the ECOFF and MIPS ELF backends, which have no
779 other common header files. */
781 struct ecoff_debug_info;
782 struct ecoff_debug_swap;
783 struct ecoff_extr;
784 struct ecoff_find_line;
786 extern void _bfd_ecoff_free_ecoff_debug_info
787 (struct ecoff_debug_info *debug);
788 extern bool _bfd_ecoff_locate_line
789 (bfd *, asection *, bfd_vma, struct ecoff_debug_info * const,
790 const struct ecoff_debug_swap * const, struct ecoff_find_line *,
791 const char **, const char **, unsigned int *) ATTRIBUTE_HIDDEN;
792 extern bool _bfd_ecoff_get_accumulated_pdr
793 (void *, bfd_byte *) ATTRIBUTE_HIDDEN;
794 extern bool _bfd_ecoff_get_accumulated_sym
795 (void *, bfd_byte *) ATTRIBUTE_HIDDEN;
796 extern bool _bfd_ecoff_get_accumulated_ss
797 (void *, bfd_byte *) ATTRIBUTE_HIDDEN;
799 extern bfd_vma _bfd_get_gp_value
800 (bfd *) ATTRIBUTE_HIDDEN;
801 extern void _bfd_set_gp_value
802 (bfd *, bfd_vma) ATTRIBUTE_HIDDEN;
804 /* Function shared by the COFF and ELF SH backends, which have no
805 other common header files. */
807 #ifndef _bfd_sh_align_load_span
808 extern bool _bfd_sh_align_load_span
809 (bfd *, asection *, bfd_byte *,
810 bool (*) (bfd *, asection *, void *, bfd_byte *, bfd_vma),
811 void *, bfd_vma **, bfd_vma *, bfd_vma, bfd_vma, bool *) ATTRIBUTE_HIDDEN;
812 #endif
814 /* This is the shape of the elements inside the already_linked hash
815 table. It maps a name onto a list of already_linked elements with
816 the same name. */
818 struct bfd_section_already_linked_hash_entry
820 struct bfd_hash_entry root;
821 struct bfd_section_already_linked *entry;
824 struct bfd_section_already_linked
826 struct bfd_section_already_linked *next;
827 asection *sec;
830 extern struct bfd_section_already_linked_hash_entry *
831 bfd_section_already_linked_table_lookup (const char *) ATTRIBUTE_HIDDEN;
832 extern bool bfd_section_already_linked_table_insert
833 (struct bfd_section_already_linked_hash_entry *, asection *)
834 ATTRIBUTE_HIDDEN;
835 extern void bfd_section_already_linked_table_traverse
836 (bool (*) (struct bfd_section_already_linked_hash_entry *,
837 void *), void *) ATTRIBUTE_HIDDEN;
839 extern bfd_vma _bfd_read_unsigned_leb128
840 (bfd *, bfd_byte *, unsigned int *) ATTRIBUTE_HIDDEN;
841 extern bfd_signed_vma _bfd_read_signed_leb128
842 (bfd *, bfd_byte *, unsigned int *) ATTRIBUTE_HIDDEN;
843 extern bfd_vma _bfd_safe_read_leb128
844 (bfd *, bfd_byte **, bool, const bfd_byte * const) ATTRIBUTE_HIDDEN;
845 extern bfd_byte * _bfd_write_unsigned_leb128
846 (bfd_byte *, bfd_byte *, bfd_vma) ATTRIBUTE_HIDDEN;
848 extern struct bfd_link_info *_bfd_get_link_info (bfd *);
850 extern bool _bfd_link_keep_memory (struct bfd_link_info *)
851 ATTRIBUTE_HIDDEN;
853 #if GCC_VERSION >= 7000
854 #define _bfd_mul_overflow(a, b, res) __builtin_mul_overflow (a, b, res)
855 #else
856 /* Assumes unsigned values. Careful! Args evaluated multiple times. */
857 #define _bfd_mul_overflow(a, b, res) \
858 ((*res) = (a), (*res) *= (b), (b) != 0 && (*res) / (b) != (a))
859 #endif
861 #ifdef __GNUC__
862 #define _bfd_constant_p(v) __builtin_constant_p (v)
863 #else
864 #define _bfd_constant_p(v) 0
865 #endif
867 static inline void *
868 _bfd_alloc_and_read (bfd *abfd, bfd_size_type asize, bfd_size_type rsize)
870 void *mem;
871 if (!_bfd_constant_p (rsize))
873 ufile_ptr filesize = bfd_get_file_size (abfd);
874 if (filesize != 0 && rsize > filesize)
876 bfd_set_error (bfd_error_file_truncated);
877 return NULL;
880 mem = bfd_alloc (abfd, asize);
881 if (mem != NULL)
883 if (bfd_read (mem, rsize, abfd) == rsize)
884 return mem;
885 bfd_release (abfd, mem);
887 return NULL;
890 static inline void *
891 _bfd_malloc_and_read (bfd *abfd, bfd_size_type asize, bfd_size_type rsize)
893 void *mem;
894 if (!_bfd_constant_p (rsize))
896 ufile_ptr filesize = bfd_get_file_size (abfd);
897 if (filesize != 0 && rsize > filesize)
899 bfd_set_error (bfd_error_file_truncated);
900 return NULL;
903 mem = bfd_malloc (asize);
904 if (mem != NULL)
906 if (bfd_read (mem, rsize, abfd) == rsize)
907 return mem;
908 free (mem);
910 return NULL;