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