xref: /netbsd-src/external/gpl3/binutils/dist/bfd/bfd-in.h (revision cb63e24e8d6aae7ddac1859a9015f48b1d8bd90e)
1 /* Main header file for the bfd library -- portable access to object files.
2 
3    Copyright (C) 1990-2024 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
32 extern "C" {
33 #endif
34 
35 #include "ansidecl.h"
36 #include "symcat.h"
37 #include <stdint.h>
38 #include <stdbool.h>
39 #include "diagnostics.h"
40 #include <stdarg.h>
41 #include <string.h>
42 #include <sys/stat.h>
43 
44 #if defined (__STDC__) || defined (ALMOST_STDC) || defined (HAVE_STRINGIZE)
45 #ifndef SABER
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.  */
51 #undef CONCAT4
52 #define CONCAT4(a,b,c,d) XCONCAT2(CONCAT2(a,b),CONCAT2(c,d))
53 #endif
54 #endif
55 
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)
61 
62 #define BFD_SUPPORTS_PLUGINS @supports_plugins@
63 
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@
68 
69 /* The word size of the default bfd target.  */
70 #define BFD_DEFAULT_TARGET_SIZE @bfd_default_target_size@
71 
72 #include <inttypes.h>
73 
74 #if BFD_ARCH_SIZE >= 64
75 #define BFD64
76 #endif
77 
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).  */
81 
82 #ifdef POISON_BFD_BOOLEAN
83 # pragma GCC poison bfd_boolean
84 #else
85 # define bfd_boolean bool
86 # undef FALSE
87 # undef TRUE
88 # define FALSE 0
89 # define TRUE 1
90 #endif
91 
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))
96 
97 #ifdef BFD64
98 
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;
103 
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;
109 
110 typedef uint64_t bfd_size_type;
111 typedef uint64_t symvalue;
112 
113 #else /* not BFD64  */
114 
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;
119 
120 #endif /* not BFD64  */
121 
122 #define HALF_BFD_SIZE_TYPE \
123   (((bfd_size_type) 1) << (8 * sizeof (bfd_size_type) / 2))
124 
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;
129 
130 typedef uint32_t flagword;	/* 32 bits of flags */
131 typedef uint8_t bfd_byte;
132 
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;
139 struct orl;
140 
141 #define	align_power(addr, align)	\
142   (((addr) + ((bfd_vma) 1 << (align)) - 1) & (-((bfd_vma) 1 << (align))))
143 
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
147    address space.  */
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)) \
151    : ~ (bfd_vma) 0)
152 
153 /* Return TRUE if the start of STR matches PREFIX, FALSE otherwise.  */
154 
155 static inline bool
startswith(const char * str,const char * prefix)156 startswith (const char *str, const char *prefix)
157 {
158   return strncmp (str, prefix, strlen (prefix)) == 0;
159 }
160 
161