1 /* Main header file for the bfd library -- portable access to object files.
3 Copyright (C) 1990-2023 Free Software Foundation, Inc.
5 Contributed by Cygnus Support.
7 This file is part of BFD, the Binary File Descriptor library.
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.
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.
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. */
23 #ifndef __BFD_H_SEEN__
24 #define __BFD_H_SEEN__
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
39 #include "diagnostics.h"
44 #if defined (__STDC__) || defined (ALMOST_STDC) || defined (HAVE_STRINGIZE)
46 /* This hack is to avoid a problem with some strict ANSI C preprocessors.
47 The problem is, "32_" is not a valid preprocessing token, and we don't
48 want extra underscores (e.g., "nlm_32_"). The XCONCAT2 macro will
49 cause the inner CONCAT2 macros to be evaluated first, producing
50 still-valid pp-tokens. Then the final concatenation can be done. */
52 #define CONCAT4(a,b,c,d) XCONCAT2(CONCAT2(a,b),CONCAT2(c,d))
56 /* This is a utility macro to handle the situation where the code
57 wants to place a constant string into the code, followed by a
58 comma and then the length of the string. Doing this by hand
59 is error prone, so using this macro is safer. */
60 #define STRING_COMMA_LEN(STR) (STR), (sizeof (STR) - 1)
62 #define BFD_SUPPORTS_PLUGINS @supports_plugins@
64 /* The word size used by BFD on the host. This may be 64 with a 32
65 bit target if the host is 64 bit, or if other 64 bit targets have
66 been selected with --enable-targets, or if --enable-64-bit-bfd. */
67 #define BFD_ARCH_SIZE @wordsize@
69 /* The word size of the default bfd target. */
70 #define BFD_DEFAULT_TARGET_SIZE @bfd_default_target_size@
74 #if BFD_ARCH_SIZE >= 64
78 /* Boolean type used in bfd.
79 General rule: Functions which are bfd_boolean return TRUE on
80 success and FALSE on failure (unless they're a predicate). */
82 #ifdef POISON_BFD_BOOLEAN
83 # pragma GCC poison bfd_boolean
85 # define bfd_boolean bool
92 /* Silence "applying zero offset to null pointer" UBSAN warnings. */
93 #define PTR_ADD(P,A) ((A) != 0 ? (P) + (A) : (P))
94 /* Also prevent non-zero offsets from being applied to a null pointer. */
95 #define NPTR_ADD(P,A) ((P) != NULL ? (P) + (A) : (P))
99 /* Represent a target address. Also used as a generic unsigned type
100 which is guaranteed to be big enough to hold any arithmetic types
101 we need to deal with. */
102 typedef uint64_t bfd_vma
;
104 /* A generic signed type which is guaranteed to be big enough to hold any
105 arithmetic types we need to deal with. Can be assumed to be compatible
106 with bfd_vma in the same way that signed and unsigned ints are compatible
107 (as parameters, in assignment, etc). */
108 typedef int64_t bfd_signed_vma
;
110 typedef uint64_t bfd_size_type
;
111 typedef uint64_t symvalue
;
113 #else /* not BFD64 */
115 typedef uint32_t bfd_vma
;
116 typedef int32_t bfd_signed_vma
;
117 typedef uint32_t bfd_size_type
;
118 typedef uint32_t symvalue
;
120 #endif /* not BFD64 */
122 #define HALF_BFD_SIZE_TYPE \
123 (((bfd_size_type) 1) << (8 * sizeof (bfd_size_type) / 2))
125 /* An offset into a file. BFD always uses the largest possible offset
126 based on the build time availability of fseek, fseeko, or fseeko64. */
127 typedef @bfd_file_ptr@ file_ptr
;
128 typedef @bfd_ufile_ptr@ ufile_ptr
;
130 typedef uint32_t flagword
; /* 32 bits of flags */
131 typedef uint8_t bfd_byte
;
133 /* Forward declarations. */
134 typedef struct bfd bfd
;
135 struct bfd_link_info
;
136 struct bfd_link_hash_entry
;
137 typedef struct bfd_section
*sec_ptr
;
138 typedef struct reloc_cache_entry arelent
;
141 #define align_power(addr, align) \
142 (((addr) + ((bfd_vma) 1 << (align)) - 1) & (-((bfd_vma) 1 << (align))))
144 /* Align an address upward to a boundary, expressed as a number of bytes.
145 E.g. align to an 8-byte boundary with argument of 8. Take care never
146 to wrap around if the address is within boundary-1 of the end of the
148 #define BFD_ALIGN(this, boundary) \
149 ((((bfd_vma) (this) + (boundary) - 1) >= (bfd_vma) (this)) \
150 ? (((bfd_vma) (this) + ((boundary) - 1)) & ~ (bfd_vma) ((boundary)-1)) \
153 /* Return TRUE if the start of STR matches PREFIX, FALSE otherwise. */
156 startswith (const char *str
, const char *prefix
)
158 return strncmp (str
, prefix
, strlen (prefix
)) == 0;