bfd-in.h 35 KB

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