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