bfd-in.h revision 104834
1246120Sgahr/* Main header file for the bfd library -- portable access to object files.
2246206Sgahr   Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3246206Sgahr   2000, 2001, 2002
4246206Sgahr   Free Software Foundation, Inc.
5246206Sgahr   Contributed by Cygnus Support.
6246206Sgahr
7246206Sgahr   This file is part of BFD, the Binary File Descriptor library.
8246206Sgahr
9246206Sgahr   This program is free software; you can redistribute it and/or modify
10246206Sgahr   it under the terms of the GNU General Public License as published by
11246206Sgahr   the Free Software Foundation; either version 2 of the License, or
12246206Sgahr   (at your option) any later version.
13246206Sgahr
14246206Sgahr   This program is distributed in the hope that it will be useful,
15246206Sgahr   but WITHOUT ANY WARRANTY; without even the implied warranty of
16246206Sgahr   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17246206Sgahr   GNU General Public License for more details.
18246206Sgahr
19246206Sgahr   You should have received a copy of the GNU General Public License
20246206Sgahr   along with this program; if not, write to the Free Software
21246206Sgahr   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
22246206Sgahr
23246206Sgahr#ifndef __BFD_H_SEEN__
24246206Sgahr#define __BFD_H_SEEN__
25246120Sgahr
26246120Sgahr#ifdef __cplusplus
27246120Sgahrextern "C" {
28246120Sgahr#endif
29246148Sgahr
30246206Sgahr#include "ansidecl.h"
31246120Sgahr#include "symcat.h"
32246120Sgahr#if defined (__STDC__) || defined (ALMOST_STDC) || defined (HAVE_STRINGIZE)
33246120Sgahr#ifndef SABER
34246120Sgahr/* This hack is to avoid a problem with some strict ANSI C preprocessors.
35246148Sgahr   The problem is, "32_" is not a valid preprocessing token, and we don't
36246120Sgahr   want extra underscores (e.g., "nlm_32_").  The XCONCAT2 macro will
37246148Sgahr   cause the inner CONCAT2 macros to be evaluated first, producing
38246120Sgahr   still-valid pp-tokens.  Then the final concatenation can be done.  */
39246148Sgahr#undef CONCAT4
40246206Sgahr#define CONCAT4(a,b,c,d) XCONCAT2(CONCAT2(a,b),CONCAT2(c,d))
41246148Sgahr#endif
42246148Sgahr#endif
43246148Sgahr
44246148Sgahr#define BFD_VERSION @bfd_version@
45246120Sgahr#define BFD_VERSION_DATE @bfd_version_date@
46246120Sgahr#define BFD_VERSION_STRING @bfd_version_string@
47246206Sgahr
48246206Sgahr/* The word size used by BFD on the host.  This may be 64 with a 32
49246206Sgahr   bit target if the host is 64 bit, or if other 64 bit targets have
50246206Sgahr   been selected with --enable-targets, or if --enable-64-bit-bfd.  */
51246120Sgahr#define BFD_ARCH_SIZE @wordsize@
52246120Sgahr
53246206Sgahr/* The word size of the default bfd target.  */
54246120Sgahr#define BFD_DEFAULT_TARGET_SIZE @bfd_default_target_size@
55246148Sgahr
56246148Sgahr#define BFD_HOST_64BIT_LONG @BFD_HOST_64BIT_LONG@
57246148Sgahr#if @BFD_HOST_64_BIT_DEFINED@
58246148Sgahr#define BFD_HOST_64_BIT @BFD_HOST_64_BIT@
59246206Sgahr#define BFD_HOST_U_64_BIT @BFD_HOST_U_64_BIT@
60266971Sgahr#endif
61266971Sgahr
62266971Sgahr#if BFD_ARCH_SIZE >= 64
63266971Sgahr#define BFD64
64266971Sgahr#endif
65266971Sgahr
66266971Sgahr#ifndef INLINE
67266971Sgahr#if __GNUC__ >= 2
68246148Sgahr#define INLINE __inline__
69246148Sgahr#else
70246206Sgahr#define INLINE
71246206Sgahr#endif
72246148Sgahr#endif
73246148Sgahr
74246148Sgahr/* Forward declaration.  */
75246148Sgahrtypedef struct _bfd bfd;
76246148Sgahr
77246206Sgahr/* To squelch erroneous compiler warnings ("illegal pointer
78246148Sgahr   combination") from the SVR3 compiler, we would like to typedef
79246148Sgahr   boolean to int (it doesn't like functions which return boolean.
80246148Sgahr   Making sure they are never implicitly declared to return int
81246148Sgahr   doesn't seem to help).  But this file is not configured based on
82246148Sgahr   the host.  */
83246148Sgahr/* General rules: functions which are boolean return true on success
84246148Sgahr   and false on failure (unless they're a predicate).   -- bfd.doc */
85246148Sgahr/* I'm sure this is going to break something and someone is going to
86246206Sgahr   force me to change it.  */
87246120Sgahr/* typedef enum boolean {false, true} boolean; */
88246120Sgahr/* Yup, SVR4 has a "typedef enum boolean" in <sys/types.h>  -fnf */
89246120Sgahr/* It gets worse if the host also defines a true/false enum... -sts */
90246120Sgahr/* And even worse if your compiler has built-in boolean types... -law */
91246148Sgahr/* And even worse if your compiler provides a stdbool.h that conflicts
92246148Sgahr   with these definitions... gcc 2.95 and later do.  If so, it must
93246120Sgahr   be included first.  -drow */
94246148Sgahr#if defined (__GNUG__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 6))
95246120Sgahr#define TRUE_FALSE_ALREADY_DEFINED
96246120Sgahr#else
97246206Sgahr#if defined (__bool_true_false_are_defined)
98246120Sgahr/* We have <stdbool.h>.  */
99246206Sgahr#define TRUE_FALSE_ALREADY_DEFINED
100246120Sgahr#endif
101246120Sgahr#endif
102246148Sgahr#ifdef MPW
103246148Sgahr/* Pre-emptive strike - get the file with the enum.  */
104246148Sgahr#include <Types.h>
105246148Sgahr#define TRUE_FALSE_ALREADY_DEFINED
106246148Sgahr#endif /* MPW */
107246148Sgahr#ifndef TRUE_FALSE_ALREADY_DEFINED
108246148Sgahrtypedef enum bfd_boolean {false, true} boolean;
109246120Sgahr#define BFD_TRUE_FALSE
110246120Sgahr#else
111246120Sgahr/* Use enum names that will appear nowhere else.  */
112246148Sgahrtypedef enum bfd_boolean {bfd_fffalse, bfd_tttrue} boolean;
113246148Sgahr#endif
114246120Sgahr
115246148Sgahr/* Support for different sizes of target format ints and addresses.
116246148Sgahr   If the type `long' is at least 64 bits, BFD_HOST_64BIT_LONG will be
117246148Sgahr   set to 1 above.  Otherwise, if gcc is being used, this code will
118246206Sgahr   use gcc's "long long" type.  Otherwise, BFD_HOST_64_BIT must be
119246148Sgahr   defined above.  */
120246148Sgahr
121246148Sgahr#ifndef BFD_HOST_64_BIT
122246148Sgahr# if BFD_HOST_64BIT_LONG
123246206Sgahr#  define BFD_HOST_64_BIT long
124246148Sgahr#  define BFD_HOST_U_64_BIT unsigned long
125246206Sgahr# else
126246148Sgahr#  ifdef __GNUC__
127246148Sgahr#   if __GNUC__ >= 2
128246148Sgahr#    define BFD_HOST_64_BIT long long
129246148Sgahr#    define BFD_HOST_U_64_BIT unsigned long long
130266971Sgahr#   endif /* __GNUC__ >= 2 */
131246148Sgahr#  endif /* ! defined (__GNUC__) */
132246148Sgahr# endif /* ! BFD_HOST_64BIT_LONG */
133246148Sgahr#endif /* ! defined (BFD_HOST_64_BIT) */
134246148Sgahr
135246148Sgahr#ifdef BFD64
136246148Sgahr
137246148Sgahr#ifndef BFD_HOST_64_BIT
138246148Sgahr #error No 64 bit integer type available
139246148Sgahr#endif /* ! defined (BFD_HOST_64_BIT) */
140246206Sgahr
141246148Sgahrtypedef BFD_HOST_U_64_BIT bfd_vma;
142246148Sgahrtypedef BFD_HOST_64_BIT bfd_signed_vma;
143246120Sgahrtypedef BFD_HOST_U_64_BIT bfd_size_type;
144246120Sgahrtypedef BFD_HOST_U_64_BIT symvalue;
145246120Sgahr
146246120Sgahr#ifndef fprintf_vma
147246206Sgahr#if BFD_HOST_64BIT_LONG
148246206Sgahr#define sprintf_vma(s,x) sprintf (s, "%016lx", x)
149246120Sgahr#define fprintf_vma(f,x) fprintf (f, "%016lx", x)
150246120Sgahr#else
151246120Sgahr#define _bfd_int64_low(x) ((unsigned long) (((x) & 0xffffffff)))
152289931Sache#define _bfd_int64_high(x) ((unsigned long) (((x) >> 32) & 0xffffffff))
153289931Sache#define fprintf_vma(s,x) \
154289931Sache  fprintf ((s), "%08lx%08lx", _bfd_int64_high (x), _bfd_int64_low (x))
155246148Sgahr#define sprintf_vma(s,x) \
156246148Sgahr  sprintf ((s), "%08lx%08lx", _bfd_int64_high (x), _bfd_int64_low (x))
157246148Sgahr#endif
158246148Sgahr#endif
159246206Sgahr
160246120Sgahr#else /* not BFD64  */
161246120Sgahr
162246120Sgahr/* Represent a target address.  Also used as a generic unsigned type
163246120Sgahr   which is guaranteed to be big enough to hold any arithmetic types
164246120Sgahr   we need to deal with.  */
165246206Sgahrtypedef unsigned long bfd_vma;
166246120Sgahr
167246148Sgahr/* A generic signed type which is guaranteed to be big enough to hold any
168246120Sgahr   arithmetic types we need to deal with.  Can be assumed to be compatible
169246120Sgahr   with bfd_vma in the same way that signed and unsigned ints are compatible
170246120Sgahr   (as parameters, in assignment, etc).  */
171246120Sgahrtypedef long bfd_signed_vma;
172246120Sgahr
173246120Sgahrtypedef unsigned long symvalue;
174246120Sgahrtypedef unsigned long bfd_size_type;
175246206Sgahr
176246120Sgahr/* Print a bfd_vma x on stream s.  */
177246120Sgahr#define fprintf_vma(s,x) fprintf (s, "%08lx", x)
178246120Sgahr#define sprintf_vma(s,x) sprintf (s, "%08lx", x)
179246120Sgahr
180246120Sgahr#endif /* not BFD64  */
181246120Sgahr
182246120Sgahr/* A pointer to a position in a file.  */
183246206Sgahr/* FIXME:  This should be using off_t from <sys/types.h>.
184246120Sgahr   For now, try to avoid breaking stuff by not including <sys/types.h> here.
185246148Sgahr   This will break on systems with 64-bit file offsets (e.g. 4.4BSD).
186246120Sgahr   Probably the best long-term answer is to avoid using file_ptr AND off_t
187246148Sgahr   in this header file, and to handle this in the BFD implementation
188246148Sgahr   rather than in its interface.  */
189246120Sgahr/* typedef off_t	file_ptr; */
190246120Sgahrtypedef bfd_signed_vma file_ptr;
191246120Sgahrtypedef bfd_vma ufile_ptr;
192246120Sgahr
193246206Sgahrextern void bfd_sprintf_vma PARAMS ((bfd *, char *, bfd_vma));
194246120Sgahrextern void bfd_fprintf_vma PARAMS ((bfd *, PTR, bfd_vma));
195246120Sgahr
196246120Sgahr#define printf_vma(x) fprintf_vma(stdout,x)
197246148Sgahr#define bfd_printf_vma(abfd,x) bfd_fprintf_vma (abfd,stdout,x)
198246148Sgahr
199246148Sgahrtypedef unsigned int flagword;	/* 32 bits of flags */
200246148Sgahrtypedef unsigned char bfd_byte;
201246148Sgahr
202246148Sgahr/* File formats.  */
203246148Sgahr
204246148Sgahrtypedef enum bfd_format
205246148Sgahr{
206246148Sgahr  bfd_unknown = 0,	/* File format is unknown.  */
207246120Sgahr  bfd_object,		/* Linker/assember/compiler output.  */
208246120Sgahr  bfd_archive,		/* Object archive file.  */
209246120Sgahr  bfd_core,		/* Core dump.  */
210246120Sgahr  bfd_type_end		/* Marks the end; don't use it!  */
211246120Sgahr}
212246120Sgahrbfd_format;
213246206Sgahr
214246120Sgahr/* Values that may appear in the flags field of a BFD.  These also
215246148Sgahr   appear in the object_flags field of the bfd_target structure, where
216246120Sgahr   they indicate the set of flags used by that backend (not all flags
217246120Sgahr   are meaningful for all object file formats) (FIXME: at the moment,
218246120Sgahr   the object_flags values have mostly just been copied from backend
219246120Sgahr   to another, and are not necessarily correct).  */
220246148Sgahr
221246120Sgahr/* No flags.  */
222246120Sgahr#define BFD_NO_FLAGS   	0x00
223246120Sgahr
224246120Sgahr/* BFD contains relocation entries.  */
225246120Sgahr#define HAS_RELOC   	0x01
226246120Sgahr
227246120Sgahr/* BFD is directly executable.  */
228246148Sgahr#define EXEC_P      	0x02
229246120Sgahr
230246120Sgahr/* BFD has line number information (basically used for F_LNNO in a
231246120Sgahr   COFF header).  */
232246120Sgahr#define HAS_LINENO  	0x04
233246120Sgahr
234246120Sgahr/* BFD has debugging information.  */
235246120Sgahr#define HAS_DEBUG   	0x08
236246120Sgahr
237246120Sgahr/* BFD has symbols.  */
238246120Sgahr#define HAS_SYMS    	0x10
239246120Sgahr
240246120Sgahr/* BFD has local symbols (basically used for F_LSYMS in a COFF
241246120Sgahr   header).  */
242246120Sgahr#define HAS_LOCALS  	0x20
243246120Sgahr
244246120Sgahr/* BFD is a dynamic object.  */
245246120Sgahr#define DYNAMIC     	0x40
246246120Sgahr
247246120Sgahr/* Text section is write protected (if D_PAGED is not set, this is
248246120Sgahr   like an a.out NMAGIC file) (the linker sets this by default, but
249246120Sgahr   clears it for -r or -N).  */
250246120Sgahr#define WP_TEXT     	0x80
251246120Sgahr
252246206Sgahr/* BFD is dynamically paged (this is like an a.out ZMAGIC file) (the
253246120Sgahr   linker sets this by default, but clears it for -r or -n or -N).  */
254246148Sgahr#define D_PAGED     	0x100
255246120Sgahr
256246120Sgahr/* BFD is relaxable (this means that bfd_relax_section may be able to
257246206Sgahr   do something) (sometimes bfd_relax_section can do something even if
258246120Sgahr   this is not set).  */
259246206Sgahr#define BFD_IS_RELAXABLE 0x200
260246120Sgahr
261246120Sgahr/* This may be set before writing out a BFD to request using a
262246120Sgahr   traditional format.  For example, this is used to request that when
263   writing out an a.out object the symbols not be hashed to eliminate
264   duplicates.  */
265#define BFD_TRADITIONAL_FORMAT 0x400
266
267/* This flag indicates that the BFD contents are actually cached in
268   memory.  If this is set, iostream points to a bfd_in_memory struct.  */
269#define BFD_IN_MEMORY 0x800
270
271/* Symbols and relocation.  */
272
273/* A count of carsyms (canonical archive symbols).  */
274typedef unsigned long symindex;
275
276/* How to perform a relocation.  */
277typedef const struct reloc_howto_struct reloc_howto_type;
278
279#define BFD_NO_MORE_SYMBOLS ((symindex) ~0)
280
281/* General purpose part of a symbol X;
282   target specific parts are in libcoff.h, libaout.h, etc.  */
283
284#define bfd_get_section(x) ((x)->section)
285#define bfd_get_output_section(x) ((x)->section->output_section)
286#define bfd_set_section(x,y) ((x)->section) = (y)
287#define bfd_asymbol_base(x) ((x)->section->vma)
288#define bfd_asymbol_value(x) (bfd_asymbol_base(x) + (x)->value)
289#define bfd_asymbol_name(x) ((x)->name)
290/*Perhaps future: #define bfd_asymbol_bfd(x) ((x)->section->owner)*/
291#define bfd_asymbol_bfd(x) ((x)->the_bfd)
292#define bfd_asymbol_flavour(x) (bfd_asymbol_bfd(x)->xvec->flavour)
293
294/* A canonical archive symbol.  */
295/* This is a type pun with struct ranlib on purpose!  */
296typedef struct carsym
297{
298  char *name;
299  file_ptr file_offset;	/* Look here to find the file.  */
300}
301carsym;			/* To make these you call a carsymogen.  */
302
303/* Used in generating armaps (archive tables of contents).
304   Perhaps just a forward definition would do?  */
305struct orl 			/* Output ranlib.  */
306{
307  char **name;		/* Symbol name.  */
308  union
309  {
310    file_ptr pos;
311    bfd *abfd;
312  } u;			/* bfd* or file position.  */
313  int namidx;		/* Index into string table.  */
314};
315
316/* Linenumber stuff.  */
317typedef struct lineno_cache_entry
318{
319  unsigned int line_number;	/* Linenumber from start of function.  */
320  union
321  {
322    struct symbol_cache_entry *sym;	/* Function name.  */
323    bfd_vma offset;	    		/* Offset into section.  */
324  } u;
325}
326alent;
327
328/* Object and core file sections.  */
329
330#define	align_power(addr, align)	\
331  (((addr) + ((bfd_vma) 1 << (align)) - 1) & ((bfd_vma) -1 << (align)))
332
333typedef struct sec *sec_ptr;
334
335#define bfd_get_section_name(bfd, ptr) ((ptr)->name + 0)
336#define bfd_get_section_vma(bfd, ptr) ((ptr)->vma + 0)
337#define bfd_get_section_lma(bfd, ptr) ((ptr)->lma + 0)
338#define bfd_get_section_alignment(bfd, ptr) ((ptr)->alignment_power + 0)
339#define bfd_section_name(bfd, ptr) ((ptr)->name)
340#define bfd_section_size(bfd, ptr) (bfd_get_section_size_before_reloc(ptr))
341#define bfd_section_vma(bfd, ptr) ((ptr)->vma)
342#define bfd_section_lma(bfd, ptr) ((ptr)->lma)
343#define bfd_section_alignment(bfd, ptr) ((ptr)->alignment_power)
344#define bfd_get_section_flags(bfd, ptr) ((ptr)->flags + 0)
345#define bfd_get_section_userdata(bfd, ptr) ((ptr)->userdata)
346
347#define bfd_is_com_section(ptr) (((ptr)->flags & SEC_IS_COMMON) != 0)
348
349#define bfd_set_section_vma(bfd, ptr, val) (((ptr)->vma = (ptr)->lma = (val)), ((ptr)->user_set_vma = (boolean)true), true)
350#define bfd_set_section_alignment(bfd, ptr, val) (((ptr)->alignment_power = (val)),true)
351#define bfd_set_section_userdata(bfd, ptr, val) (((ptr)->userdata = (val)),true)
352
353typedef struct stat stat_type;
354
355typedef enum bfd_print_symbol
356{
357  bfd_print_symbol_name,
358  bfd_print_symbol_more,
359  bfd_print_symbol_all
360} bfd_print_symbol_type;
361
362/* Information about a symbol that nm needs.  */
363
364typedef struct _symbol_info
365{
366  symvalue value;
367  char type;
368  const char *name;            /* Symbol name.  */
369  unsigned char stab_type;     /* Stab type.  */
370  char stab_other;             /* Stab other.  */
371  short stab_desc;             /* Stab desc.  */
372  const char *stab_name;       /* String for stab type.  */
373} symbol_info;
374
375/* Get the name of a stabs type code.  */
376
377extern const char *bfd_get_stab_name PARAMS ((int));
378
379/* Hash table routines.  There is no way to free up a hash table.  */
380
381/* An element in the hash table.  Most uses will actually use a larger
382   structure, and an instance of this will be the first field.  */
383
384struct bfd_hash_entry
385{
386  /* Next entry for this hash code.  */
387  struct bfd_hash_entry *next;
388  /* String being hashed.  */
389  const char *string;
390  /* Hash code.  This is the full hash code, not the index into the
391     table.  */
392  unsigned long hash;
393};
394
395/* A hash table.  */
396
397struct bfd_hash_table
398{
399  /* The hash array.  */
400  struct bfd_hash_entry **table;
401  /* The number of slots in the hash table.  */
402  unsigned int size;
403  /* A function used to create new elements in the hash table.  The
404     first entry is itself a pointer to an element.  When this
405     function is first invoked, this pointer will be NULL.  However,
406     having the pointer permits a hierarchy of method functions to be
407     built each of which calls the function in the superclass.  Thus
408     each function should be written to allocate a new block of memory
409     only if the argument is NULL.  */
410  struct bfd_hash_entry *(*newfunc) PARAMS ((struct bfd_hash_entry *,
411					     struct bfd_hash_table *,
412					     const char *));
413   /* An objalloc for this hash table.  This is a struct objalloc *,
414     but we use PTR to avoid requiring the inclusion of objalloc.h.  */
415  PTR memory;
416};
417
418/* Initialize a hash table.  */
419extern boolean bfd_hash_table_init
420  PARAMS ((struct bfd_hash_table *,
421	   struct bfd_hash_entry *(*) (struct bfd_hash_entry *,
422				       struct bfd_hash_table *,
423				       const char *)));
424
425/* Initialize a hash table specifying a size.  */
426extern boolean bfd_hash_table_init_n
427  PARAMS ((struct bfd_hash_table *,
428	   struct bfd_hash_entry *(*) (struct bfd_hash_entry *,
429				       struct bfd_hash_table *,
430				       const char *),
431	   unsigned int size));
432
433/* Free up a hash table.  */
434extern void bfd_hash_table_free PARAMS ((struct bfd_hash_table *));
435
436/* Look up a string in a hash table.  If CREATE is true, a new entry
437   will be created for this string if one does not already exist.  The
438   COPY argument must be true if this routine should copy the string
439   into newly allocated memory when adding an entry.  */
440extern struct bfd_hash_entry *bfd_hash_lookup
441  PARAMS ((struct bfd_hash_table *, const char *, boolean create,
442	   boolean copy));
443
444/* Replace an entry in a hash table.  */
445extern void bfd_hash_replace
446  PARAMS ((struct bfd_hash_table *, struct bfd_hash_entry *old,
447	   struct bfd_hash_entry *nw));
448
449/* Base method for creating a hash table entry.  */
450extern struct bfd_hash_entry *bfd_hash_newfunc
451  PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *,
452	   const char *));
453
454/* Grab some space for a hash table entry.  */
455extern PTR bfd_hash_allocate PARAMS ((struct bfd_hash_table *,
456				      unsigned int));
457
458/* Traverse a hash table in a random order, calling a function on each
459   element.  If the function returns false, the traversal stops.  The
460   INFO argument is passed to the function.  */
461extern void bfd_hash_traverse PARAMS ((struct bfd_hash_table *,
462				       boolean (*) (struct bfd_hash_entry *,
463						    PTR),
464				       PTR info));
465
466#define COFF_SWAP_TABLE (PTR) &bfd_coff_std_swap_table
467
468/* User program access to BFD facilities.  */
469
470/* Direct I/O routines, for programs which know more about the object
471   file than BFD does.  Use higher level routines if possible.  */
472
473extern bfd_size_type bfd_bread PARAMS ((PTR, bfd_size_type, bfd *));
474extern bfd_size_type bfd_bwrite PARAMS ((const PTR, bfd_size_type, bfd *));
475extern int bfd_seek PARAMS ((bfd *, file_ptr, int));
476extern ufile_ptr bfd_tell PARAMS ((bfd *));
477extern int bfd_flush PARAMS ((bfd *));
478extern int bfd_stat PARAMS ((bfd *, struct stat *));
479
480/* Deprecated old routines.  */
481#if __GNUC__
482#define bfd_read(BUF, ELTSIZE, NITEMS, ABFD)				\
483  (warn_deprecated ("bfd_read", __FILE__, __LINE__, __FUNCTION__),	\
484   bfd_bread ((BUF), (ELTSIZE) * (NITEMS), (ABFD)))
485#define bfd_write(BUF, ELTSIZE, NITEMS, ABFD)				\
486  (warn_deprecated ("bfd_write", __FILE__, __LINE__, __FUNCTION__),	\
487   bfd_bwrite ((BUF), (ELTSIZE) * (NITEMS), (ABFD)))
488#else
489#define bfd_read(BUF, ELTSIZE, NITEMS, ABFD)				\
490  (warn_deprecated ("bfd_read", (const char *) 0, 0, (const char *) 0), \
491   bfd_bread ((BUF), (ELTSIZE) * (NITEMS), (ABFD)))
492#define bfd_write(BUF, ELTSIZE, NITEMS, ABFD)				\
493  (warn_deprecated ("bfd_write", (const char *) 0, 0, (const char *) 0),\
494   bfd_bwrite ((BUF), (ELTSIZE) * (NITEMS), (ABFD)))
495#endif
496extern void warn_deprecated
497  PARAMS ((const char *, const char *, int, const char *));
498
499/* Cast from const char * to char * so that caller can assign to
500   a char * without a warning.  */
501#define bfd_get_filename(abfd) ((char *) (abfd)->filename)
502#define bfd_get_cacheable(abfd) ((abfd)->cacheable)
503#define bfd_get_format(abfd) ((abfd)->format)
504#define bfd_get_target(abfd) ((abfd)->xvec->name)
505#define bfd_get_flavour(abfd) ((abfd)->xvec->flavour)
506#define bfd_family_coff(abfd) \
507  (bfd_get_flavour (abfd) == bfd_target_coff_flavour || \
508   bfd_get_flavour (abfd) == bfd_target_xcoff_flavour)
509#define bfd_big_endian(abfd) ((abfd)->xvec->byteorder == BFD_ENDIAN_BIG)
510#define bfd_little_endian(abfd) ((abfd)->xvec->byteorder == BFD_ENDIAN_LITTLE)
511#define bfd_header_big_endian(abfd) \
512  ((abfd)->xvec->header_byteorder == BFD_ENDIAN_BIG)
513#define bfd_header_little_endian(abfd) \
514  ((abfd)->xvec->header_byteorder == BFD_ENDIAN_LITTLE)
515#define bfd_get_file_flags(abfd) ((abfd)->flags)
516#define bfd_applicable_file_flags(abfd) ((abfd)->xvec->object_flags)
517#define bfd_applicable_section_flags(abfd) ((abfd)->xvec->section_flags)
518#define bfd_my_archive(abfd) ((abfd)->my_archive)
519#define bfd_has_map(abfd) ((abfd)->has_armap)
520
521#define bfd_valid_reloc_types(abfd) ((abfd)->xvec->valid_reloc_types)
522#define bfd_usrdata(abfd) ((abfd)->usrdata)
523
524#define bfd_get_start_address(abfd) ((abfd)->start_address)
525#define bfd_get_symcount(abfd) ((abfd)->symcount)
526#define bfd_get_outsymbols(abfd) ((abfd)->outsymbols)
527#define bfd_count_sections(abfd) ((abfd)->section_count)
528
529#define bfd_get_dynamic_symcount(abfd) ((abfd)->dynsymcount)
530
531#define bfd_get_symbol_leading_char(abfd) ((abfd)->xvec->symbol_leading_char)
532
533#define bfd_set_cacheable(abfd,bool) (((abfd)->cacheable = (boolean) (bool)), true)
534
535extern boolean bfd_cache_close PARAMS ((bfd *abfd));
536/* NB: This declaration should match the autogenerated one in libbfd.h.  */
537
538extern boolean bfd_record_phdr
539  PARAMS ((bfd *, unsigned long, boolean, flagword, boolean, bfd_vma,
540	   boolean, boolean, unsigned int, struct sec **));
541
542/* Byte swapping routines.  */
543
544bfd_vma		bfd_getb64	   PARAMS ((const unsigned char *));
545bfd_vma 	bfd_getl64	   PARAMS ((const unsigned char *));
546bfd_signed_vma	bfd_getb_signed_64 PARAMS ((const unsigned char *));
547bfd_signed_vma	bfd_getl_signed_64 PARAMS ((const unsigned char *));
548bfd_vma		bfd_getb32	   PARAMS ((const unsigned char *));
549bfd_vma		bfd_getl32	   PARAMS ((const unsigned char *));
550bfd_signed_vma	bfd_getb_signed_32 PARAMS ((const unsigned char *));
551bfd_signed_vma	bfd_getl_signed_32 PARAMS ((const unsigned char *));
552bfd_vma		bfd_getb16	   PARAMS ((const unsigned char *));
553bfd_vma		bfd_getl16	   PARAMS ((const unsigned char *));
554bfd_signed_vma	bfd_getb_signed_16 PARAMS ((const unsigned char *));
555bfd_signed_vma	bfd_getl_signed_16 PARAMS ((const unsigned char *));
556void		bfd_putb64	   PARAMS ((bfd_vma, unsigned char *));
557void		bfd_putl64	   PARAMS ((bfd_vma, unsigned char *));
558void		bfd_putb32	   PARAMS ((bfd_vma, unsigned char *));
559void		bfd_putl32	   PARAMS ((bfd_vma, unsigned char *));
560void		bfd_putb16	   PARAMS ((bfd_vma, unsigned char *));
561void		bfd_putl16	   PARAMS ((bfd_vma, unsigned char *));
562
563/* Byte swapping routines which take size and endiannes as arguments.  */
564
565bfd_vma         bfd_get_bits       PARAMS ((bfd_byte *, int, boolean));
566void            bfd_put_bits       PARAMS ((bfd_vma, bfd_byte *, int, boolean));
567
568/* Externally visible ECOFF routines.  */
569
570#if defined(__STDC__) || defined(ALMOST_STDC)
571struct ecoff_debug_info;
572struct ecoff_debug_swap;
573struct ecoff_extr;
574struct symbol_cache_entry;
575struct bfd_link_info;
576struct bfd_link_hash_entry;
577struct bfd_elf_version_tree;
578#endif
579extern bfd_vma bfd_ecoff_get_gp_value PARAMS ((bfd * abfd));
580extern boolean bfd_ecoff_set_gp_value PARAMS ((bfd *abfd, bfd_vma gp_value));
581extern boolean bfd_ecoff_set_regmasks
582  PARAMS ((bfd *abfd, unsigned long gprmask, unsigned long fprmask,
583	   unsigned long *cprmask));
584extern PTR bfd_ecoff_debug_init
585  PARAMS ((bfd *output_bfd, struct ecoff_debug_info *output_debug,
586	   const struct ecoff_debug_swap *output_swap,
587	   struct bfd_link_info *));
588extern void bfd_ecoff_debug_free
589  PARAMS ((PTR handle, bfd *output_bfd, struct ecoff_debug_info *output_debug,
590	   const struct ecoff_debug_swap *output_swap,
591	   struct bfd_link_info *));
592extern boolean bfd_ecoff_debug_accumulate
593  PARAMS ((PTR handle, bfd *output_bfd, struct ecoff_debug_info *output_debug,
594	   const struct ecoff_debug_swap *output_swap,
595	   bfd *input_bfd, struct ecoff_debug_info *input_debug,
596	   const struct ecoff_debug_swap *input_swap,
597	   struct bfd_link_info *));
598extern boolean bfd_ecoff_debug_accumulate_other
599  PARAMS ((PTR handle, bfd *output_bfd, struct ecoff_debug_info *output_debug,
600	   const struct ecoff_debug_swap *output_swap, bfd *input_bfd,
601	   struct bfd_link_info *));
602extern boolean bfd_ecoff_debug_externals
603  PARAMS ((bfd *abfd, struct ecoff_debug_info *debug,
604	   const struct ecoff_debug_swap *swap,
605	   boolean relocateable,
606	   boolean (*get_extr) (struct symbol_cache_entry *,
607				struct ecoff_extr *),
608	   void (*set_index) (struct symbol_cache_entry *,
609			      bfd_size_type)));
610extern boolean bfd_ecoff_debug_one_external
611  PARAMS ((bfd *abfd, struct ecoff_debug_info *debug,
612	   const struct ecoff_debug_swap *swap,
613	   const char *name, struct ecoff_extr *esym));
614extern bfd_size_type bfd_ecoff_debug_size
615  PARAMS ((bfd *abfd, struct ecoff_debug_info *debug,
616	   const struct ecoff_debug_swap *swap));
617extern boolean bfd_ecoff_write_debug
618  PARAMS ((bfd *abfd, struct ecoff_debug_info *debug,
619	   const struct ecoff_debug_swap *swap, file_ptr where));
620extern boolean bfd_ecoff_write_accumulated_debug
621  PARAMS ((PTR handle, bfd *abfd, struct ecoff_debug_info *debug,
622	   const struct ecoff_debug_swap *swap,
623	   struct bfd_link_info *info, file_ptr where));
624extern boolean bfd_mips_ecoff_create_embedded_relocs
625  PARAMS ((bfd *, struct bfd_link_info *, struct sec *, struct sec *,
626	   char **));
627
628/* Externally visible ELF routines.  */
629
630struct bfd_link_needed_list
631{
632  struct bfd_link_needed_list *next;
633  bfd *by;
634  const char *name;
635};
636
637extern boolean bfd_elf32_record_link_assignment
638  PARAMS ((bfd *, struct bfd_link_info *, const char *, boolean));
639extern boolean bfd_elf64_record_link_assignment
640  PARAMS ((bfd *, struct bfd_link_info *, const char *, boolean));
641extern struct bfd_link_needed_list *bfd_elf_get_needed_list
642  PARAMS ((bfd *, struct bfd_link_info *));
643extern boolean bfd_elf_get_bfd_needed_list
644  PARAMS ((bfd *, struct bfd_link_needed_list **));
645extern boolean bfd_elf32_size_dynamic_sections
646  PARAMS ((bfd *, const char *, const char *, const char *,
647	   const char * const *, struct bfd_link_info *, struct sec **,
648	   struct bfd_elf_version_tree *));
649extern boolean bfd_elf64_size_dynamic_sections
650  PARAMS ((bfd *, const char *, const char *, const char *,
651	   const char * const *, struct bfd_link_info *, struct sec **,
652	   struct bfd_elf_version_tree *));
653extern void bfd_elf_set_dt_needed_name PARAMS ((bfd *, const char *));
654extern void bfd_elf_set_dt_needed_soname PARAMS ((bfd *, const char *));
655extern const char *bfd_elf_get_dt_soname PARAMS ((bfd *));
656extern struct bfd_link_needed_list *bfd_elf_get_runpath_list
657  PARAMS ((bfd *, struct bfd_link_info *));
658extern boolean bfd_elf32_discard_info
659  PARAMS ((bfd *, struct bfd_link_info *));
660extern boolean bfd_elf64_discard_info
661  PARAMS ((bfd *, struct bfd_link_info *));
662
663/* Return an upper bound on the number of bytes required to store a
664   copy of ABFD's program header table entries.  Return -1 if an error
665   occurs; bfd_get_error will return an appropriate code.  */
666extern long bfd_get_elf_phdr_upper_bound PARAMS ((bfd *abfd));
667
668/* Copy ABFD's program header table entries to *PHDRS.  The entries
669   will be stored as an array of Elf_Internal_Phdr structures, as
670   defined in include/elf/internal.h.  To find out how large the
671   buffer needs to be, call bfd_get_elf_phdr_upper_bound.
672
673   Return the number of program header table entries read, or -1 if an
674   error occurs; bfd_get_error will return an appropriate code.  */
675extern int bfd_get_elf_phdrs PARAMS ((bfd *abfd, void *phdrs));
676
677/* Return the arch_size field of an elf bfd, or -1 if not elf.  */
678extern int bfd_get_arch_size PARAMS ((bfd *));
679
680/* Return true if address "naturally" sign extends, or -1 if not elf.  */
681extern int bfd_get_sign_extend_vma PARAMS ((bfd *));
682
683extern boolean bfd_m68k_elf32_create_embedded_relocs
684  PARAMS ((bfd *, struct bfd_link_info *, struct sec *, struct sec *,
685	   char **));
686extern boolean bfd_mips_elf32_create_embedded_relocs
687  PARAMS ((bfd *, struct bfd_link_info *, struct sec *, struct sec *,
688	   char **));
689
690/* SunOS shared library support routines for the linker.  */
691
692extern struct bfd_link_needed_list *bfd_sunos_get_needed_list
693  PARAMS ((bfd *, struct bfd_link_info *));
694extern boolean bfd_sunos_record_link_assignment
695  PARAMS ((bfd *, struct bfd_link_info *, const char *));
696extern boolean bfd_sunos_size_dynamic_sections
697  PARAMS ((bfd *, struct bfd_link_info *, struct sec **, struct sec **,
698	   struct sec **));
699
700/* Linux shared library support routines for the linker.  */
701
702extern boolean bfd_i386linux_size_dynamic_sections
703  PARAMS ((bfd *, struct bfd_link_info *));
704extern boolean bfd_m68klinux_size_dynamic_sections
705  PARAMS ((bfd *, struct bfd_link_info *));
706extern boolean bfd_sparclinux_size_dynamic_sections
707  PARAMS ((bfd *, struct bfd_link_info *));
708
709/* mmap hacks */
710
711struct _bfd_window_internal;
712typedef struct _bfd_window_internal bfd_window_internal;
713
714typedef struct _bfd_window
715{
716  /* What the user asked for.  */
717  PTR data;
718  bfd_size_type size;
719  /* The actual window used by BFD.  Small user-requested read-only
720     regions sharing a page may share a single window into the object
721     file.  Read-write versions shouldn't until I've fixed things to
722     keep track of which portions have been claimed by the
723     application; don't want to give the same region back when the
724     application wants two writable copies!  */
725  struct _bfd_window_internal *i;
726}
727bfd_window;
728
729extern void bfd_init_window PARAMS ((bfd_window *));
730extern void bfd_free_window PARAMS ((bfd_window *));
731extern boolean bfd_get_file_window
732  PARAMS ((bfd *, file_ptr, bfd_size_type, bfd_window *, boolean));
733
734/* XCOFF support routines for the linker.  */
735
736extern boolean bfd_xcoff_link_record_set
737  PARAMS ((bfd *, struct bfd_link_info *, struct bfd_link_hash_entry *,
738	   bfd_size_type));
739extern boolean bfd_xcoff_import_symbol
740  PARAMS ((bfd *, struct bfd_link_info *, struct bfd_link_hash_entry *,
741	   bfd_vma, const char *, const char *, const char *, unsigned int));
742extern boolean bfd_xcoff_export_symbol
743  PARAMS ((bfd *, struct bfd_link_info *, struct bfd_link_hash_entry *));
744extern boolean bfd_xcoff_link_count_reloc
745  PARAMS ((bfd *, struct bfd_link_info *, const char *));
746extern boolean bfd_xcoff_record_link_assignment
747  PARAMS ((bfd *, struct bfd_link_info *, const char *));
748extern boolean bfd_xcoff_size_dynamic_sections
749  PARAMS ((bfd *, struct bfd_link_info *, const char *, const char *,
750	   unsigned long, unsigned long, unsigned long, boolean,
751	   int, boolean, boolean, struct sec **, boolean));
752extern boolean bfd_xcoff_link_generate_rtinit
753  PARAMS ((bfd *, const char *, const char *, boolean));
754
755/* XCOFF support routines for ar.  */
756extern boolean bfd_xcoff_ar_archive_set_magic PARAMS ((bfd *, char *));
757
758/* Externally visible COFF routines.  */
759
760#if defined(__STDC__) || defined(ALMOST_STDC)
761struct internal_syment;
762union internal_auxent;
763#endif
764
765extern boolean bfd_coff_get_syment
766  PARAMS ((bfd *, struct symbol_cache_entry *, struct internal_syment *));
767
768extern boolean bfd_coff_get_auxent
769  PARAMS ((bfd *, struct symbol_cache_entry *, int, union internal_auxent *));
770
771extern boolean bfd_coff_set_symbol_class
772  PARAMS ((bfd *, struct symbol_cache_entry *, unsigned int));
773
774extern boolean bfd_m68k_coff_create_embedded_relocs
775  PARAMS ((bfd *, struct bfd_link_info *, struct sec *, struct sec *,
776	   char **));
777
778/* ARM Interworking support.  Called from linker.  */
779extern boolean bfd_arm_allocate_interworking_sections
780  PARAMS ((struct bfd_link_info *));
781
782extern boolean bfd_arm_process_before_allocation
783  PARAMS ((bfd *, struct bfd_link_info *, int));
784
785extern boolean bfd_arm_get_bfd_for_interworking
786  PARAMS ((bfd *, struct bfd_link_info *));
787
788/* PE ARM Interworking support.  Called from linker.  */
789extern boolean bfd_arm_pe_allocate_interworking_sections
790  PARAMS ((struct bfd_link_info *));
791
792extern boolean bfd_arm_pe_process_before_allocation
793  PARAMS ((bfd *, struct bfd_link_info *, int));
794
795extern boolean bfd_arm_pe_get_bfd_for_interworking
796  PARAMS ((bfd *, struct bfd_link_info *));
797
798/* ELF ARM Interworking support.  Called from linker.  */
799extern boolean bfd_elf32_arm_allocate_interworking_sections
800  PARAMS ((struct bfd_link_info *));
801
802extern boolean bfd_elf32_arm_process_before_allocation
803  PARAMS ((bfd *, struct bfd_link_info *, int));
804
805extern boolean bfd_elf32_arm_get_bfd_for_interworking
806  PARAMS ((bfd *, struct bfd_link_info *));
807
808extern boolean bfd_elf32_arm_add_glue_sections_to_bfd
809  PARAMS ((bfd *, struct bfd_link_info *));
810
811/* TI COFF load page support.  */
812extern void bfd_ticoff_set_section_load_page
813  PARAMS ((struct sec *, int));
814
815extern int bfd_ticoff_get_section_load_page
816  PARAMS ((struct sec *));
817
818