Home | History | Annotate | Line # | Download | only in bfd
      1   1.1  christos /* Main header file for the bfd library -- portable access to object files.
      2   1.1  christos 
      3  1.11  christos    Copyright (C) 1990-2024 Free Software Foundation, Inc.
      4   1.1  christos 
      5   1.1  christos    Contributed by Cygnus Support.
      6   1.1  christos 
      7   1.1  christos    This file is part of BFD, the Binary File Descriptor library.
      8   1.1  christos 
      9   1.1  christos    This program is free software; you can redistribute it and/or modify
     10   1.1  christos    it under the terms of the GNU General Public License as published by
     11   1.1  christos    the Free Software Foundation; either version 3 of the License, or
     12   1.1  christos    (at your option) any later version.
     13   1.1  christos 
     14   1.1  christos    This program is distributed in the hope that it will be useful,
     15   1.1  christos    but WITHOUT ANY WARRANTY; without even the implied warranty of
     16   1.1  christos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     17   1.1  christos    GNU General Public License for more details.
     18   1.1  christos 
     19   1.1  christos    You should have received a copy of the GNU General Public License
     20   1.1  christos    along with this program; if not, write to the Free Software
     21   1.1  christos    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
     22   1.1  christos 
     23   1.1  christos #ifndef __BFD_H_SEEN__
     24   1.1  christos #define __BFD_H_SEEN__
     25   1.1  christos 
     26   1.1  christos /* PR 14072: Ensure that config.h is included first.  */
     27   1.1  christos #if !defined PACKAGE && !defined PACKAGE_VERSION
     28   1.1  christos #error config.h must be included before this header
     29   1.1  christos #endif
     30   1.1  christos 
     31   1.1  christos #ifdef __cplusplus
     32   1.1  christos extern "C" {
     33   1.1  christos #endif
     34   1.1  christos 
     35   1.1  christos #include "ansidecl.h"
     36   1.1  christos #include "symcat.h"
     37  1.10  christos #include <stdint.h>
     38  1.10  christos #include <stdbool.h>
     39  1.11  christos #include <time.h>
     40   1.8  christos #include "diagnostics.h"
     41   1.7  christos #include <stdarg.h>
     42  1.10  christos #include <string.h>
     43   1.1  christos #include <sys/stat.h>
     44   1.1  christos 
     45   1.1  christos #if defined (__STDC__) || defined (ALMOST_STDC) || defined (HAVE_STRINGIZE)
     46   1.1  christos #ifndef SABER
     47   1.1  christos /* This hack is to avoid a problem with some strict ANSI C preprocessors.
     48   1.1  christos    The problem is, "32_" is not a valid preprocessing token, and we don't
     49   1.1  christos    want extra underscores (e.g., "nlm_32_").  The XCONCAT2 macro will
     50   1.1  christos    cause the inner CONCAT2 macros to be evaluated first, producing
     51   1.1  christos    still-valid pp-tokens.  Then the final concatenation can be done.  */
     52   1.1  christos #undef CONCAT4
     53   1.1  christos #define CONCAT4(a,b,c,d) XCONCAT2(CONCAT2(a,b),CONCAT2(c,d))
     54   1.1  christos #endif
     55   1.1  christos #endif
     56   1.1  christos 
     57   1.1  christos /* This is a utility macro to handle the situation where the code
     58   1.1  christos    wants to place a constant string into the code, followed by a
     59   1.1  christos    comma and then the length of the string.  Doing this by hand
     60   1.1  christos    is error prone, so using this macro is safer.  */
     61   1.1  christos #define STRING_COMMA_LEN(STR) (STR), (sizeof (STR) - 1)
     62   1.1  christos 
     63   1.1  christos #define BFD_SUPPORTS_PLUGINS @supports_plugins@
     64   1.1  christos 
     65   1.1  christos /* The word size used by BFD on the host.  This may be 64 with a 32
     66   1.1  christos    bit target if the host is 64 bit, or if other 64 bit targets have
     67   1.1  christos    been selected with --enable-targets, or if --enable-64-bit-bfd.  */
     68   1.1  christos #define BFD_ARCH_SIZE @wordsize@
     69   1.1  christos 
     70   1.1  christos /* The word size of the default bfd target.  */
     71   1.1  christos #define BFD_DEFAULT_TARGET_SIZE @bfd_default_target_size@
     72   1.1  christos 
     73  1.10  christos #include <inttypes.h>
     74   1.8  christos 
     75   1.1  christos #if BFD_ARCH_SIZE >= 64
     76   1.1  christos #define BFD64
     77   1.1  christos #endif
     78   1.1  christos 
     79  1.10  christos /* Boolean type used in bfd.
     80   1.1  christos    General rule: Functions which are bfd_boolean return TRUE on
     81   1.1  christos    success and FALSE on failure (unless they're a predicate).  */
     82   1.1  christos 
     83  1.10  christos #ifdef POISON_BFD_BOOLEAN
     84  1.10  christos # pragma GCC poison bfd_boolean
     85   1.1  christos #else
     86  1.10  christos # define bfd_boolean bool
     87  1.10  christos # undef FALSE
     88  1.10  christos # undef TRUE
     89  1.10  christos # define FALSE 0
     90  1.10  christos # define TRUE 1
     91   1.1  christos #endif
     92   1.1  christos 
     93  1.10  christos /* Silence "applying zero offset to null pointer" UBSAN warnings.  */
     94  1.10  christos #define PTR_ADD(P,A) ((A) != 0 ? (P) + (A) : (P))
     95  1.10  christos /* Also prevent non-zero offsets from being applied to a null pointer.  */
     96  1.10  christos #define NPTR_ADD(P,A) ((P) != NULL ? (P) + (A) : (P))
     97   1.1  christos 
     98  1.10  christos #ifdef BFD64
     99   1.1  christos 
    100   1.1  christos /* Represent a target address.  Also used as a generic unsigned type
    101   1.1  christos    which is guaranteed to be big enough to hold any arithmetic types
    102   1.1  christos    we need to deal with.  */
    103  1.10  christos typedef uint64_t bfd_vma;
    104   1.1  christos 
    105   1.1  christos /* A generic signed type which is guaranteed to be big enough to hold any
    106   1.1  christos    arithmetic types we need to deal with.  Can be assumed to be compatible
    107   1.1  christos    with bfd_vma in the same way that signed and unsigned ints are compatible
    108   1.1  christos    (as parameters, in assignment, etc).  */
    109  1.10  christos typedef int64_t bfd_signed_vma;
    110  1.10  christos 
    111  1.10  christos typedef uint64_t bfd_size_type;
    112  1.10  christos typedef uint64_t symvalue;
    113  1.10  christos 
    114  1.10  christos #else /* not BFD64  */
    115  1.10  christos 
    116  1.11  christos typedef uint32_t bfd_vma;
    117  1.11  christos typedef int32_t bfd_signed_vma;
    118  1.11  christos typedef uint32_t bfd_size_type;
    119  1.11  christos typedef uint32_t symvalue;
    120   1.1  christos 
    121   1.1  christos #endif /* not BFD64  */
    122   1.1  christos 
    123   1.1  christos #define HALF_BFD_SIZE_TYPE \
    124   1.1  christos   (((bfd_size_type) 1) << (8 * sizeof (bfd_size_type) / 2))
    125   1.1  christos 
    126   1.1  christos /* An offset into a file.  BFD always uses the largest possible offset
    127   1.1  christos    based on the build time availability of fseek, fseeko, or fseeko64.  */
    128   1.1  christos typedef @bfd_file_ptr@ file_ptr;
    129  1.10  christos typedef @bfd_ufile_ptr@ ufile_ptr;
    130   1.1  christos 
    131  1.11  christos typedef uint32_t flagword;	/* 32 bits of flags */
    132  1.11  christos typedef uint8_t bfd_byte;
    133   1.1  christos 
    134  1.11  christos /* Forward declarations.  */
    135  1.11  christos typedef struct bfd bfd;
    136  1.11  christos struct bfd_link_info;
    137  1.11  christos struct bfd_link_hash_entry;
    138   1.6  christos typedef struct bfd_section *sec_ptr;
    139  1.11  christos typedef struct reloc_cache_entry arelent;
    140  1.11  christos struct orl;
    141   1.1  christos 
    142   1.1  christos #define	align_power(addr, align)	\
    143   1.6  christos   (((addr) + ((bfd_vma) 1 << (align)) - 1) & (-((bfd_vma) 1 << (align))))
    144   1.1  christos 
    145   1.6  christos /* Align an address upward to a boundary, expressed as a number of bytes.
    146   1.6  christos    E.g. align to an 8-byte boundary with argument of 8.  Take care never
    147   1.6  christos    to wrap around if the address is within boundary-1 of the end of the
    148   1.6  christos    address space.  */
    149   1.6  christos #define BFD_ALIGN(this, boundary)					  \
    150   1.6  christos   ((((bfd_vma) (this) + (boundary) - 1) >= (bfd_vma) (this))		  \
    151   1.6  christos    ? (((bfd_vma) (this) + ((boundary) - 1)) & ~ (bfd_vma) ((boundary)-1)) \
    152   1.6  christos    : ~ (bfd_vma) 0)
    153  1.10  christos 
    154  1.10  christos /* Return TRUE if the start of STR matches PREFIX, FALSE otherwise.  */
    155  1.10  christos 
    156  1.10  christos static inline bool
    157  1.10  christos startswith (const char *str, const char *prefix)
    158  1.10  christos {
    159  1.10  christos   return strncmp (str, prefix, strlen (prefix)) == 0;
    160  1.10  christos }
    161  1.11  christos 
    162