Radix cross Linux

The main Radix cross Linux repository contains the build scripts of packages, which have the most complete and common functionality for desktop machines

452 Commits   2 Branches   1 Tag
    33         kx /* Main header file for the bfd library -- portable access to object files.
    33         kx 
    33         kx    Copyright (C) 1990-2023 Free Software Foundation, Inc.
    33         kx 
    33         kx    Contributed by Cygnus Support.
    33         kx 
    33         kx    This file is part of BFD, the Binary File Descriptor library.
    33         kx 
    33         kx    This program is free software; you can redistribute it and/or modify
    33         kx    it under the terms of the GNU General Public License as published by
    33         kx    the Free Software Foundation; either version 3 of the License, or
    33         kx    (at your option) any later version.
    33         kx 
    33         kx    This program is distributed in the hope that it will be useful,
    33         kx    but WITHOUT ANY WARRANTY; without even the implied warranty of
    33         kx    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    33         kx    GNU General Public License for more details.
    33         kx 
    33         kx    You should have received a copy of the GNU General Public License
    33         kx    along with this program; if not, write to the Free Software
    33         kx    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
    33         kx 
    33         kx #ifndef __BFD_H_SEEN__
    33         kx #define __BFD_H_SEEN__
    33         kx 
    33         kx #ifdef __cplusplus
    33         kx extern "C" {
    33         kx #endif
    33         kx 
    33         kx #include "ansidecl.h"
    33         kx #include "symcat.h"
    33         kx #include <stdint.h>
    33         kx #include <stdbool.h>
    33         kx #include "diagnostics.h"
    33         kx #include <stdarg.h>
    33         kx #include <string.h>
    33         kx #include <sys/stat.h>
    33         kx 
    33         kx #if defined (__STDC__) || defined (ALMOST_STDC) || defined (HAVE_STRINGIZE)
    33         kx #ifndef SABER
    33         kx /* This hack is to avoid a problem with some strict ANSI C preprocessors.
    33         kx    The problem is, "32_" is not a valid preprocessing token, and we don't
    33         kx    want extra underscores (e.g., "nlm_32_").  The XCONCAT2 macro will
    33         kx    cause the inner CONCAT2 macros to be evaluated first, producing
    33         kx    still-valid pp-tokens.  Then the final concatenation can be done.  */
    33         kx #undef CONCAT4
    33         kx #define CONCAT4(a,b,c,d) XCONCAT2(CONCAT2(a,b),CONCAT2(c,d))
    33         kx #endif
    33         kx #endif
    33         kx 
    33         kx /* This is a utility macro to handle the situation where the code
    33         kx    wants to place a constant string into the code, followed by a
    33         kx    comma and then the length of the string.  Doing this by hand
    33         kx    is error prone, so using this macro is safer.  */
    33         kx #define STRING_COMMA_LEN(STR) (STR), (sizeof (STR) - 1)
    33         kx 
    33         kx #define BFD_SUPPORTS_PLUGINS @supports_plugins@
    33         kx 
    33         kx /* The word size used by BFD on the host.  This may be 64 with a 32
    33         kx    bit target if the host is 64 bit, or if other 64 bit targets have
    33         kx    been selected with --enable-targets, or if --enable-64-bit-bfd.  */
    33         kx #define BFD_ARCH_SIZE @wordsize@
    33         kx 
    33         kx /* The word size of the default bfd target.  */
    33         kx #define BFD_DEFAULT_TARGET_SIZE @bfd_default_target_size@
    33         kx 
    33         kx #include <inttypes.h>
    33         kx 
    33         kx #if BFD_ARCH_SIZE >= 64
    33         kx #define BFD64
    33         kx #endif
    33         kx 
    33         kx /* Forward declaration.  */
    33         kx typedef struct bfd bfd;
    33         kx 
    33         kx /* Boolean type used in bfd.
    33         kx    General rule: Functions which are bfd_boolean return TRUE on
    33         kx    success and FALSE on failure (unless they're a predicate).  */
    33         kx 
    33         kx #ifdef POISON_BFD_BOOLEAN
    33         kx # pragma GCC poison bfd_boolean
    33         kx #else
    33         kx # define bfd_boolean bool
    33         kx # undef FALSE
    33         kx # undef TRUE
    33         kx # define FALSE 0
    33         kx # define TRUE 1
    33         kx #endif
    33         kx 
    33         kx /* Silence "applying zero offset to null pointer" UBSAN warnings.  */
    33         kx #define PTR_ADD(P,A) ((A) != 0 ? (P) + (A) : (P))
    33         kx /* Also prevent non-zero offsets from being applied to a null pointer.  */
    33         kx #define NPTR_ADD(P,A) ((P) != NULL ? (P) + (A) : (P))
    33         kx 
    33         kx #ifdef BFD64
    33         kx 
    33         kx /* Represent a target address.  Also used as a generic unsigned type
    33         kx    which is guaranteed to be big enough to hold any arithmetic types
    33         kx    we need to deal with.  */
    33         kx typedef uint64_t bfd_vma;
    33         kx 
    33         kx /* A generic signed type which is guaranteed to be big enough to hold any
    33         kx    arithmetic types we need to deal with.  Can be assumed to be compatible
    33         kx    with bfd_vma in the same way that signed and unsigned ints are compatible
    33         kx    (as parameters, in assignment, etc).  */
    33         kx typedef int64_t bfd_signed_vma;
    33         kx 
    33         kx typedef uint64_t bfd_size_type;
    33         kx typedef uint64_t symvalue;
    33         kx 
    33         kx #else /* not BFD64  */
    33         kx 
    33         kx typedef unsigned long bfd_vma;
    33         kx typedef long bfd_signed_vma;
    33         kx typedef unsigned long symvalue;
    33         kx typedef unsigned long bfd_size_type;
    33         kx 
    33         kx #endif /* not BFD64  */
    33         kx 
    33         kx #define HALF_BFD_SIZE_TYPE \
    33         kx   (((bfd_size_type) 1) << (8 * sizeof (bfd_size_type) / 2))
    33         kx 
    33         kx /* An offset into a file.  BFD always uses the largest possible offset
    33         kx    based on the build time availability of fseek, fseeko, or fseeko64.  */
    33         kx typedef @bfd_file_ptr@ file_ptr;
    33         kx typedef @bfd_ufile_ptr@ ufile_ptr;
    33         kx 
    33         kx extern void bfd_sprintf_vma (bfd *, char *, bfd_vma);
    33         kx extern void bfd_fprintf_vma (bfd *, void *, bfd_vma);
    33         kx 
    33         kx #define bfd_printf_vma(abfd,x) bfd_fprintf_vma (abfd,stdout,x)
    33         kx 
    33         kx typedef unsigned int flagword;	/* 32 bits of flags */
    33         kx typedef unsigned char bfd_byte;
    33         kx 
    33         kx /* File formats.  */
    33         kx 
    33         kx typedef enum bfd_format
    33         kx {
    33         kx   bfd_unknown = 0,	/* File format is unknown.  */
    33         kx   bfd_object,		/* Linker/assembler/compiler output.  */
    33         kx   bfd_archive,		/* Object archive file.  */
    33         kx   bfd_core,		/* Core dump.  */
    33         kx   bfd_type_end		/* Marks the end; don't use it!  */
    33         kx }
    33         kx bfd_format;
    33         kx 
    33         kx /* Symbols and relocation.  */
    33         kx 
    33         kx /* A count of carsyms (canonical archive symbols).  */
    33         kx typedef unsigned long symindex;
    33         kx 
    33         kx #define BFD_NO_MORE_SYMBOLS ((symindex) ~0)
    33         kx 
    33         kx /* A canonical archive symbol.  */
    33         kx /* This is a type pun with struct ranlib on purpose!  */
    33         kx typedef struct carsym
    33         kx {
    33         kx   const char *name;
    33         kx   file_ptr file_offset;	/* Look here to find the file.  */
    33         kx }
    33         kx carsym;			/* To make these you call a carsymogen.  */
    33         kx 
    33         kx /* Used in generating armaps (archive tables of contents).
    33         kx    Perhaps just a forward definition would do?  */
    33         kx struct orl		/* Output ranlib.  */
    33         kx {
    33         kx   char **name;		/* Symbol name.  */
    33         kx   union
    33         kx   {
    33         kx     file_ptr pos;
    33         kx     bfd *abfd;
    33         kx   } u;			/* bfd* or file position.  */
    33         kx   int namidx;		/* Index into string table.  */
    33         kx };
    33         kx 
    33         kx /* Linenumber stuff.  */
    33         kx typedef struct lineno_cache_entry
    33         kx {
    33         kx   unsigned int line_number;	/* Linenumber from start of function.  */
    33         kx   union
    33         kx   {
    33         kx     struct bfd_symbol *sym;	/* Function name.  */
    33         kx     bfd_vma offset;		/* Offset into section.  */
    33         kx   } u;
    33         kx }
    33         kx alent;
    33         kx 
    33         kx /* Object and core file sections.  */
    33         kx typedef struct bfd_section *sec_ptr;
    33         kx 
    33         kx #define	align_power(addr, align)	\
    33         kx   (((addr) + ((bfd_vma) 1 << (align)) - 1) & (-((bfd_vma) 1 << (align))))
    33         kx 
    33         kx /* Align an address upward to a boundary, expressed as a number of bytes.
    33         kx    E.g. align to an 8-byte boundary with argument of 8.  Take care never
    33         kx    to wrap around if the address is within boundary-1 of the end of the
    33         kx    address space.  */
    33         kx #define BFD_ALIGN(this, boundary)					  \
    33         kx   ((((bfd_vma) (this) + (boundary) - 1) >= (bfd_vma) (this))		  \
    33         kx    ? (((bfd_vma) (this) + ((boundary) - 1)) & ~ (bfd_vma) ((boundary)-1)) \
    33         kx    : ~ (bfd_vma) 0)
    33         kx 
    33         kx typedef enum bfd_print_symbol
    33         kx {
    33         kx   bfd_print_symbol_name,
    33         kx   bfd_print_symbol_more,
    33         kx   bfd_print_symbol_all
    33         kx } bfd_print_symbol_type;
    33         kx 
    33         kx /* Information about a symbol that nm needs.  */
    33         kx 
    33         kx typedef struct _symbol_info
    33         kx {
    33         kx   symvalue value;
    33         kx   char type;
    33         kx   const char *name;		/* Symbol name.  */
    33         kx   unsigned char stab_type;	/* Stab type.  */
    33         kx   char stab_other;		/* Stab other.  */
    33         kx   short stab_desc;		/* Stab desc.  */
    33         kx   const char *stab_name;	/* String for stab type.  */
    33         kx } symbol_info;
    33         kx 
    33         kx /* Get the name of a stabs type code.  */
    33         kx 
    33         kx extern const char *bfd_get_stab_name (int);
    33         kx 
    33         kx /* Hash table routines.  There is no way to free up a hash table.  */
    33         kx 
    33         kx /* An element in the hash table.  Most uses will actually use a larger
    33         kx    structure, and an instance of this will be the first field.  */
    33         kx 
    33         kx struct bfd_hash_entry
    33         kx {
    33         kx   /* Next entry for this hash code.  */
    33         kx   struct bfd_hash_entry *next;
    33         kx   /* String being hashed.  */
    33         kx   const char *string;
    33         kx   /* Hash code.  This is the full hash code, not the index into the
    33         kx      table.  */
    33         kx   unsigned long hash;
    33         kx };
    33         kx 
    33         kx /* A hash table.  */
    33         kx 
    33         kx struct bfd_hash_table
    33         kx {
    33         kx   /* The hash array.  */
    33         kx   struct bfd_hash_entry **table;
    33         kx   /* A function used to create new elements in the hash table.  The
    33         kx      first entry is itself a pointer to an element.  When this
    33         kx      function is first invoked, this pointer will be NULL.  However,
    33         kx      having the pointer permits a hierarchy of method functions to be
    33         kx      built each of which calls the function in the superclass.  Thus
    33         kx      each function should be written to allocate a new block of memory
    33         kx      only if the argument is NULL.  */
    33         kx   struct bfd_hash_entry *(*newfunc)
    33         kx     (struct bfd_hash_entry *, struct bfd_hash_table *, const char *);
    33         kx   /* An objalloc for this hash table.  This is a struct objalloc *,
    33         kx      but we use void * to avoid requiring the inclusion of objalloc.h.  */
    33         kx   void *memory;
    33         kx   /* The number of slots in the hash table.  */
    33         kx   unsigned int size;
    33         kx   /* The number of entries in the hash table.  */
    33         kx   unsigned int count;
    33         kx   /* The size of elements.  */
    33         kx   unsigned int entsize;
    33         kx   /* If non-zero, don't grow the hash table.  */
    33         kx   unsigned int frozen:1;
    33         kx };
    33         kx 
    33         kx /* Initialize a hash table.  */
    33         kx extern bool bfd_hash_table_init
    33         kx   (struct bfd_hash_table *,
    33         kx    struct bfd_hash_entry *(*) (struct bfd_hash_entry *,
    33         kx 			       struct bfd_hash_table *,
    33         kx 			       const char *),
    33         kx    unsigned int);
    33         kx 
    33         kx /* Initialize a hash table specifying a size.  */
    33         kx extern bool bfd_hash_table_init_n
    33         kx   (struct bfd_hash_table *,
    33         kx    struct bfd_hash_entry *(*) (struct bfd_hash_entry *,
    33         kx 			       struct bfd_hash_table *,
    33         kx 			       const char *),
    33         kx    unsigned int, unsigned int);
    33         kx 
    33         kx /* Free up a hash table.  */
    33         kx extern void bfd_hash_table_free
    33         kx   (struct bfd_hash_table *);
    33         kx 
    33         kx /* Look up a string in a hash table.  If CREATE is TRUE, a new entry
    33         kx    will be created for this string if one does not already exist.  The
    33         kx    COPY argument must be TRUE if this routine should copy the string
    33         kx    into newly allocated memory when adding an entry.  */
    33         kx extern struct bfd_hash_entry *bfd_hash_lookup
    33         kx   (struct bfd_hash_table *, const char *, bool create, bool copy);
    33         kx 
    33         kx /* Insert an entry in a hash table.  */
    33         kx extern struct bfd_hash_entry *bfd_hash_insert
    33         kx   (struct bfd_hash_table *, const char *, unsigned long);
    33         kx 
    33         kx /* Rename an entry in a hash table.  */
    33         kx extern void bfd_hash_rename
    33         kx   (struct bfd_hash_table *, const char *, struct bfd_hash_entry *);
    33         kx 
    33         kx /* Replace an entry in a hash table.  */
    33         kx extern void bfd_hash_replace
    33         kx   (struct bfd_hash_table *, struct bfd_hash_entry *old,
    33         kx    struct bfd_hash_entry *nw);
    33         kx 
    33         kx /* Base method for creating a hash table entry.  */
    33         kx extern struct bfd_hash_entry *bfd_hash_newfunc
    33         kx   (struct bfd_hash_entry *, struct bfd_hash_table *, const char *);
    33         kx 
    33         kx /* Grab some space for a hash table entry.  */
    33         kx extern void *bfd_hash_allocate
    33         kx   (struct bfd_hash_table *, unsigned int);
    33         kx 
    33         kx /* Traverse a hash table in a random order, calling a function on each
    33         kx    element.  If the function returns FALSE, the traversal stops.  The
    33         kx    INFO argument is passed to the function.  */
    33         kx extern void bfd_hash_traverse
    33         kx   (struct bfd_hash_table *,
    33         kx    bool (*) (struct bfd_hash_entry *, void *),
    33         kx    void *info);
    33         kx 
    33         kx /* Allows the default size of a hash table to be configured. New hash
    33         kx    tables allocated using bfd_hash_table_init will be created with
    33         kx    this size.  */
    33         kx extern unsigned long bfd_hash_set_default_size (unsigned long);
    33         kx 
    33         kx /* This structure is used to keep track of stabs in sections
    33         kx    information while linking.  */
    33         kx 
    33         kx struct stab_info
    33         kx {
    33         kx   /* A hash table used to hold stabs strings.  */
    33         kx   struct bfd_strtab_hash *strings;
    33         kx   /* The header file hash table.  */
    33         kx   struct bfd_hash_table includes;
    33         kx   /* The first .stabstr section.  */
    33         kx   struct bfd_section *stabstr;
    33         kx };
    33         kx 
    33         kx #define COFF_SWAP_TABLE (void *) &bfd_coff_std_swap_table
    33         kx 
    33         kx /* User program access to BFD facilities.  */
    33         kx 
    33         kx /* Direct I/O routines, for programs which know more about the object
    33         kx    file than BFD does.  Use higher level routines if possible.  */
    33         kx 
    33         kx extern bfd_size_type bfd_bread (void *, bfd_size_type, bfd *);
    33         kx extern bfd_size_type bfd_bwrite (const void *, bfd_size_type, bfd *);
    33         kx extern int bfd_seek (bfd *, file_ptr, int);
    33         kx extern file_ptr bfd_tell (bfd *);
    33         kx extern int bfd_flush (bfd *);
    33         kx extern int bfd_stat (bfd *, struct stat *);
    33         kx 
    33         kx /* Deprecated old routines.  */
    33         kx #if __GNUC__
    33         kx #define bfd_read(BUF, ELTSIZE, NITEMS, ABFD)				\
    33         kx   (_bfd_warn_deprecated ("bfd_read", __FILE__, __LINE__, __FUNCTION__),	\
    33         kx    bfd_bread ((BUF), (ELTSIZE) * (NITEMS), (ABFD)))
    33         kx #define bfd_write(BUF, ELTSIZE, NITEMS, ABFD)				\
    33         kx   (_bfd_warn_deprecated ("bfd_write", __FILE__, __LINE__, __FUNCTION__), \
    33         kx    bfd_bwrite ((BUF), (ELTSIZE) * (NITEMS), (ABFD)))
    33         kx #else
    33         kx #define bfd_read(BUF, ELTSIZE, NITEMS, ABFD)				\
    33         kx   (_bfd_warn_deprecated ("bfd_read", (const char *) 0, 0, (const char *) 0), \
    33         kx    bfd_bread ((BUF), (ELTSIZE) * (NITEMS), (ABFD)))
    33         kx #define bfd_write(BUF, ELTSIZE, NITEMS, ABFD)				\
    33         kx   (_bfd_warn_deprecated ("bfd_write", (const char *) 0, 0, (const char *) 0),\
    33         kx    bfd_bwrite ((BUF), (ELTSIZE) * (NITEMS), (ABFD)))
    33         kx #endif
    33         kx extern void _bfd_warn_deprecated (const char *, const char *, int, const char *);
    33         kx 
    33         kx extern bool bfd_cache_close
    33         kx   (bfd *abfd);
    33         kx /* NB: This declaration should match the autogenerated one in libbfd.h.  */
    33         kx 
    33         kx extern bool bfd_cache_close_all (void);
    33         kx 
    33         kx extern bool bfd_record_phdr
    33         kx   (bfd *, unsigned long, bool, flagword, bool, bfd_vma,
    33         kx    bool, bool, unsigned int, struct bfd_section **);
    33         kx 
    33         kx /* Byte swapping routines.  */
    33         kx 
    33         kx uint64_t bfd_getb64 (const void *);
    33         kx uint64_t bfd_getl64 (const void *);
    33         kx int64_t bfd_getb_signed_64 (const void *);
    33         kx int64_t bfd_getl_signed_64 (const void *);
    33         kx bfd_vma bfd_getb32 (const void *);
    33         kx bfd_vma bfd_getl32 (const void *);
    33         kx bfd_signed_vma bfd_getb_signed_32 (const void *);
    33         kx bfd_signed_vma bfd_getl_signed_32 (const void *);
    33         kx bfd_vma bfd_getb16 (const void *);
    33         kx bfd_vma bfd_getl16 (const void *);
    33         kx bfd_signed_vma bfd_getb_signed_16 (const void *);
    33         kx bfd_signed_vma bfd_getl_signed_16 (const void *);
    33         kx void bfd_putb64 (uint64_t, void *);
    33         kx void bfd_putl64 (uint64_t, void *);
    33         kx void bfd_putb32 (bfd_vma, void *);
    33         kx void bfd_putl32 (bfd_vma, void *);
    33         kx void bfd_putb24 (bfd_vma, void *);
    33         kx void bfd_putl24 (bfd_vma, void *);
    33         kx void bfd_putb16 (bfd_vma, void *);
    33         kx void bfd_putl16 (bfd_vma, void *);
    33         kx 
    33         kx /* Byte swapping routines which take size and endiannes as arguments.  */
    33         kx 
    33         kx uint64_t bfd_get_bits (const void *, int, bool);
    33         kx void bfd_put_bits (uint64_t, void *, int, bool);
    33         kx 
    33         kx 
    33         kx /* mmap hacks */
    33         kx 
    33         kx struct _bfd_window_internal;
    33         kx typedef struct _bfd_window_internal bfd_window_internal;
    33         kx 
    33         kx typedef struct _bfd_window
    33         kx {
    33         kx   /* What the user asked for.  */
    33         kx   void *data;
    33         kx   bfd_size_type size;
    33         kx   /* The actual window used by BFD.  Small user-requested read-only
    33         kx      regions sharing a page may share a single window into the object
    33         kx      file.  Read-write versions shouldn't until I've fixed things to
    33         kx      keep track of which portions have been claimed by the
    33         kx      application; don't want to give the same region back when the
    33         kx      application wants two writable copies!  */
    33         kx   struct _bfd_window_internal *i;
    33         kx }
    33         kx bfd_window;
    33         kx 
    33         kx extern void bfd_init_window
    33         kx   (bfd_window *);
    33         kx extern void bfd_free_window
    33         kx   (bfd_window *);
    33         kx extern bool bfd_get_file_window
    33         kx   (bfd *, file_ptr, bfd_size_type, bfd_window *, bool);
    33         kx 
    33         kx /* Externally visible ELF routines.  */
    33         kx 
    33         kx /* Create a new BFD as if by bfd_openr.  Rather than opening a file,
    33         kx    reconstruct an ELF file by reading the segments out of remote
    33         kx    memory based on the ELF file header at EHDR_VMA and the ELF program
    33         kx    headers it points to.  If non-zero, SIZE is the known extent of the
    33         kx    object.  If not null, *LOADBASEP is filled in with the difference
    33         kx    between the VMAs from which the segments were read, and the VMAs
    33         kx    the file headers (and hence BFD's idea of each section's VMA) put
    33         kx    them at.
    33         kx 
    33         kx    The function TARGET_READ_MEMORY is called to copy LEN bytes from
    33         kx    the remote memory at target address VMA into the local buffer at
    33         kx    MYADDR; it should return zero on success or an `errno' code on
    33         kx    failure.  TEMPL must be a BFD for a target with the word size and
    33         kx    byte order found in the remote memory.  */
    33         kx extern bfd *bfd_elf_bfd_from_remote_memory
    33         kx   (bfd *templ, bfd_vma ehdr_vma, bfd_size_type size, bfd_vma *loadbasep,
    33         kx    int (*target_read_memory) (bfd_vma vma, bfd_byte *myaddr,
    33         kx 			      bfd_size_type len));
    33         kx 
    33         kx /* Forward declarations.  */
    33         kx struct ecoff_debug_info;
    33         kx struct ecoff_debug_swap;
    33         kx struct ecoff_extr;
    33         kx struct bfd_link_info;
    33         kx struct bfd_link_hash_entry;
    33         kx 
    33         kx /* Return TRUE if the start of STR matches PREFIX, FALSE otherwise.  */
    33         kx 
    33         kx static inline bool
    33         kx startswith (const char *str, const char *prefix)
    33         kx {
    33         kx   return strncmp (str, prefix, strlen (prefix)) == 0;
    33         kx }