1/* libbfd.h -- Declarations used by bfd library *implementation*.
2   (This include file is not for users of the library.)
3
4   Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
5   1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
6   Free Software Foundation, Inc.
7
8   Written by Cygnus Support.
9
10This file is part of BFD, the Binary File Descriptor library.
11
12This program is free software; you can redistribute it and/or modify
13it under the terms of the GNU General Public License as published by
14the Free Software Foundation; either version 2 of the License, or
15(at your option) any later version.
16
17This program is distributed in the hope that it will be useful,
18but WITHOUT ANY WARRANTY; without even the implied warranty of
19MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20GNU General Public License for more details.
21
22You should have received a copy of the GNU General Public License
23along with this program; if not, write to the Free Software
24Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
25
26#include "hashtab.h"
27
28/* Align an address upward to a boundary, expressed as a number of bytes.
29   E.g. align to an 8-byte boundary with argument of 8.  Take care never
30   to wrap around if the address is within boundary-1 of the end of the
31   address space.  */
32#define BFD_ALIGN(this, boundary)					  \
33  ((((bfd_vma) (this) + (boundary) - 1) >= (bfd_vma) (this))		  \
34   ? (((bfd_vma) (this) + ((boundary) - 1)) & ~ (bfd_vma) ((boundary)-1)) \
35   : ~ (bfd_vma) 0)
36
37/* If you want to read and write large blocks, you might want to do it
38   in quanta of this amount */
39#define DEFAULT_BUFFERSIZE 8192
40
41/* Set a tdata field.  Can't use the other macros for this, since they
42   do casts, and casting to the left of assignment isn't portable.  */
43#define set_tdata(bfd, v) ((bfd)->tdata.any = (v))
44
45/* If BFD_IN_MEMORY is set for a BFD, then the iostream fields points
46   to an instance of this structure.  */
47
48struct bfd_in_memory
49{
50  /* Size of buffer.  */
51  bfd_size_type size;
52  /* Buffer holding contents of BFD.  */
53  bfd_byte *buffer;
54};
55
56struct section_hash_entry
57{
58  struct bfd_hash_entry root;
59  asection section;
60};
61
62/* tdata for an archive.  For an input archive, cache
63   needs to be free()'d.  For an output archive, symdefs do.  */
64
65struct artdata {
66  file_ptr first_file_filepos;
67  /* Speed up searching the armap */
68  htab_t cache;
69  bfd *archive_head;		/* Only interesting in output routines */
70  carsym *symdefs;		/* the symdef entries */
71  symindex symdef_count;	/* how many there are */
72  char *extended_names;		/* clever intel extension */
73  bfd_size_type extended_names_size; /* Size of extended names */
74  /* when more compilers are standard C, this can be a time_t */
75  long  armap_timestamp;	/* Timestamp value written into armap.
76				   This is used for BSD archives to check
77				   that the timestamp is recent enough
78				   for the BSD linker to not complain,
79				   just before we finish writing an
80				   archive.  */
81  file_ptr armap_datepos;	/* Position within archive to seek to
82				   rewrite the date field.  */
83  void *tdata;			/* Backend specific information.  */
84};
85
86#define bfd_ardata(bfd) ((bfd)->tdata.aout_ar_data)
87
88/* Goes in bfd's arelt_data slot */
89struct areltdata {
90  char * arch_header;		/* it's actually a string */
91  unsigned int parsed_size;	/* octets of filesize not including ar_hdr */
92  char *filename;		/* null-terminated */
93};
94
95#define arelt_size(bfd) (((struct areltdata *)((bfd)->arelt_data))->parsed_size)
96
97extern void *bfd_malloc
98  (bfd_size_type);
99extern void *bfd_realloc
100  (void *, bfd_size_type);
101extern void *bfd_zmalloc
102  (bfd_size_type);
103extern void *bfd_malloc2
104  (bfd_size_type, bfd_size_type);
105extern void *bfd_realloc2
106  (void *, bfd_size_type, bfd_size_type);
107extern void *bfd_zmalloc2
108  (bfd_size_type, bfd_size_type);
109
110extern void _bfd_default_error_handler (const char *s, ...);
111extern bfd_error_handler_type _bfd_error_handler;
112
113/* These routines allocate and free things on the BFD's objalloc.  */
114
115extern void *bfd_alloc
116  (bfd *, bfd_size_type);
117extern void *bfd_zalloc
118  (bfd *, bfd_size_type);
119extern void *bfd_alloc2
120  (bfd *, bfd_size_type, bfd_size_type);
121extern void *bfd_zalloc2
122  (bfd *, bfd_size_type, bfd_size_type);
123extern void bfd_release
124  (bfd *, void *);
125
126bfd * _bfd_create_empty_archive_element_shell
127  (bfd *obfd);
128bfd * _bfd_look_for_bfd_in_cache
129  (bfd *, file_ptr);
130bfd_boolean _bfd_add_bfd_to_archive_cache
131  (bfd *, file_ptr, bfd *);
132bfd_boolean _bfd_generic_mkarchive
133  (bfd *abfd);
134const bfd_target *bfd_generic_archive_p
135  (bfd *abfd);
136bfd_boolean bfd_slurp_armap
137  (bfd *abfd);
138bfd_boolean bfd_slurp_bsd_armap_f2
139  (bfd *abfd);
140#define bfd_slurp_bsd_armap bfd_slurp_armap
141#define bfd_slurp_coff_armap bfd_slurp_armap
142bfd_boolean _bfd_slurp_extended_name_table
143  (bfd *abfd);
144extern bfd_boolean _bfd_construct_extended_name_table
145  (bfd *, bfd_boolean, char **, bfd_size_type *);
146bfd_boolean _bfd_write_archive_contents
147  (bfd *abfd);
148bfd_boolean _bfd_compute_and_write_armap
149  (bfd *, unsigned int elength);
150bfd *_bfd_get_elt_at_filepos
151  (bfd *archive, file_ptr filepos);
152extern bfd *_bfd_generic_get_elt_at_index
153  (bfd *, symindex);
154bfd * _bfd_new_bfd
155  (void);
156void _bfd_delete_bfd
157  (bfd *);
158bfd_boolean _bfd_free_cached_info
159  (bfd *);
160
161bfd_boolean bfd_false
162  (bfd *ignore);
163bfd_boolean bfd_true
164  (bfd *ignore);
165void *bfd_nullvoidptr
166  (bfd *ignore);
167int bfd_0
168  (bfd *ignore);
169unsigned int bfd_0u
170  (bfd *ignore);
171long bfd_0l
172  (bfd *ignore);
173long _bfd_n1
174  (bfd *ignore);
175void bfd_void
176  (bfd *ignore);
177
178bfd *_bfd_new_bfd_contained_in
179  (bfd *);
180const bfd_target *_bfd_dummy_target
181  (bfd *abfd);
182
183void bfd_dont_truncate_arname
184  (bfd *abfd, const char *filename, char *hdr);
185void bfd_bsd_truncate_arname
186  (bfd *abfd, const char *filename, char *hdr);
187void bfd_gnu_truncate_arname
188  (bfd *abfd, const char *filename, char *hdr);
189
190bfd_boolean bsd_write_armap
191  (bfd *arch, unsigned int elength, struct orl *map, unsigned int orl_count,
192   int stridx);
193
194bfd_boolean coff_write_armap
195  (bfd *arch, unsigned int elength, struct orl *map, unsigned int orl_count,
196   int stridx);
197
198extern void *_bfd_generic_read_ar_hdr
199  (bfd *);
200extern void _bfd_ar_spacepad
201  (char *, size_t, const char *, long);
202
203extern void *_bfd_generic_read_ar_hdr_mag
204  (bfd *, const char *);
205
206bfd * bfd_generic_openr_next_archived_file
207  (bfd *archive, bfd *last_file);
208
209int bfd_generic_stat_arch_elt
210  (bfd *, struct stat *);
211
212#define _bfd_read_ar_hdr(abfd) \
213  BFD_SEND (abfd, _bfd_read_ar_hdr_fn, (abfd))
214
215/* Generic routines to use for BFD_JUMP_TABLE_GENERIC.  Use
216   BFD_JUMP_TABLE_GENERIC (_bfd_generic).  */
217
218#define _bfd_generic_close_and_cleanup bfd_true
219#define _bfd_generic_bfd_free_cached_info bfd_true
220extern bfd_boolean _bfd_generic_new_section_hook
221  (bfd *, asection *);
222extern bfd_boolean _bfd_generic_get_section_contents
223  (bfd *, asection *, void *, file_ptr, bfd_size_type);
224extern bfd_boolean _bfd_generic_get_section_contents_in_window
225  (bfd *, asection *, bfd_window *, file_ptr, bfd_size_type);
226
227/* Generic routines to use for BFD_JUMP_TABLE_COPY.  Use
228   BFD_JUMP_TABLE_COPY (_bfd_generic).  */
229
230#define _bfd_generic_bfd_copy_private_bfd_data \
231  ((bfd_boolean (*) (bfd *, bfd *)) bfd_true)
232#define _bfd_generic_bfd_merge_private_bfd_data \
233  ((bfd_boolean (*) (bfd *, bfd *)) bfd_true)
234#define _bfd_generic_bfd_set_private_flags \
235  ((bfd_boolean (*) (bfd *, flagword)) bfd_true)
236#define _bfd_generic_bfd_copy_private_section_data \
237  ((bfd_boolean (*) (bfd *, asection *, bfd *, asection *)) bfd_true)
238#define _bfd_generic_bfd_copy_private_symbol_data \
239  ((bfd_boolean (*) (bfd *, asymbol *, bfd *, asymbol *)) bfd_true)
240#define _bfd_generic_bfd_copy_private_header_data \
241  ((bfd_boolean (*) (bfd *, bfd *)) bfd_true)
242#define _bfd_generic_bfd_print_private_bfd_data \
243  ((bfd_boolean (*) (bfd *, void *)) bfd_true)
244
245extern bfd_boolean _bfd_generic_init_private_section_data
246  (bfd *, asection *, bfd *, asection *, struct bfd_link_info *);
247
248/* Routines to use for BFD_JUMP_TABLE_CORE when there is no core file
249   support.  Use BFD_JUMP_TABLE_CORE (_bfd_nocore).  */
250
251extern char *_bfd_nocore_core_file_failing_command
252  (bfd *);
253extern int _bfd_nocore_core_file_failing_signal
254  (bfd *);
255extern bfd_boolean _bfd_nocore_core_file_matches_executable_p
256  (bfd *, bfd *);
257
258/* Routines to use for BFD_JUMP_TABLE_ARCHIVE when there is no archive
259   file support.  Use BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive).  */
260
261#define _bfd_noarchive_slurp_armap bfd_false
262#define _bfd_noarchive_slurp_extended_name_table bfd_false
263#define _bfd_noarchive_construct_extended_name_table \
264  ((bfd_boolean (*) (bfd *, char **, bfd_size_type *, const char **)) \
265   bfd_false)
266#define _bfd_noarchive_truncate_arname \
267  ((void (*) (bfd *, const char *, char *)) bfd_void)
268#define _bfd_noarchive_write_armap \
269  ((bfd_boolean (*) (bfd *, unsigned int, struct orl *, unsigned int, int)) \
270   bfd_false)
271#define _bfd_noarchive_read_ar_hdr bfd_nullvoidptr
272#define _bfd_noarchive_openr_next_archived_file \
273  ((bfd *(*) (bfd *, bfd *)) bfd_nullvoidptr)
274#define _bfd_noarchive_get_elt_at_index \
275  ((bfd *(*) (bfd *, symindex)) bfd_nullvoidptr)
276#define _bfd_noarchive_generic_stat_arch_elt bfd_generic_stat_arch_elt
277#define _bfd_noarchive_update_armap_timestamp bfd_false
278
279/* Routines to use for BFD_JUMP_TABLE_ARCHIVE to get BSD style
280   archives.  Use BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_bsd).  */
281
282#define _bfd_archive_bsd_slurp_armap bfd_slurp_bsd_armap
283#define _bfd_archive_bsd_slurp_extended_name_table \
284  _bfd_slurp_extended_name_table
285extern bfd_boolean _bfd_archive_bsd_construct_extended_name_table
286  (bfd *, char **, bfd_size_type *, const char **);
287#define _bfd_archive_bsd_truncate_arname bfd_bsd_truncate_arname
288#define _bfd_archive_bsd_write_armap bsd_write_armap
289#define _bfd_archive_bsd_read_ar_hdr _bfd_generic_read_ar_hdr
290#define _bfd_archive_bsd_openr_next_archived_file \
291  bfd_generic_openr_next_archived_file
292#define _bfd_archive_bsd_get_elt_at_index _bfd_generic_get_elt_at_index
293#define _bfd_archive_bsd_generic_stat_arch_elt \
294  bfd_generic_stat_arch_elt
295extern bfd_boolean _bfd_archive_bsd_update_armap_timestamp
296  (bfd *);
297
298/* Routines to use for BFD_JUMP_TABLE_ARCHIVE to get COFF style
299   archives.  Use BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff).  */
300
301#define _bfd_archive_coff_slurp_armap bfd_slurp_coff_armap
302#define _bfd_archive_coff_slurp_extended_name_table \
303  _bfd_slurp_extended_name_table
304extern bfd_boolean _bfd_archive_coff_construct_extended_name_table
305  (bfd *, char **, bfd_size_type *, const char **);
306#define _bfd_archive_coff_truncate_arname bfd_dont_truncate_arname
307#define _bfd_archive_coff_write_armap coff_write_armap
308#define _bfd_archive_coff_read_ar_hdr _bfd_generic_read_ar_hdr
309#define _bfd_archive_coff_openr_next_archived_file \
310  bfd_generic_openr_next_archived_file
311#define _bfd_archive_coff_get_elt_at_index _bfd_generic_get_elt_at_index
312#define _bfd_archive_coff_generic_stat_arch_elt \
313  bfd_generic_stat_arch_elt
314#define _bfd_archive_coff_update_armap_timestamp bfd_true
315
316/* Routines to use for BFD_JUMP_TABLE_SYMBOLS where there is no symbol
317   support.  Use BFD_JUMP_TABLE_SYMBOLS (_bfd_nosymbols).  */
318
319#define _bfd_nosymbols_get_symtab_upper_bound _bfd_n1
320#define _bfd_nosymbols_canonicalize_symtab \
321  ((long (*) (bfd *, asymbol **)) _bfd_n1)
322#define _bfd_nosymbols_make_empty_symbol _bfd_generic_make_empty_symbol
323#define _bfd_nosymbols_print_symbol \
324  ((void (*) (bfd *, void *, asymbol *, bfd_print_symbol_type)) bfd_void)
325#define _bfd_nosymbols_get_symbol_info \
326  ((void (*) (bfd *, asymbol *, symbol_info *)) bfd_void)
327#define _bfd_nosymbols_bfd_is_local_label_name \
328  ((bfd_boolean (*) (bfd *, const char *)) bfd_false)
329#define _bfd_nosymbols_bfd_is_target_special_symbol \
330  ((bfd_boolean (*) (bfd *, asymbol *)) bfd_false)
331#define _bfd_nosymbols_get_lineno \
332  ((alent *(*) (bfd *, asymbol *)) bfd_nullvoidptr)
333#define _bfd_nosymbols_find_nearest_line \
334  ((bfd_boolean (*) (bfd *, asection *, asymbol **, bfd_vma, const char **, \
335		     const char **, unsigned int *)) \
336   bfd_false)
337#define _bfd_nosymbols_find_inliner_info \
338  ((bfd_boolean (*) (bfd *, const char **, const char **, unsigned int *)) \
339   bfd_false)
340#define _bfd_nosymbols_bfd_make_debug_symbol \
341  ((asymbol *(*) (bfd *, void *, unsigned long)) bfd_nullvoidptr)
342#define _bfd_nosymbols_read_minisymbols \
343  ((long (*) (bfd *, bfd_boolean, void **, unsigned int *)) _bfd_n1)
344#define _bfd_nosymbols_minisymbol_to_symbol \
345  ((asymbol *(*) (bfd *, bfd_boolean, const void *, asymbol *)) \
346   bfd_nullvoidptr)
347
348/* Routines to use for BFD_JUMP_TABLE_RELOCS when there is no reloc
349   support.  Use BFD_JUMP_TABLE_RELOCS (_bfd_norelocs).  */
350
351extern long _bfd_norelocs_get_reloc_upper_bound (bfd *, asection *);
352extern long _bfd_norelocs_canonicalize_reloc (bfd *, asection *,
353					      arelent **, asymbol **);
354#define _bfd_norelocs_bfd_reloc_type_lookup \
355  ((reloc_howto_type *(*) (bfd *, bfd_reloc_code_real_type)) bfd_nullvoidptr)
356#define _bfd_norelocs_bfd_reloc_name_lookup \
357  ((reloc_howto_type *(*) (bfd *, const char *)) bfd_nullvoidptr)
358
359/* Routines to use for BFD_JUMP_TABLE_WRITE for targets which may not
360   be written.  Use BFD_JUMP_TABLE_WRITE (_bfd_nowrite).  */
361
362#define _bfd_nowrite_set_arch_mach \
363  ((bfd_boolean (*) (bfd *, enum bfd_architecture, unsigned long)) \
364   bfd_false)
365#define _bfd_nowrite_set_section_contents \
366  ((bfd_boolean (*) (bfd *, asection *, const void *, file_ptr, bfd_size_type)) \
367   bfd_false)
368
369/* Generic routines to use for BFD_JUMP_TABLE_WRITE.  Use
370   BFD_JUMP_TABLE_WRITE (_bfd_generic).  */
371
372#define _bfd_generic_set_arch_mach bfd_default_set_arch_mach
373extern bfd_boolean _bfd_generic_set_section_contents
374  (bfd *, asection *, const void *, file_ptr, bfd_size_type);
375
376/* Routines to use for BFD_JUMP_TABLE_LINK for targets which do not
377   support linking.  Use BFD_JUMP_TABLE_LINK (_bfd_nolink).  */
378
379#define _bfd_nolink_sizeof_headers \
380  ((int (*) (bfd *, struct bfd_link_info *)) bfd_0)
381#define _bfd_nolink_bfd_get_relocated_section_contents \
382  ((bfd_byte *(*) (bfd *, struct bfd_link_info *, struct bfd_link_order *, \
383		   bfd_byte *, bfd_boolean, asymbol **)) \
384   bfd_nullvoidptr)
385#define _bfd_nolink_bfd_relax_section \
386  ((bfd_boolean (*) \
387    (bfd *, asection *, struct bfd_link_info *, bfd_boolean *)) \
388   bfd_false)
389#define _bfd_nolink_bfd_gc_sections \
390  ((bfd_boolean (*) (bfd *, struct bfd_link_info *)) \
391   bfd_false)
392#define _bfd_nolink_bfd_merge_sections \
393  ((bfd_boolean (*) (bfd *, struct bfd_link_info *)) \
394   bfd_false)
395#define _bfd_nolink_bfd_is_group_section \
396  ((bfd_boolean (*) (bfd *, const struct bfd_section *)) \
397   bfd_false)
398#define _bfd_nolink_bfd_discard_group \
399  ((bfd_boolean (*) (bfd *, struct bfd_section *)) \
400   bfd_false)
401#define _bfd_nolink_bfd_link_hash_table_create \
402  ((struct bfd_link_hash_table *(*) (bfd *)) bfd_nullvoidptr)
403#define _bfd_nolink_bfd_link_hash_table_free \
404  ((void (*) (struct bfd_link_hash_table *)) bfd_void)
405#define _bfd_nolink_bfd_link_add_symbols \
406  ((bfd_boolean (*) (bfd *, struct bfd_link_info *)) bfd_false)
407#define _bfd_nolink_bfd_link_just_syms \
408  ((void (*) (asection *, struct bfd_link_info *)) bfd_void)
409#define _bfd_nolink_bfd_final_link \
410  ((bfd_boolean (*) (bfd *, struct bfd_link_info *)) bfd_false)
411#define _bfd_nolink_bfd_link_split_section \
412  ((bfd_boolean (*) (bfd *, struct bfd_section *)) bfd_false)
413#define _bfd_nolink_section_already_linked \
414  ((void (*) (bfd *, struct bfd_section *, struct bfd_link_info *)) bfd_void)
415
416/* Routines to use for BFD_JUMP_TABLE_DYNAMIC for targets which do not
417   have dynamic symbols or relocs.  Use BFD_JUMP_TABLE_DYNAMIC
418   (_bfd_nodynamic).  */
419
420#define _bfd_nodynamic_get_dynamic_symtab_upper_bound _bfd_n1
421#define _bfd_nodynamic_canonicalize_dynamic_symtab \
422  ((long (*) (bfd *, asymbol **)) _bfd_n1)
423#define _bfd_nodynamic_get_synthetic_symtab \
424  ((long (*) (bfd *, long, asymbol **, long, asymbol **, asymbol **)) _bfd_n1)
425#define _bfd_nodynamic_get_dynamic_reloc_upper_bound _bfd_n1
426#define _bfd_nodynamic_canonicalize_dynamic_reloc \
427  ((long (*) (bfd *, arelent **, asymbol **)) _bfd_n1)
428
429/* Generic routine to determine of the given symbol is a local
430   label.  */
431extern bfd_boolean bfd_generic_is_local_label_name
432  (bfd *, const char *);
433
434/* Generic minisymbol routines.  */
435extern long _bfd_generic_read_minisymbols
436  (bfd *, bfd_boolean, void **, unsigned int *);
437extern asymbol *_bfd_generic_minisymbol_to_symbol
438  (bfd *, bfd_boolean, const void *, asymbol *);
439
440/* Find the nearest line using .stab/.stabstr sections.  */
441extern bfd_boolean _bfd_stab_section_find_nearest_line
442  (bfd *, asymbol **, asection *, bfd_vma, bfd_boolean *,
443   const char **, const char **, unsigned int *, void **);
444
445/* Find the nearest line using DWARF 1 debugging information.  */
446extern bfd_boolean _bfd_dwarf1_find_nearest_line
447  (bfd *, asection *, asymbol **, bfd_vma, const char **,
448   const char **, unsigned int *);
449
450/* Find the nearest line using DWARF 2 debugging information.  */
451extern bfd_boolean _bfd_dwarf2_find_nearest_line
452  (bfd *, asection *, asymbol **, bfd_vma, const char **, const char **,
453   unsigned int *, unsigned int, void **);
454
455/* Find the line using DWARF 2 debugging information.  */
456extern bfd_boolean _bfd_dwarf2_find_line
457  (bfd *, asymbol **, asymbol *, const char **,
458   unsigned int *, unsigned int, void **);
459
460bfd_boolean _bfd_generic_find_line
461  (bfd *, asymbol **, asymbol *, const char **, unsigned int *);
462
463/* Find inliner info after calling bfd_find_nearest_line. */
464extern bfd_boolean _bfd_dwarf2_find_inliner_info
465  (bfd *, const char **, const char **, unsigned int *, void **);
466
467/* Create a new section entry.  */
468extern struct bfd_hash_entry *bfd_section_hash_newfunc
469  (struct bfd_hash_entry *, struct bfd_hash_table *, const char *);
470
471/* A routine to create entries for a bfd_link_hash_table.  */
472extern struct bfd_hash_entry *_bfd_link_hash_newfunc
473  (struct bfd_hash_entry *entry, struct bfd_hash_table *table,
474   const char *string);
475
476/* Initialize a bfd_link_hash_table.  */
477extern bfd_boolean _bfd_link_hash_table_init
478  (struct bfd_link_hash_table *, bfd *,
479   struct bfd_hash_entry *(*) (struct bfd_hash_entry *,
480			       struct bfd_hash_table *,
481			       const char *),
482   unsigned int);
483
484/* Generic link hash table creation routine.  */
485extern struct bfd_link_hash_table *_bfd_generic_link_hash_table_create
486  (bfd *);
487
488/* Generic link hash table destruction routine.  */
489extern void _bfd_generic_link_hash_table_free
490  (struct bfd_link_hash_table *);
491
492/* Generic add symbol routine.  */
493extern bfd_boolean _bfd_generic_link_add_symbols
494  (bfd *, struct bfd_link_info *);
495
496/* Generic add symbol routine.  This version is used by targets for
497   which the linker must collect constructors and destructors by name,
498   as the collect2 program does.  */
499extern bfd_boolean _bfd_generic_link_add_symbols_collect
500  (bfd *, struct bfd_link_info *);
501
502/* Generic archive add symbol routine.  */
503extern bfd_boolean _bfd_generic_link_add_archive_symbols
504  (bfd *, struct bfd_link_info *,
505   bfd_boolean (*) (bfd *, struct bfd_link_info *, bfd_boolean *));
506
507/* Forward declaration to avoid prototype errors.  */
508typedef struct bfd_link_hash_entry _bfd_link_hash_entry;
509
510/* Generic routine to add a single symbol.  */
511extern bfd_boolean _bfd_generic_link_add_one_symbol
512  (struct bfd_link_info *, bfd *, const char *name, flagword,
513   asection *, bfd_vma, const char *, bfd_boolean copy,
514   bfd_boolean constructor, struct bfd_link_hash_entry **);
515
516/* Generic routine to mark section as supplying symbols only.  */
517extern void _bfd_generic_link_just_syms
518  (asection *, struct bfd_link_info *);
519
520/* Generic link routine.  */
521extern bfd_boolean _bfd_generic_final_link
522  (bfd *, struct bfd_link_info *);
523
524extern bfd_boolean _bfd_generic_link_split_section
525  (bfd *, struct bfd_section *);
526
527extern void _bfd_generic_section_already_linked
528  (bfd *, struct bfd_section *, struct bfd_link_info *);
529
530/* Generic reloc_link_order processing routine.  */
531extern bfd_boolean _bfd_generic_reloc_link_order
532  (bfd *, struct bfd_link_info *, asection *, struct bfd_link_order *);
533
534/* Default link order processing routine.  */
535extern bfd_boolean _bfd_default_link_order
536  (bfd *, struct bfd_link_info *, asection *, struct bfd_link_order *);
537
538/* Count the number of reloc entries in a link order list.  */
539extern unsigned int _bfd_count_link_order_relocs
540  (struct bfd_link_order *);
541
542/* Final link relocation routine.  */
543extern bfd_reloc_status_type _bfd_final_link_relocate
544  (reloc_howto_type *, bfd *, asection *, bfd_byte *,
545   bfd_vma, bfd_vma, bfd_vma);
546
547/* Relocate a particular location by a howto and a value.  */
548extern bfd_reloc_status_type _bfd_relocate_contents
549  (reloc_howto_type *, bfd *, bfd_vma, bfd_byte *);
550
551/* Clear a given location using a given howto.  */
552extern void _bfd_clear_contents (reloc_howto_type *howto, bfd *input_bfd,
553				 bfd_byte *location);
554
555/* Link stabs in sections in the first pass.  */
556
557extern bfd_boolean _bfd_link_section_stabs
558  (bfd *, struct stab_info *, asection *, asection *, void **,
559   bfd_size_type *);
560
561/* Eliminate stabs for discarded functions and symbols.  */
562extern bfd_boolean _bfd_discard_section_stabs
563  (bfd *, asection *, void *, bfd_boolean (*) (bfd_vma, void *), void *);
564
565/* Write out the .stab section when linking stabs in sections.  */
566
567extern bfd_boolean _bfd_write_section_stabs
568  (bfd *, struct stab_info *, asection *, void **, bfd_byte *);
569
570/* Write out the .stabstr string table when linking stabs in sections.  */
571
572extern bfd_boolean _bfd_write_stab_strings
573  (bfd *, struct stab_info *);
574
575/* Find an offset within a .stab section when linking stabs in
576   sections.  */
577
578extern bfd_vma _bfd_stab_section_offset
579  (asection *, void *, bfd_vma);
580
581/* Register a SEC_MERGE section as a candidate for merging.  */
582
583extern bfd_boolean _bfd_add_merge_section
584  (bfd *, void **, asection *, void **);
585
586/* Attempt to merge SEC_MERGE sections.  */
587
588extern bfd_boolean _bfd_merge_sections
589  (bfd *, struct bfd_link_info *, void *, void (*) (bfd *, asection *));
590
591/* Write out a merged section.  */
592
593extern bfd_boolean _bfd_write_merged_section
594  (bfd *, asection *, void *);
595
596/* Find an offset within a modified SEC_MERGE section.  */
597
598extern bfd_vma _bfd_merged_section_offset
599  (bfd *, asection **, void *, bfd_vma);
600
601/* Create a string table.  */
602extern struct bfd_strtab_hash *_bfd_stringtab_init
603  (void);
604
605/* Create an XCOFF .debug section style string table.  */
606extern struct bfd_strtab_hash *_bfd_xcoff_stringtab_init
607  (void);
608
609/* Free a string table.  */
610extern void _bfd_stringtab_free
611  (struct bfd_strtab_hash *);
612
613/* Get the size of a string table.  */
614extern bfd_size_type _bfd_stringtab_size
615  (struct bfd_strtab_hash *);
616
617/* Add a string to a string table.  */
618extern bfd_size_type _bfd_stringtab_add
619  (struct bfd_strtab_hash *, const char *, bfd_boolean hash, bfd_boolean copy);
620
621/* Write out a string table.  */
622extern bfd_boolean _bfd_stringtab_emit
623  (bfd *, struct bfd_strtab_hash *);
624
625/* Check that endianness of input and output file match.  */
626extern bfd_boolean _bfd_generic_verify_endian_match
627  (bfd *, bfd *);
628
629/* Macros to tell if bfds are read or write enabled.
630
631   Note that bfds open for read may be scribbled into if the fd passed
632   to bfd_fdopenr is actually open both for read and write
633   simultaneously.  However an output bfd will never be open for
634   read.  Therefore sometimes you want to check bfd_read_p or
635   !bfd_read_p, and only sometimes bfd_write_p.
636*/
637
638#define	bfd_read_p(abfd) \
639  ((abfd)->direction == read_direction || (abfd)->direction == both_direction)
640#define	bfd_write_p(abfd) \
641  ((abfd)->direction == write_direction || (abfd)->direction == both_direction)
642
643void bfd_assert
644  (const char*,int);
645
646#define BFD_ASSERT(x) \
647  do { if (!(x)) bfd_assert(__FILE__,__LINE__); } while (0)
648
649#define BFD_FAIL() \
650  do { bfd_assert(__FILE__,__LINE__); } while (0)
651
652extern void _bfd_abort
653  (const char *, int, const char *) ATTRIBUTE_NORETURN;
654
655/* if gcc >= 2.6, we can give a function name, too */
656#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 6)
657#define __PRETTY_FUNCTION__  ((char *) NULL)
658#endif
659
660#undef abort
661#define abort() _bfd_abort (__FILE__, __LINE__, __PRETTY_FUNCTION__)
662
663/* Manipulate a system FILE but using BFD's "file_ptr", rather than
664   the system "off_t" or "off64_t", as the offset.  */
665extern file_ptr real_ftell (FILE *file);
666extern int real_fseek (FILE *file, file_ptr offset, int whence);
667extern FILE *real_fopen (const char *filename, const char *modes);
668
669/* List of supported target vectors, and the default vector (if
670   bfd_default_vector[0] is NULL, there is no default).  */
671extern const bfd_target * const *bfd_target_vector;
672extern const bfd_target *bfd_default_vector[];
673
674/* List of associated target vectors.  */
675extern const bfd_target * const *bfd_associated_vector;
676
677/* Functions shared by the ECOFF and MIPS ELF backends, which have no
678   other common header files.  */
679
680#if defined(__STDC__) || defined(ALMOST_STDC)
681struct ecoff_find_line;
682#endif
683
684extern bfd_boolean _bfd_ecoff_locate_line
685  (bfd *, asection *, bfd_vma, struct ecoff_debug_info * const,
686   const struct ecoff_debug_swap * const, struct ecoff_find_line *,
687   const char **, const char **, unsigned int *);
688extern bfd_boolean _bfd_ecoff_get_accumulated_pdr
689  (void *, bfd_byte *);
690extern bfd_boolean _bfd_ecoff_get_accumulated_sym
691  (void *, bfd_byte *);
692extern bfd_boolean _bfd_ecoff_get_accumulated_ss
693  (void *, bfd_byte *);
694
695extern bfd_vma _bfd_get_gp_value
696  (bfd *);
697extern void _bfd_set_gp_value
698  (bfd *, bfd_vma);
699
700/* Function shared by the COFF and ELF SH backends, which have no
701   other common header files.  */
702
703#ifndef _bfd_sh_align_load_span
704extern bfd_boolean _bfd_sh_align_load_span
705  (bfd *, asection *, bfd_byte *,
706   bfd_boolean (*) (bfd *, asection *, void *, bfd_byte *, bfd_vma),
707   void *, bfd_vma **, bfd_vma *, bfd_vma, bfd_vma, bfd_boolean *);
708#endif
709
710/* This is the shape of the elements inside the already_linked hash
711   table. It maps a name onto a list of already_linked elements with
712   the same name.  */
713
714struct bfd_section_already_linked_hash_entry
715{
716  struct bfd_hash_entry root;
717  struct bfd_section_already_linked *entry;
718};
719
720struct bfd_section_already_linked
721{
722  struct bfd_section_already_linked *next;
723  asection *sec;
724};
725
726extern struct bfd_section_already_linked_hash_entry *
727  bfd_section_already_linked_table_lookup (const char *);
728extern void bfd_section_already_linked_table_insert
729  (struct bfd_section_already_linked_hash_entry *, asection *);
730extern void bfd_section_already_linked_table_traverse
731  (bfd_boolean (*) (struct bfd_section_already_linked_hash_entry *,
732		    void *), void *);
733
734extern bfd_vma read_unsigned_leb128 (bfd *, bfd_byte *, unsigned int *);
735extern bfd_signed_vma read_signed_leb128 (bfd *, bfd_byte *, unsigned int *);
736
737