1/* Main header file for the bfd library -- portable access to object files.
2
3   Copyright (C) 1990-2017 Free Software Foundation, Inc.
4
5   Contributed by Cygnus Support.
6
7   This file is part of BFD, the Binary File Descriptor library.
8
9   This program is free software; you can redistribute it and/or modify
10   it under the terms of the GNU General Public License as published by
11   the Free Software Foundation; either version 3 of the License, or
12   (at your option) any later version.
13
14   This program is distributed in the hope that it will be useful,
15   but WITHOUT ANY WARRANTY; without even the implied warranty of
16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   GNU General Public License for more details.
18
19   You should have received a copy of the GNU General Public License
20   along with this program; if not, write to the Free Software
21   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
22
23#ifndef __BFD_H_SEEN__
24#define __BFD_H_SEEN__
25
26/* PR 14072: Ensure that config.h is included first.  */
27#if !defined PACKAGE && !defined PACKAGE_VERSION
28#error config.h must be included before this header
29#endif
30
31#ifdef __cplusplus
32extern "C" {
33#endif
34
35#include "ansidecl.h"
36#include "symcat.h"
37#include <stdarg.h>
38#include <sys/stat.h>
39
40#if defined (__STDC__) || defined (ALMOST_STDC) || defined (HAVE_STRINGIZE)
41#ifndef SABER
42/* This hack is to avoid a problem with some strict ANSI C preprocessors.
43   The problem is, "32_" is not a valid preprocessing token, and we don't
44   want extra underscores (e.g., "nlm_32_").  The XCONCAT2 macro will
45   cause the inner CONCAT2 macros to be evaluated first, producing
46   still-valid pp-tokens.  Then the final concatenation can be done.  */
47#undef CONCAT4
48#define CONCAT4(a,b,c,d) XCONCAT2(CONCAT2(a,b),CONCAT2(c,d))
49#endif
50#endif
51
52/* This is a utility macro to handle the situation where the code
53   wants to place a constant string into the code, followed by a
54   comma and then the length of the string.  Doing this by hand
55   is error prone, so using this macro is safer.  */
56#define STRING_COMMA_LEN(STR) (STR), (sizeof (STR) - 1)
57/* Unfortunately it is not possible to use the STRING_COMMA_LEN macro
58   to create the arguments to another macro, since the preprocessor
59   will mis-count the number of arguments to the outer macro (by not
60   evaluating STRING_COMMA_LEN and so missing the comma).  This is a
61   problem for example when trying to use STRING_COMMA_LEN to build
62   the arguments to the strncmp() macro.  Hence this alternative
63   definition of strncmp is provided here.
64
65   Note - these macros do NOT work if STR2 is not a constant string.  */
66#define CONST_STRNEQ(STR1,STR2) (strncmp ((STR1), (STR2), sizeof (STR2) - 1) == 0)
67  /* strcpy() can have a similar problem, but since we know we are
68     copying a constant string, we can use memcpy which will be faster
69     since there is no need to check for a NUL byte inside STR.  We
70     can also save time if we do not need to copy the terminating NUL.  */
71#define LITMEMCPY(DEST,STR2) memcpy ((DEST), (STR2), sizeof (STR2) - 1)
72#define LITSTRCPY(DEST,STR2) memcpy ((DEST), (STR2), sizeof (STR2))
73
74
75#define BFD_SUPPORTS_PLUGINS @supports_plugins@
76
77/* The word size used by BFD on the host.  This may be 64 with a 32
78   bit target if the host is 64 bit, or if other 64 bit targets have
79   been selected with --enable-targets, or if --enable-64-bit-bfd.  */
80#define BFD_ARCH_SIZE @wordsize@
81
82/* The word size of the default bfd target.  */
83#define BFD_DEFAULT_TARGET_SIZE @bfd_default_target_size@
84
85#define BFD_HOST_64BIT_LONG @BFD_HOST_64BIT_LONG@
86#define BFD_HOST_64BIT_LONG_LONG @BFD_HOST_64BIT_LONG_LONG@
87#if @BFD_HOST_64_BIT_DEFINED@
88#define BFD_HOST_64_BIT @BFD_HOST_64_BIT@
89#define BFD_HOST_U_64_BIT @BFD_HOST_U_64_BIT@
90typedef BFD_HOST_64_BIT bfd_int64_t;
91typedef BFD_HOST_U_64_BIT bfd_uint64_t;
92#endif
93
94#if BFD_ARCH_SIZE >= 64
95#define BFD64
96#endif
97
98#ifndef INLINE
99#if __GNUC__ >= 2
100#define INLINE __inline__
101#else
102#define INLINE
103#endif
104#endif
105
106/* Declaring a type wide enough to hold a host long and a host pointer.  */
107#define BFD_HOSTPTR_T	@BFD_HOSTPTR_T@
108typedef BFD_HOSTPTR_T bfd_hostptr_t;
109
110/* Forward declaration.  */
111typedef struct bfd bfd;
112
113/* Boolean type used in bfd.  Too many systems define their own
114   versions of "boolean" for us to safely typedef a "boolean" of
115   our own.  Using an enum for "bfd_boolean" has its own set of
116   problems, with strange looking casts required to avoid warnings
117   on some older compilers.  Thus we just use an int.
118
119   General rule: Functions which are bfd_boolean return TRUE on
120   success and FALSE on failure (unless they're a predicate).  */
121
122typedef int bfd_boolean;
123#undef FALSE
124#undef TRUE
125#define FALSE 0
126#define TRUE 1
127
128#ifdef BFD64
129
130#ifndef BFD_HOST_64_BIT
131 #error No 64 bit integer type available
132#endif /* ! defined (BFD_HOST_64_BIT) */
133
134typedef BFD_HOST_U_64_BIT bfd_vma;
135typedef BFD_HOST_64_BIT bfd_signed_vma;
136typedef BFD_HOST_U_64_BIT bfd_size_type;
137typedef BFD_HOST_U_64_BIT symvalue;
138
139#if BFD_HOST_64BIT_LONG
140#define BFD_VMA_FMT "l"
141#elif defined (__MSVCRT__)
142#define BFD_VMA_FMT "I64"
143#else
144#define BFD_VMA_FMT "ll"
145#endif
146
147#ifndef fprintf_vma
148#define sprintf_vma(s,x) sprintf (s, "%016" BFD_VMA_FMT "x", x)
149#define fprintf_vma(f,x) fprintf (f, "%016" BFD_VMA_FMT "x", x)
150#endif
151
152#else /* not BFD64  */
153
154/* Represent a target address.  Also used as a generic unsigned type
155   which is guaranteed to be big enough to hold any arithmetic types
156   we need to deal with.  */
157typedef unsigned long bfd_vma;
158
159/* A generic signed type which is guaranteed to be big enough to hold any
160   arithmetic types we need to deal with.  Can be assumed to be compatible
161   with bfd_vma in the same way that signed and unsigned ints are compatible
162   (as parameters, in assignment, etc).  */
163typedef long bfd_signed_vma;
164
165typedef unsigned long symvalue;
166typedef unsigned long bfd_size_type;
167
168/* Print a bfd_vma x on stream s.  */
169#define BFD_VMA_FMT "l"
170#define fprintf_vma(s,x) fprintf (s, "%08" BFD_VMA_FMT "x", x)
171#define sprintf_vma(s,x) sprintf (s, "%08" BFD_VMA_FMT "x", x)
172
173#endif /* not BFD64  */
174
175#define HALF_BFD_SIZE_TYPE \
176  (((bfd_size_type) 1) << (8 * sizeof (bfd_size_type) / 2))
177
178#ifndef BFD_HOST_64_BIT
179/* Fall back on a 32 bit type.  The idea is to make these types always
180   available for function return types, but in the case that
181   BFD_HOST_64_BIT is undefined such a function should abort or
182   otherwise signal an error.  */
183typedef bfd_signed_vma bfd_int64_t;
184typedef bfd_vma bfd_uint64_t;
185#endif
186
187/* An offset into a file.  BFD always uses the largest possible offset
188   based on the build time availability of fseek, fseeko, or fseeko64.  */
189typedef @bfd_file_ptr@ file_ptr;
190typedef unsigned @bfd_file_ptr@ ufile_ptr;
191
192extern void bfd_sprintf_vma (bfd *, char *, bfd_vma);
193extern void bfd_fprintf_vma (bfd *, void *, bfd_vma);
194
195#define printf_vma(x) fprintf_vma(stdout,x)
196#define bfd_printf_vma(abfd,x) bfd_fprintf_vma (abfd,stdout,x)
197
198typedef unsigned int flagword;	/* 32 bits of flags */
199typedef unsigned char bfd_byte;
200
201/* File formats.  */
202
203typedef enum bfd_format
204{
205  bfd_unknown = 0,	/* File format is unknown.  */
206  bfd_object,		/* Linker/assembler/compiler output.  */
207  bfd_archive,		/* Object archive file.  */
208  bfd_core,		/* Core dump.  */
209  bfd_type_end		/* Marks the end; don't use it!  */
210}
211bfd_format;
212
213/* Symbols and relocation.  */
214
215/* A count of carsyms (canonical archive symbols).  */
216typedef unsigned long symindex;
217
218/* How to perform a relocation.  */
219typedef const struct reloc_howto_struct reloc_howto_type;
220
221#define BFD_NO_MORE_SYMBOLS ((symindex) ~0)
222
223/* General purpose part of a symbol X;
224   target specific parts are in libcoff.h, libaout.h, etc.  */
225
226#define bfd_get_section(x) ((x)->section)
227#define bfd_get_output_section(x) ((x)->section->output_section)
228#define bfd_set_section(x,y) ((x)->section) = (y)
229#define bfd_asymbol_base(x) ((x)->section->vma)
230#define bfd_asymbol_value(x) (bfd_asymbol_base(x) + (x)->value)
231#define bfd_asymbol_name(x) ((x)->name)
232/*Perhaps future: #define bfd_asymbol_bfd(x) ((x)->section->owner)*/
233#define bfd_asymbol_bfd(x) ((x)->the_bfd)
234#define bfd_asymbol_flavour(x)			\
235  (((x)->flags & BSF_SYNTHETIC) != 0		\
236   ? bfd_target_unknown_flavour			\
237   : bfd_asymbol_bfd (x)->xvec->flavour)
238
239/* A canonical archive symbol.  */
240/* This is a type pun with struct ranlib on purpose!  */
241typedef struct carsym
242{
243  char *name;
244  file_ptr file_offset;	/* Look here to find the file.  */
245}
246carsym;			/* To make these you call a carsymogen.  */
247
248/* Used in generating armaps (archive tables of contents).
249   Perhaps just a forward definition would do?  */
250struct orl 			/* Output ranlib.  */
251{
252  char **name;		/* Symbol name.  */
253  union
254  {
255    file_ptr pos;
256    bfd *abfd;
257  } u;			/* bfd* or file position.  */
258  int namidx;		/* Index into string table.  */
259};
260
261/* Linenumber stuff.  */
262typedef struct lineno_cache_entry
263{
264  unsigned int line_number;	/* Linenumber from start of function.  */
265  union
266  {
267    struct bfd_symbol *sym;	/* Function name.  */
268    bfd_vma offset;	    		/* Offset into section.  */
269  } u;
270}
271alent;
272
273/* Object and core file sections.  */
274typedef struct bfd_section *sec_ptr;
275
276#define	align_power(addr, align)	\
277  (((addr) + ((bfd_vma) 1 << (align)) - 1) & (-((bfd_vma) 1 << (align))))
278
279/* Align an address upward to a boundary, expressed as a number of bytes.
280   E.g. align to an 8-byte boundary with argument of 8.  Take care never
281   to wrap around if the address is within boundary-1 of the end of the
282   address space.  */
283#define BFD_ALIGN(this, boundary)					  \
284  ((((bfd_vma) (this) + (boundary) - 1) >= (bfd_vma) (this))		  \
285   ? (((bfd_vma) (this) + ((boundary) - 1)) & ~ (bfd_vma) ((boundary)-1)) \
286   : ~ (bfd_vma) 0)
287
288#define bfd_get_section_name(bfd, ptr) ((void) bfd, (ptr)->name)
289#define bfd_get_section_vma(bfd, ptr) ((void) bfd, (ptr)->vma)
290#define bfd_get_section_lma(bfd, ptr) ((void) bfd, (ptr)->lma)
291#define bfd_get_section_alignment(bfd, ptr) ((void) bfd, \
292					     (ptr)->alignment_power)
293#define bfd_section_name(bfd, ptr) ((ptr)->name)
294#define bfd_section_size(bfd, ptr) ((ptr)->size)
295#define bfd_get_section_size(ptr) ((ptr)->size)
296#define bfd_section_vma(bfd, ptr) ((ptr)->vma)
297#define bfd_section_lma(bfd, ptr) ((ptr)->lma)
298#define bfd_section_alignment(bfd, ptr) ((ptr)->alignment_power)
299#define bfd_get_section_flags(bfd, ptr) ((void) bfd, (ptr)->flags)
300#define bfd_get_section_userdata(bfd, ptr) ((void) bfd, (ptr)->userdata)
301
302#define bfd_is_com_section(ptr) (((ptr)->flags & SEC_IS_COMMON) != 0)
303
304#define bfd_get_section_limit_octets(bfd, sec)			\
305  ((bfd)->direction != write_direction && (sec)->rawsize != 0	\
306   ? (sec)->rawsize : (sec)->size)
307
308/* Find the address one past the end of SEC.  */
309#define bfd_get_section_limit(bfd, sec) \
310  (bfd_get_section_limit_octets(bfd, sec) / bfd_octets_per_byte (bfd))
311
312/* Return TRUE if input section SEC has been discarded.  */
313#define discarded_section(sec)				\
314  (!bfd_is_abs_section (sec)					\
315   && bfd_is_abs_section ((sec)->output_section)		\
316   && (sec)->sec_info_type != SEC_INFO_TYPE_MERGE		\
317   && (sec)->sec_info_type != SEC_INFO_TYPE_JUST_SYMS)
318
319typedef enum bfd_print_symbol
320{
321  bfd_print_symbol_name,
322  bfd_print_symbol_more,
323  bfd_print_symbol_all
324} bfd_print_symbol_type;
325
326/* Information about a symbol that nm needs.  */
327
328typedef struct _symbol_info
329{
330  symvalue value;
331  char type;
332  const char *name;            /* Symbol name.  */
333  unsigned char stab_type;     /* Stab type.  */
334  char stab_other;             /* Stab other.  */
335  short stab_desc;             /* Stab desc.  */
336  const char *stab_name;       /* String for stab type.  */
337} symbol_info;
338
339/* Get the name of a stabs type code.  */
340
341extern const char *bfd_get_stab_name (int);
342
343/* Hash table routines.  There is no way to free up a hash table.  */
344
345/* An element in the hash table.  Most uses will actually use a larger
346   structure, and an instance of this will be the first field.  */
347
348struct bfd_hash_entry
349{
350  /* Next entry for this hash code.  */
351  struct bfd_hash_entry *next;
352  /* String being hashed.  */
353  const char *string;
354  /* Hash code.  This is the full hash code, not the index into the
355     table.  */
356  unsigned long hash;
357};
358
359/* A hash table.  */
360
361struct bfd_hash_table
362{
363  /* The hash array.  */
364  struct bfd_hash_entry **table;
365  /* A function used to create new elements in the hash table.  The
366     first entry is itself a pointer to an element.  When this
367     function is first invoked, this pointer will be NULL.  However,
368     having the pointer permits a hierarchy of method functions to be
369     built each of which calls the function in the superclass.  Thus
370     each function should be written to allocate a new block of memory
371     only if the argument is NULL.  */
372  struct bfd_hash_entry *(*newfunc)
373    (struct bfd_hash_entry *, struct bfd_hash_table *, const char *);
374   /* An objalloc for this hash table.  This is a struct objalloc *,
375     but we use void * to avoid requiring the inclusion of objalloc.h.  */
376  void *memory;
377  /* The number of slots in the hash table.  */
378  unsigned int size;
379  /* The number of entries in the hash table.  */
380  unsigned int count;
381  /* The size of elements.  */
382  unsigned int entsize;
383  /* If non-zero, don't grow the hash table.  */
384  unsigned int frozen:1;
385};
386
387/* Initialize a hash table.  */
388extern bfd_boolean bfd_hash_table_init
389  (struct bfd_hash_table *,
390   struct bfd_hash_entry *(*) (struct bfd_hash_entry *,
391			       struct bfd_hash_table *,
392			       const char *),
393   unsigned int);
394
395/* Initialize a hash table specifying a size.  */
396extern bfd_boolean bfd_hash_table_init_n
397  (struct bfd_hash_table *,
398   struct bfd_hash_entry *(*) (struct bfd_hash_entry *,
399			       struct bfd_hash_table *,
400			       const char *),
401   unsigned int, unsigned int);
402
403/* Free up a hash table.  */
404extern void bfd_hash_table_free
405  (struct bfd_hash_table *);
406
407/* Look up a string in a hash table.  If CREATE is TRUE, a new entry
408   will be created for this string if one does not already exist.  The
409   COPY argument must be TRUE if this routine should copy the string
410   into newly allocated memory when adding an entry.  */
411extern struct bfd_hash_entry *bfd_hash_lookup
412  (struct bfd_hash_table *, const char *, bfd_boolean create,
413   bfd_boolean copy);
414
415/* Insert an entry in a hash table.  */
416extern struct bfd_hash_entry *bfd_hash_insert
417  (struct bfd_hash_table *, const char *, unsigned long);
418
419/* Rename an entry in a hash table.  */
420extern void bfd_hash_rename
421  (struct bfd_hash_table *, const char *, struct bfd_hash_entry *);
422
423/* Replace an entry in a hash table.  */
424extern void bfd_hash_replace
425  (struct bfd_hash_table *, struct bfd_hash_entry *old,
426   struct bfd_hash_entry *nw);
427
428/* Base method for creating a hash table entry.  */
429extern struct bfd_hash_entry *bfd_hash_newfunc
430  (struct bfd_hash_entry *, struct bfd_hash_table *, const char *);
431
432/* Grab some space for a hash table entry.  */
433extern void *bfd_hash_allocate
434  (struct bfd_hash_table *, unsigned int);
435
436/* Traverse a hash table in a random order, calling a function on each
437   element.  If the function returns FALSE, the traversal stops.  The
438   INFO argument is passed to the function.  */
439extern void bfd_hash_traverse
440  (struct bfd_hash_table *,
441   bfd_boolean (*) (struct bfd_hash_entry *, void *),
442   void *info);
443
444/* Allows the default size of a hash table to be configured. New hash
445   tables allocated using bfd_hash_table_init will be created with
446   this size.  */
447extern unsigned long bfd_hash_set_default_size (unsigned long);
448
449/* Types of compressed DWARF debug sections.  We currently support
450   zlib.  */
451enum compressed_debug_section_type
452{
453  COMPRESS_DEBUG_NONE = 0,
454  COMPRESS_DEBUG = 1 << 0,
455  COMPRESS_DEBUG_GNU_ZLIB = COMPRESS_DEBUG | 1 << 1,
456  COMPRESS_DEBUG_GABI_ZLIB = COMPRESS_DEBUG | 1 << 2
457};
458
459/* This structure is used to keep track of stabs in sections
460   information while linking.  */
461
462struct stab_info
463{
464  /* A hash table used to hold stabs strings.  */
465  struct bfd_strtab_hash *strings;
466  /* The header file hash table.  */
467  struct bfd_hash_table includes;
468  /* The first .stabstr section.  */
469  struct bfd_section *stabstr;
470};
471
472#define COFF_SWAP_TABLE (void *) &bfd_coff_std_swap_table
473
474/* User program access to BFD facilities.  */
475
476/* Direct I/O routines, for programs which know more about the object
477   file than BFD does.  Use higher level routines if possible.  */
478
479extern bfd_size_type bfd_bread (void *, bfd_size_type, bfd *);
480extern bfd_size_type bfd_bwrite (const void *, bfd_size_type, bfd *);
481extern int bfd_seek (bfd *, file_ptr, int);
482extern file_ptr bfd_tell (bfd *);
483extern int bfd_flush (bfd *);
484extern int bfd_stat (bfd *, struct stat *);
485
486/* Deprecated old routines.  */
487#if __GNUC__
488#define bfd_read(BUF, ELTSIZE, NITEMS, ABFD)				\
489  (warn_deprecated ("bfd_read", __FILE__, __LINE__, __FUNCTION__),	\
490   bfd_bread ((BUF), (ELTSIZE) * (NITEMS), (ABFD)))
491#define bfd_write(BUF, ELTSIZE, NITEMS, ABFD)				\
492  (warn_deprecated ("bfd_write", __FILE__, __LINE__, __FUNCTION__),	\
493   bfd_bwrite ((BUF), (ELTSIZE) * (NITEMS), (ABFD)))
494#else
495#define bfd_read(BUF, ELTSIZE, NITEMS, ABFD)				\
496  (warn_deprecated ("bfd_read", (const char *) 0, 0, (const char *) 0), \
497   bfd_bread ((BUF), (ELTSIZE) * (NITEMS), (ABFD)))
498#define bfd_write(BUF, ELTSIZE, NITEMS, ABFD)				\
499  (warn_deprecated ("bfd_write", (const char *) 0, 0, (const char *) 0),\
500   bfd_bwrite ((BUF), (ELTSIZE) * (NITEMS), (ABFD)))
501#endif
502extern void warn_deprecated (const char *, const char *, int, const char *);
503
504/* Cast from const char * to char * so that caller can assign to
505   a char * without a warning.  */
506#define bfd_get_filename(abfd) ((char *) (abfd)->filename)
507#define bfd_get_cacheable(abfd) ((abfd)->cacheable)
508#define bfd_get_format(abfd) ((abfd)->format)
509#define bfd_get_target(abfd) ((abfd)->xvec->name)
510#define bfd_get_flavour(abfd) ((abfd)->xvec->flavour)
511#define bfd_family_coff(abfd) \
512  (bfd_get_flavour (abfd) == bfd_target_coff_flavour || \
513   bfd_get_flavour (abfd) == bfd_target_xcoff_flavour)
514#define bfd_big_endian(abfd) ((abfd)->xvec->byteorder == BFD_ENDIAN_BIG)
515#define bfd_little_endian(abfd) ((abfd)->xvec->byteorder == BFD_ENDIAN_LITTLE)
516#define bfd_header_big_endian(abfd) \
517  ((abfd)->xvec->header_byteorder == BFD_ENDIAN_BIG)
518#define bfd_header_little_endian(abfd) \
519  ((abfd)->xvec->header_byteorder == BFD_ENDIAN_LITTLE)
520#define bfd_get_file_flags(abfd) ((abfd)->flags)
521#define bfd_applicable_file_flags(abfd) ((abfd)->xvec->object_flags)
522#define bfd_applicable_section_flags(abfd) ((abfd)->xvec->section_flags)
523#define bfd_has_map(abfd) ((abfd)->has_armap)
524#define bfd_is_thin_archive(abfd) ((abfd)->is_thin_archive)
525
526#define bfd_valid_reloc_types(abfd) ((abfd)->xvec->valid_reloc_types)
527#define bfd_usrdata(abfd) ((abfd)->usrdata)
528
529#define bfd_get_start_address(abfd) ((abfd)->start_address)
530#define bfd_get_symcount(abfd) ((abfd)->symcount)
531#define bfd_get_outsymbols(abfd) ((abfd)->outsymbols)
532#define bfd_count_sections(abfd) ((abfd)->section_count)
533
534#define bfd_get_dynamic_symcount(abfd) ((abfd)->dynsymcount)
535
536#define bfd_get_symbol_leading_char(abfd) ((abfd)->xvec->symbol_leading_char)
537
538extern bfd_boolean bfd_cache_close
539  (bfd *abfd);
540/* NB: This declaration should match the autogenerated one in libbfd.h.  */
541
542extern bfd_boolean bfd_cache_close_all (void);
543
544extern bfd_boolean bfd_record_phdr
545  (bfd *, unsigned long, bfd_boolean, flagword, bfd_boolean, bfd_vma,
546   bfd_boolean, bfd_boolean, unsigned int, struct bfd_section **);
547
548/* Byte swapping routines.  */
549
550bfd_uint64_t bfd_getb64 (const void *);
551bfd_uint64_t bfd_getl64 (const void *);
552bfd_int64_t bfd_getb_signed_64 (const void *);
553bfd_int64_t bfd_getl_signed_64 (const void *);
554bfd_vma bfd_getb32 (const void *);
555bfd_vma bfd_getl32 (const void *);
556bfd_signed_vma bfd_getb_signed_32 (const void *);
557bfd_signed_vma bfd_getl_signed_32 (const void *);
558bfd_vma bfd_getb16 (const void *);
559bfd_vma bfd_getl16 (const void *);
560bfd_signed_vma bfd_getb_signed_16 (const void *);
561bfd_signed_vma bfd_getl_signed_16 (const void *);
562void bfd_putb64 (bfd_uint64_t, void *);
563void bfd_putl64 (bfd_uint64_t, void *);
564void bfd_putb32 (bfd_vma, void *);
565void bfd_putl32 (bfd_vma, void *);
566void bfd_putb16 (bfd_vma, void *);
567void bfd_putl16 (bfd_vma, void *);
568
569/* Byte swapping routines which take size and endiannes as arguments.  */
570
571bfd_uint64_t bfd_get_bits (const void *, int, bfd_boolean);
572void bfd_put_bits (bfd_uint64_t, void *, int, bfd_boolean);
573
574#if defined(__STDC__) || defined(ALMOST_STDC)
575struct ecoff_debug_info;
576struct ecoff_debug_swap;
577struct ecoff_extr;
578struct bfd_symbol;
579struct bfd_link_info;
580struct bfd_link_hash_entry;
581struct bfd_section_already_linked;
582struct bfd_elf_version_tree;
583#endif
584
585extern bfd_boolean bfd_section_already_linked_table_init (void);
586extern void bfd_section_already_linked_table_free (void);
587extern bfd_boolean _bfd_handle_already_linked
588  (struct bfd_section *, struct bfd_section_already_linked *,
589   struct bfd_link_info *);
590
591/* Externally visible ECOFF routines.  */
592
593extern bfd_vma bfd_ecoff_get_gp_value
594  (bfd * abfd);
595extern bfd_boolean bfd_ecoff_set_gp_value
596  (bfd *abfd, bfd_vma gp_value);
597extern bfd_boolean bfd_ecoff_set_regmasks
598  (bfd *abfd, unsigned long gprmask, unsigned long fprmask,
599   unsigned long *cprmask);
600extern void *bfd_ecoff_debug_init
601  (bfd *output_bfd, struct ecoff_debug_info *output_debug,
602   const struct ecoff_debug_swap *output_swap, struct bfd_link_info *);
603extern void bfd_ecoff_debug_free
604  (void *handle, bfd *output_bfd, struct ecoff_debug_info *output_debug,
605   const struct ecoff_debug_swap *output_swap, struct bfd_link_info *);
606extern bfd_boolean bfd_ecoff_debug_accumulate
607  (void *handle, bfd *output_bfd, struct ecoff_debug_info *output_debug,
608   const struct ecoff_debug_swap *output_swap, bfd *input_bfd,
609   struct ecoff_debug_info *input_debug,
610   const struct ecoff_debug_swap *input_swap, struct bfd_link_info *);
611extern bfd_boolean bfd_ecoff_debug_accumulate_other
612  (void *handle, bfd *output_bfd, struct ecoff_debug_info *output_debug,
613   const struct ecoff_debug_swap *output_swap, bfd *input_bfd,
614   struct bfd_link_info *);
615extern bfd_boolean bfd_ecoff_debug_externals
616  (bfd *abfd, struct ecoff_debug_info *debug,
617   const struct ecoff_debug_swap *swap, bfd_boolean relocatable,
618   bfd_boolean (*get_extr) (struct bfd_symbol *, struct ecoff_extr *),
619   void (*set_index) (struct bfd_symbol *, bfd_size_type));
620extern bfd_boolean bfd_ecoff_debug_one_external
621  (bfd *abfd, struct ecoff_debug_info *debug,
622   const struct ecoff_debug_swap *swap, const char *name,
623   struct ecoff_extr *esym);
624extern bfd_size_type bfd_ecoff_debug_size
625  (bfd *abfd, struct ecoff_debug_info *debug,
626   const struct ecoff_debug_swap *swap);
627extern bfd_boolean bfd_ecoff_write_debug
628  (bfd *abfd, struct ecoff_debug_info *debug,
629   const struct ecoff_debug_swap *swap, file_ptr where);
630extern bfd_boolean bfd_ecoff_write_accumulated_debug
631  (void *handle, bfd *abfd, struct ecoff_debug_info *debug,
632   const struct ecoff_debug_swap *swap,
633   struct bfd_link_info *info, file_ptr where);
634
635/* Externally visible ELF routines.  */
636
637struct bfd_link_needed_list
638{
639  struct bfd_link_needed_list *next;
640  bfd *by;
641  const char *name;
642};
643
644enum dynamic_lib_link_class {
645  DYN_NORMAL = 0,
646  DYN_AS_NEEDED = 1,
647  DYN_DT_NEEDED = 2,
648  DYN_NO_ADD_NEEDED = 4,
649  DYN_NO_NEEDED = 8
650};
651
652enum notice_asneeded_action {
653  notice_as_needed,
654  notice_not_needed,
655  notice_needed
656};
657
658extern bfd_boolean bfd_elf_record_link_assignment
659  (bfd *, struct bfd_link_info *, const char *, bfd_boolean,
660   bfd_boolean);
661extern struct bfd_link_needed_list *bfd_elf_get_needed_list
662  (bfd *, struct bfd_link_info *);
663extern bfd_boolean bfd_elf_get_bfd_needed_list
664  (bfd *, struct bfd_link_needed_list **);
665extern bfd_boolean bfd_elf_stack_segment_size (bfd *, struct bfd_link_info *,
666					       const char *, bfd_vma);
667extern bfd_boolean bfd_elf_size_dynamic_sections
668  (bfd *, const char *, const char *, const char *, const char *, const char *,
669   const char * const *, struct bfd_link_info *, struct bfd_section **);
670extern bfd_boolean bfd_elf_size_dynsym_hash_dynstr
671  (bfd *, struct bfd_link_info *);
672extern void bfd_elf_set_dt_needed_name
673  (bfd *, const char *);
674extern const char *bfd_elf_get_dt_soname
675  (bfd *);
676extern void bfd_elf_set_dyn_lib_class
677  (bfd *, enum dynamic_lib_link_class);
678extern int bfd_elf_get_dyn_lib_class
679  (bfd *);
680extern struct bfd_link_needed_list *bfd_elf_get_runpath_list
681  (bfd *, struct bfd_link_info *);
682extern int bfd_elf_discard_info
683  (bfd *, struct bfd_link_info *);
684extern unsigned int _bfd_elf_default_action_discarded
685  (struct bfd_section *);
686
687/* Return an upper bound on the number of bytes required to store a
688   copy of ABFD's program header table entries.  Return -1 if an error
689   occurs; bfd_get_error will return an appropriate code.  */
690extern long bfd_get_elf_phdr_upper_bound
691  (bfd *abfd);
692
693/* Copy ABFD's program header table entries to *PHDRS.  The entries
694   will be stored as an array of Elf_Internal_Phdr structures, as
695   defined in include/elf/internal.h.  To find out how large the
696   buffer needs to be, call bfd_get_elf_phdr_upper_bound.
697
698   Return the number of program header table entries read, or -1 if an
699   error occurs; bfd_get_error will return an appropriate code.  */
700extern int bfd_get_elf_phdrs
701  (bfd *abfd, void *phdrs);
702
703/* Create a new BFD as if by bfd_openr.  Rather than opening a file,
704   reconstruct an ELF file by reading the segments out of remote
705   memory based on the ELF file header at EHDR_VMA and the ELF program
706   headers it points to.  If non-zero, SIZE is the known extent of the
707   object.  If not null, *LOADBASEP is filled in with the difference
708   between the VMAs from which the segments were read, and the VMAs
709   the file headers (and hence BFD's idea of each section's VMA) put
710   them at.
711
712   The function TARGET_READ_MEMORY is called to copy LEN bytes from
713   the remote memory at target address VMA into the local buffer at
714   MYADDR; it should return zero on success or an `errno' code on
715   failure.  TEMPL must be a BFD for a target with the word size and
716   byte order found in the remote memory.  */
717extern bfd *bfd_elf_bfd_from_remote_memory
718  (bfd *templ, bfd_vma ehdr_vma, bfd_size_type size, bfd_vma *loadbasep,
719   int (*target_read_memory) (bfd_vma vma, bfd_byte *myaddr,
720			      bfd_size_type len));
721
722extern struct bfd_section *_bfd_elf_tls_setup
723  (bfd *, struct bfd_link_info *);
724
725extern struct bfd_section *
726_bfd_nearby_section (bfd *, struct bfd_section *, bfd_vma);
727
728extern void _bfd_fix_excluded_sec_syms
729  (bfd *, struct bfd_link_info *);
730
731extern unsigned bfd_m68k_mach_to_features (int);
732
733extern int bfd_m68k_features_to_mach (unsigned);
734
735extern bfd_boolean bfd_m68k_elf32_create_embedded_relocs
736  (bfd *, struct bfd_link_info *, struct bfd_section *, struct bfd_section *,
737   char **);
738
739extern void bfd_elf_m68k_set_target_options (struct bfd_link_info *, int);
740
741extern bfd_boolean bfd_bfin_elf32_create_embedded_relocs
742  (bfd *, struct bfd_link_info *, struct bfd_section *, struct bfd_section *,
743   char **);
744
745extern bfd_boolean bfd_cr16_elf32_create_embedded_relocs
746  (bfd *, struct bfd_link_info *, struct bfd_section *, struct bfd_section *,
747   char **);
748
749/* SunOS shared library support routines for the linker.  */
750
751extern struct bfd_link_needed_list *bfd_sunos_get_needed_list
752  (bfd *, struct bfd_link_info *);
753extern bfd_boolean bfd_sunos_record_link_assignment
754  (bfd *, struct bfd_link_info *, const char *);
755extern bfd_boolean bfd_sunos_size_dynamic_sections
756  (bfd *, struct bfd_link_info *, struct bfd_section **,
757   struct bfd_section **, struct bfd_section **);
758
759/* Linux shared library support routines for the linker.  */
760
761extern bfd_boolean bfd_i386linux_size_dynamic_sections
762  (bfd *, struct bfd_link_info *);
763extern bfd_boolean bfd_m68klinux_size_dynamic_sections
764  (bfd *, struct bfd_link_info *);
765extern bfd_boolean bfd_sparclinux_size_dynamic_sections
766  (bfd *, struct bfd_link_info *);
767
768/* mmap hacks */
769
770struct _bfd_window_internal;
771typedef struct _bfd_window_internal bfd_window_internal;
772
773typedef struct _bfd_window
774{
775  /* What the user asked for.  */
776  void *data;
777  bfd_size_type size;
778  /* The actual window used by BFD.  Small user-requested read-only
779     regions sharing a page may share a single window into the object
780     file.  Read-write versions shouldn't until I've fixed things to
781     keep track of which portions have been claimed by the
782     application; don't want to give the same region back when the
783     application wants two writable copies!  */
784  struct _bfd_window_internal *i;
785}
786bfd_window;
787
788extern void bfd_init_window
789  (bfd_window *);
790extern void bfd_free_window
791  (bfd_window *);
792extern bfd_boolean bfd_get_file_window
793  (bfd *, file_ptr, bfd_size_type, bfd_window *, bfd_boolean);
794
795/* XCOFF support routines for the linker.  */
796
797extern bfd_boolean bfd_xcoff_split_import_path
798  (bfd *, const char *, const char **, const char **);
799extern bfd_boolean bfd_xcoff_set_archive_import_path
800  (struct bfd_link_info *, bfd *, const char *);
801extern bfd_boolean bfd_xcoff_link_record_set
802  (bfd *, struct bfd_link_info *, struct bfd_link_hash_entry *, bfd_size_type);
803extern bfd_boolean bfd_xcoff_import_symbol
804  (bfd *, struct bfd_link_info *, struct bfd_link_hash_entry *, bfd_vma,
805   const char *, const char *, const char *, unsigned int);
806extern bfd_boolean bfd_xcoff_export_symbol
807  (bfd *, struct bfd_link_info *, struct bfd_link_hash_entry *);
808extern bfd_boolean bfd_xcoff_link_count_reloc
809  (bfd *, struct bfd_link_info *, const char *);
810extern bfd_boolean bfd_xcoff_record_link_assignment
811  (bfd *, struct bfd_link_info *, const char *);
812extern bfd_boolean bfd_xcoff_size_dynamic_sections
813  (bfd *, struct bfd_link_info *, const char *, const char *,
814   unsigned long, unsigned long, unsigned long, bfd_boolean,
815   int, bfd_boolean, unsigned int, struct bfd_section **, bfd_boolean);
816extern bfd_boolean bfd_xcoff_link_generate_rtinit
817  (bfd *, const char *, const char *, bfd_boolean);
818
819/* XCOFF support routines for ar.  */
820extern bfd_boolean bfd_xcoff_ar_archive_set_magic
821  (bfd *, char *);
822
823/* Externally visible COFF routines.  */
824
825#if defined(__STDC__) || defined(ALMOST_STDC)
826struct internal_syment;
827union internal_auxent;
828#endif
829
830extern bfd_boolean bfd_coff_set_symbol_class
831  (bfd *, struct bfd_symbol *, unsigned int);
832
833extern bfd_boolean bfd_m68k_coff_create_embedded_relocs
834  (bfd *, struct bfd_link_info *, struct bfd_section *, struct bfd_section *, char **);
835
836/* ARM VFP11 erratum workaround support.  */
837typedef enum
838{
839  BFD_ARM_VFP11_FIX_DEFAULT,
840  BFD_ARM_VFP11_FIX_NONE,
841  BFD_ARM_VFP11_FIX_SCALAR,
842  BFD_ARM_VFP11_FIX_VECTOR
843} bfd_arm_vfp11_fix;
844
845extern void bfd_elf32_arm_init_maps
846  (bfd *);
847
848extern void bfd_elf32_arm_set_vfp11_fix
849  (bfd *, struct bfd_link_info *);
850
851extern void bfd_elf32_arm_set_cortex_a8_fix
852  (bfd *, struct bfd_link_info *);
853
854extern bfd_boolean bfd_elf32_arm_vfp11_erratum_scan
855  (bfd *, struct bfd_link_info *);
856
857extern void bfd_elf32_arm_vfp11_fix_veneer_locations
858  (bfd *, struct bfd_link_info *);
859
860/* ARM STM STM32L4XX erratum workaround support.  */
861typedef enum
862{
863  BFD_ARM_STM32L4XX_FIX_NONE,
864  BFD_ARM_STM32L4XX_FIX_DEFAULT,
865  BFD_ARM_STM32L4XX_FIX_ALL
866} bfd_arm_stm32l4xx_fix;
867
868extern void bfd_elf32_arm_set_stm32l4xx_fix
869  (bfd *, struct bfd_link_info *);
870
871extern bfd_boolean bfd_elf32_arm_stm32l4xx_erratum_scan
872  (bfd *, struct bfd_link_info *);
873
874extern void bfd_elf32_arm_stm32l4xx_fix_veneer_locations
875  (bfd *, struct bfd_link_info *);
876
877/* ARM Interworking support.  Called from linker.  */
878extern bfd_boolean bfd_arm_allocate_interworking_sections
879  (struct bfd_link_info *);
880
881extern bfd_boolean bfd_arm_process_before_allocation
882  (bfd *, struct bfd_link_info *, int);
883
884extern bfd_boolean bfd_arm_get_bfd_for_interworking
885  (bfd *, struct bfd_link_info *);
886
887/* PE ARM Interworking support.  Called from linker.  */
888extern bfd_boolean bfd_arm_pe_allocate_interworking_sections
889  (struct bfd_link_info *);
890
891extern bfd_boolean bfd_arm_pe_process_before_allocation
892  (bfd *, struct bfd_link_info *, int);
893
894extern bfd_boolean bfd_arm_pe_get_bfd_for_interworking
895  (bfd *, struct bfd_link_info *);
896
897/* ELF ARM Interworking support.  Called from linker.  */
898extern bfd_boolean bfd_elf32_arm_allocate_interworking_sections
899  (struct bfd_link_info *);
900
901extern bfd_boolean bfd_elf32_arm_process_before_allocation
902  (bfd *, struct bfd_link_info *);
903
904struct elf32_arm_params {
905  char *thumb_entry_symbol;
906  int byteswap_code;
907  int target1_is_rel;
908  char * target2_type;
909  int fix_v4bx;
910  int use_blx;
911  bfd_arm_vfp11_fix vfp11_denorm_fix;
912  bfd_arm_stm32l4xx_fix stm32l4xx_fix;
913  int no_enum_size_warning;
914  int no_wchar_size_warning;
915  int pic_veneer;
916  int fix_cortex_a8;
917  int fix_arm1176;
918  int merge_exidx_entries;
919  int cmse_implib;
920  bfd *in_implib_bfd;
921};
922
923void bfd_elf32_arm_set_target_params
924  (bfd *, struct bfd_link_info *, struct elf32_arm_params *);
925
926extern bfd_boolean bfd_elf32_arm_get_bfd_for_interworking
927  (bfd *, struct bfd_link_info *);
928
929extern bfd_boolean bfd_elf32_arm_add_glue_sections_to_bfd
930  (bfd *, struct bfd_link_info *);
931
932extern void bfd_elf32_arm_keep_private_stub_output_sections
933  (struct bfd_link_info *);
934
935/* ELF ARM mapping symbol support.  */
936#define BFD_ARM_SPECIAL_SYM_TYPE_MAP	(1 << 0)
937#define BFD_ARM_SPECIAL_SYM_TYPE_TAG	(1 << 1)
938#define BFD_ARM_SPECIAL_SYM_TYPE_OTHER  (1 << 2)
939#define BFD_ARM_SPECIAL_SYM_TYPE_ANY	(~0)
940
941extern bfd_boolean bfd_is_arm_special_symbol_name
942  (const char *, int);
943
944extern void bfd_elf32_arm_set_byteswap_code
945  (struct bfd_link_info *, int);
946
947extern void bfd_elf32_arm_use_long_plt (void);
948
949/* ARM Note section processing.  */
950extern bfd_boolean bfd_arm_merge_machines
951  (bfd *, bfd *);
952
953extern bfd_boolean bfd_arm_update_notes
954  (bfd *, const char *);
955
956extern unsigned int bfd_arm_get_mach_from_notes
957  (bfd *, const char *);
958
959/* ARM stub generation support.  Called from the linker.  */
960extern int elf32_arm_setup_section_lists
961  (bfd *, struct bfd_link_info *);
962extern void elf32_arm_next_input_section
963  (struct bfd_link_info *, struct bfd_section *);
964extern bfd_boolean elf32_arm_size_stubs
965  (bfd *, bfd *, struct bfd_link_info *, bfd_signed_vma,
966   struct bfd_section * (*) (const char *, struct bfd_section *,
967			     struct bfd_section *, unsigned int),
968   void (*) (void));
969extern bfd_boolean elf32_arm_build_stubs
970  (struct bfd_link_info *);
971
972/* ARM unwind section editing support.  */
973extern bfd_boolean elf32_arm_fix_exidx_coverage
974(struct bfd_section **, unsigned int, struct bfd_link_info *, bfd_boolean);
975
976/* C6x unwind section editing support.  */
977extern bfd_boolean elf32_tic6x_fix_exidx_coverage
978(struct bfd_section **, unsigned int, struct bfd_link_info *, bfd_boolean);
979
980extern void bfd_elf64_aarch64_init_maps
981  (bfd *);
982
983extern void bfd_elf32_aarch64_init_maps
984  (bfd *);
985
986extern void bfd_elf64_aarch64_set_options
987  (bfd *, struct bfd_link_info *, int, int, int, int, int, int);
988
989extern void bfd_elf32_aarch64_set_options
990  (bfd *, struct bfd_link_info *, int, int, int, int, int, int);
991
992/* ELF AArch64 mapping symbol support.  */
993#define BFD_AARCH64_SPECIAL_SYM_TYPE_MAP	(1 << 0)
994#define BFD_AARCH64_SPECIAL_SYM_TYPE_TAG	(1 << 1)
995#define BFD_AARCH64_SPECIAL_SYM_TYPE_OTHER	(1 << 2)
996#define BFD_AARCH64_SPECIAL_SYM_TYPE_ANY	(~0)
997extern bfd_boolean bfd_is_aarch64_special_symbol_name
998  (const char * name, int type);
999
1000/* AArch64 stub generation support for ELF64.  Called from the linker.  */
1001extern int elf64_aarch64_setup_section_lists
1002  (bfd *, struct bfd_link_info *);
1003extern void elf64_aarch64_next_input_section
1004  (struct bfd_link_info *, struct bfd_section *);
1005extern bfd_boolean elf64_aarch64_size_stubs
1006  (bfd *, bfd *, struct bfd_link_info *, bfd_signed_vma,
1007   struct bfd_section * (*) (const char *, struct bfd_section *),
1008   void (*) (void));
1009extern bfd_boolean elf64_aarch64_build_stubs
1010  (struct bfd_link_info *);
1011/* AArch64 stub generation support for ELF32.  Called from the linker.  */
1012extern int elf32_aarch64_setup_section_lists
1013  (bfd *, struct bfd_link_info *);
1014extern void elf32_aarch64_next_input_section
1015  (struct bfd_link_info *, struct bfd_section *);
1016extern bfd_boolean elf32_aarch64_size_stubs
1017  (bfd *, bfd *, struct bfd_link_info *, bfd_signed_vma,
1018   struct bfd_section * (*) (const char *, struct bfd_section *),
1019   void (*) (void));
1020extern bfd_boolean elf32_aarch64_build_stubs
1021  (struct bfd_link_info *);
1022
1023
1024/* TI COFF load page support.  */
1025extern void bfd_ticoff_set_section_load_page
1026  (struct bfd_section *, int);
1027
1028extern int bfd_ticoff_get_section_load_page
1029  (struct bfd_section *);
1030
1031/* H8/300 functions.  */
1032extern bfd_vma bfd_h8300_pad_address
1033  (bfd *, bfd_vma);
1034
1035/* IA64 Itanium code generation.  Called from linker.  */
1036extern void bfd_elf32_ia64_after_parse
1037  (int);
1038
1039extern void bfd_elf64_ia64_after_parse
1040  (int);
1041
1042/* V850 Note manipulation routines.  */
1043extern bfd_boolean v850_elf_create_sections
1044  (struct bfd_link_info *);
1045
1046extern bfd_boolean v850_elf_set_note
1047  (bfd *, unsigned int, unsigned int);
1048
1049/* MIPS ABI flags data access.  For the disassembler.  */
1050struct elf_internal_abiflags_v0;
1051extern struct elf_internal_abiflags_v0 *bfd_mips_elf_get_abiflags (bfd *);
1052