OSDN Git Service

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