Blame libelf/libelfP.h

Packit 032894
/* Internal interfaces for libelf.
Packit 032894
   Copyright (C) 1998-2010, 2015, 2016 Red Hat, Inc.
Packit 032894
   This file is part of elfutils.
Packit 032894
   Contributed by Ulrich Drepper <drepper@redhat.com>, 1998.
Packit 032894
Packit 032894
   This file is free software; you can redistribute it and/or modify
Packit 032894
   it under the terms of either
Packit 032894
Packit 032894
     * the GNU Lesser General Public License as published by the Free
Packit 032894
       Software Foundation; either version 3 of the License, or (at
Packit 032894
       your option) any later version
Packit 032894
Packit 032894
   or
Packit 032894
Packit 032894
     * the GNU General Public License as published by the Free
Packit 032894
       Software Foundation; either version 2 of the License, or (at
Packit 032894
       your option) any later version
Packit 032894
Packit 032894
   or both in parallel, as here.
Packit 032894
Packit 032894
   elfutils is distributed in the hope that it will be useful, but
Packit 032894
   WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 032894
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 032894
   General Public License for more details.
Packit 032894
Packit 032894
   You should have received copies of the GNU General Public License and
Packit 032894
   the GNU Lesser General Public License along with this program.  If
Packit 032894
   not, see <http://www.gnu.org/licenses/>.  */
Packit 032894
Packit 032894
#ifndef _LIBELFP_H
Packit 032894
#define _LIBELFP_H 1
Packit 032894
Packit 032894
#include <ar.h>
Packit 032894
#include <gelf.h>
Packit 032894
Packit 032894
#include <errno.h>
Packit 032894
#include <stdbool.h>
Packit 032894
#include <stdint.h>
Packit 032894
#include <stdio.h>
Packit 032894
#include <string.h>
Packit 032894
Packit 032894
/* gettext helper macros.  */
Packit 032894
#define _(Str) dgettext ("elfutils", Str)
Packit 032894
Packit 032894
Packit 032894
/* Helper Macros to write 32 bit and 64 bit functions.  */
Packit 032894
#define __elfw2_(Bits, Name) __elf##Bits##_##Name
Packit 032894
#define elfw2_(Bits, Name) elf##Bits##_##Name
Packit 032894
#define ElfW2_(Bits, Name) Elf##Bits##_##Name
Packit 032894
#define ELFW2_(Bits, Name) ELF##Bits##_##Name
Packit 032894
#define ELFW_(Name, Bits) Name##Bits
Packit 032894
#define __elfw2(Bits, Name) __elfw2_(Bits, Name)
Packit 032894
#define elfw2(Bits, Name) elfw2_(Bits, Name)
Packit 032894
#define ElfW2(Bits, Name) ElfW2_(Bits, Name)
Packit 032894
#define ELFW2(Bits, Name) ELFW2_(Bits, Name)
Packit 032894
#define ELFW(Name, Bits)  ELFW_(Name, Bits)
Packit 032894
Packit 032894
Packit 032894
/* Sizes of the external types, for 32 bits objects.  */
Packit 032894
#define ELF32_FSZ_ADDR   4
Packit 032894
#define ELF32_FSZ_OFF    4
Packit 032894
#define ELF32_FSZ_HALF   2
Packit 032894
#define ELF32_FSZ_WORD   4
Packit 032894
#define ELF32_FSZ_SWORD  4
Packit 032894
#define ELF32_FSZ_XWORD  8
Packit 032894
#define ELF32_FSZ_SXWORD 8
Packit 032894
Packit 032894
/* Same for 64 bits objects.  */
Packit 032894
#define ELF64_FSZ_ADDR   8
Packit 032894
#define ELF64_FSZ_OFF    8
Packit 032894
#define ELF64_FSZ_HALF   2
Packit 032894
#define ELF64_FSZ_WORD   4
Packit 032894
#define ELF64_FSZ_SWORD  4
Packit 032894
#define ELF64_FSZ_XWORD  8
Packit 032894
#define ELF64_FSZ_SXWORD 8
Packit 032894
Packit 032894
Packit 032894
/* This is an extension of the ELF_F_* enumeration.  The values here are
Packit 032894
   not part of the library interface, they are only used internally.  */
Packit 032894
enum
Packit 032894
{
Packit 032894
  ELF_F_MMAPPED = 0x40,
Packit 032894
  ELF_F_MALLOCED = 0x80,
Packit 032894
  ELF_F_FILEDATA = 0x100
Packit 032894
};
Packit 032894
Packit 032894
Packit 032894
/* Get definition of all the external types.  */
Packit 032894
#include "exttypes.h"
Packit 032894
Packit 032894
Packit 032894
/* Error values.  */
Packit 032894
enum
Packit 032894
{
Packit 032894
  ELF_E_NOERROR = 0,
Packit 032894
  ELF_E_UNKNOWN_ERROR,
Packit 032894
  ELF_E_UNKNOWN_VERSION,
Packit 032894
  ELF_E_UNKNOWN_TYPE,
Packit 032894
  ELF_E_INVALID_HANDLE,
Packit 032894
  ELF_E_SOURCE_SIZE,
Packit 032894
  ELF_E_DEST_SIZE,
Packit 032894
  ELF_E_INVALID_ENCODING,
Packit 032894
  ELF_E_NOMEM,
Packit 032894
  ELF_E_INVALID_FILE,
Packit 032894
  ELF_E_INVALID_ELF,
Packit 032894
  ELF_E_INVALID_OP,
Packit 032894
  ELF_E_NO_VERSION,
Packit 032894
  ELF_E_INVALID_CMD,
Packit 032894
  ELF_E_RANGE,
Packit 032894
  ELF_E_ARCHIVE_FMAG,
Packit 032894
  ELF_E_INVALID_ARCHIVE,
Packit 032894
  ELF_E_NO_ARCHIVE,
Packit 032894
  ELF_E_NO_INDEX,
Packit 032894
  ELF_E_READ_ERROR,
Packit 032894
  ELF_E_WRITE_ERROR,
Packit 032894
  ELF_E_INVALID_CLASS,
Packit 032894
  ELF_E_INVALID_INDEX,
Packit 032894
  ELF_E_INVALID_OPERAND,
Packit 032894
  ELF_E_INVALID_SECTION,
Packit 032894
  ELF_E_INVALID_COMMAND,
Packit 032894
  ELF_E_WRONG_ORDER_EHDR,
Packit 032894
  ELF_E_FD_DISABLED,
Packit 032894
  ELF_E_FD_MISMATCH,
Packit 032894
  ELF_E_OFFSET_RANGE,
Packit 032894
  ELF_E_NOT_NUL_SECTION,
Packit 032894
  ELF_E_DATA_MISMATCH,
Packit 032894
  ELF_E_INVALID_SECTION_HEADER,
Packit 032894
  ELF_E_INVALID_DATA,
Packit 032894
  ELF_E_DATA_ENCODING,
Packit 032894
  ELF_E_SECTION_TOO_SMALL,
Packit 032894
  ELF_E_INVALID_ALIGN,
Packit 032894
  ELF_E_INVALID_SHENTSIZE,
Packit 032894
  ELF_E_UPDATE_RO,
Packit 032894
  ELF_E_NOFILE,
Packit 032894
  ELF_E_GROUP_NOT_REL,
Packit 032894
  ELF_E_INVALID_PHDR,
Packit 032894
  ELF_E_NO_PHDR,
Packit 032894
  ELF_E_INVALID_OFFSET,
Packit 032894
  ELF_E_INVALID_SECTION_TYPE,
Packit 032894
  ELF_E_INVALID_SECTION_FLAGS,
Packit 032894
  ELF_E_NOT_COMPRESSED,
Packit 032894
  ELF_E_ALREADY_COMPRESSED,
Packit 032894
  ELF_E_UNKNOWN_COMPRESSION_TYPE,
Packit 032894
  ELF_E_COMPRESS_ERROR,
Packit 032894
  ELF_E_DECOMPRESS_ERROR,
Packit 032894
  /* Keep this as the last entry.  */
Packit 032894
  ELF_E_NUM
Packit 032894
};
Packit 032894
Packit 032894
Packit 032894
/* The visible `Elf_Data' type is not sufficent for some operations due
Packit 032894
   to a misdesigned interface.  Extend it for internal purposes.  */
Packit 032894
typedef struct
Packit 032894
{
Packit 032894
  Elf_Data d;
Packit 032894
  Elf_Scn *s;
Packit 032894
} Elf_Data_Scn;
Packit 032894
Packit 032894
Packit 032894
/* List of `Elf_Data' descriptors.  This is what makes up the section
Packit 032894
   contents.  */
Packit 032894
typedef struct Elf_Data_List
Packit 032894
{
Packit 032894
  /* `data' *must* be the first element in the struct.  */
Packit 032894
  Elf_Data_Scn data;
Packit 032894
  struct Elf_Data_List *next;
Packit 032894
  int flags;
Packit 032894
} Elf_Data_List;
Packit 032894
Packit 032894
Packit 032894
/* Descriptor for ELF section.  */
Packit 032894
struct Elf_Scn
Packit 032894
{
Packit 032894
  /* We have to distinguish several different situations:
Packit 032894
Packit 032894
     1. the section is user created.  Therefore there is no file or memory
Packit 032894
        region to read the data from.  Here we have two different subcases:
Packit 032894
Packit 032894
        a) data was not yet added (before the first `elf_newdata' call)
Packit 032894
Packit 032894
        b) at least one data set is available
Packit 032894
Packit 032894
     2. this is a section from a file/memory region.  We have to read the
Packit 032894
        current content in one data block if we have to.  But we don't
Packit 032894
        read the data until it is necessary.  So we have the subcases:
Packit 032894
Packit 032894
        a) the section in the file has size zero (for whatever reason)
Packit 032894
Packit 032894
        b) the data of the file is not (yet) read
Packit 032894
Packit 032894
        c) the data is read and available.
Packit 032894
Packit 032894
     In addition to this we have different data sets, the raw and the converted
Packit 032894
     data.  This distinction only exists for the data read from the file.
Packit 032894
     All user-added data set (all but the first when read from the file or
Packit 032894
     all of them for user-create sections) are the same in both formats.
Packit 032894
     We don't create the converted data before it is necessary.
Packit 032894
Packit 032894
     The `data_read' element signals whether data is available in the
Packit 032894
     raw format.
Packit 032894
Packit 032894
     If there is data from the file/memory region or if read one data
Packit 032894
     set is added the `rawdata_list_read' pointer in non-NULL and points
Packit 032894
     to the last filled data set.  `raw_datalist_rear' is therefore NULL
Packit 032894
     only if there is no data set at all.
Packit 032894
Packit 032894
     This so far allows to distinguish all but two cases (given that the
Packit 032894
     `rawdata_list' and `data_list' entries are initialized to zero) is
Packit 032894
     between not yet loaded data from the file/memory region and a section
Packit 032894
     with zero size and type ELF_T_BYTE.   */
Packit 032894
  Elf_Data_List data_list;	/* List of data buffers.  */
Packit 032894
  Elf_Data_List *data_list_rear; /* Pointer to the rear of the data list. */
Packit 032894
Packit 032894
  Elf_Data_Scn rawdata;		/* Uninterpreted data of the section.  */
Packit 032894
Packit 032894
  int data_read;		/* Nonzero if the section was created by the
Packit 032894
				   user or if the data from the file/memory
Packit 032894
				   is read.  */
Packit 032894
  int shndx_index;		/* Index of the extended section index
Packit 032894
				   table for this symbol table (if this
Packit 032894
				   section is a symbol table).  */
Packit 032894
Packit 032894
  size_t index;			/* Index of this section.  */
Packit 032894
  struct Elf *elf;		/* The underlying ELF file.  */
Packit 032894
Packit 032894
  union
Packit 032894
  {
Packit 032894
    Elf32_Shdr *e32;		/* Pointer to 32bit section header.  */
Packit 032894
    Elf64_Shdr *e64;		/* Pointer to 64bit section header.  */
Packit 032894
  } shdr;
Packit 032894
Packit 032894
  unsigned int shdr_flags;	/* Section header modified?  */
Packit 032894
  unsigned int flags;		/* Section changed in size?
Packit 032894
				   ELF_F_MALLOCED for a Elf_Data_Chunk
Packit 032894
				   dummy_scn means the rawchunks
Packit 032894
				   data.d.d_buf was malloced. For normal
Packit 032894
				   sections it means rawdata_base was
Packit 032894
				   malloced (by elf_compress) even if
Packit 032894
				   the Elf was mmapped.  */
Packit 032894
Packit 032894
  char *rawdata_base;		/* The unmodified data of the section.  */
Packit 032894
  char *data_base;		/* The converted data of the section.  */
Packit 032894
Packit 032894
  char *zdata_base;		/* The uncompressed data of the section.  */
Packit 032894
  size_t zdata_size;		/* If zdata_base != NULL, the size of data.  */
Packit 032894
  size_t zdata_align;		/* If zdata_base != NULL, the addralign.  */
Packit 032894
Packit 032894
  struct Elf_ScnList *list;	/* Pointer to the section list element the
Packit 032894
				   data is in.  */
Packit 032894
};
Packit 032894
Packit 032894
Packit 032894
/* List of section.  */
Packit 032894
typedef struct Elf_ScnList
Packit 032894
{
Packit 032894
  unsigned int cnt;		/* Number of elements of 'data' used.  */
Packit 032894
  unsigned int max;		/* Number of elements of 'data' allocated.  */
Packit 032894
  struct Elf_ScnList *next;	/* Next block of sections.  */
Packit 032894
  struct Elf_Scn data[0];	/* Section data.  */
Packit 032894
} Elf_ScnList;
Packit 032894
Packit 032894
Packit 032894
/* elf_getdata_rawchunk result.  */
Packit 032894
typedef struct Elf_Data_Chunk
Packit 032894
{
Packit 032894
  Elf_Data_Scn data;
Packit 032894
  union
Packit 032894
  {
Packit 032894
    Elf_Scn dummy_scn;
Packit 032894
    struct Elf_Data_Chunk *next;
Packit 032894
  };
Packit 032894
} Elf_Data_Chunk;
Packit 032894
Packit 032894
Packit 032894
/* The ELF descriptor.  */
Packit 032894
struct Elf
Packit 032894
{
Packit 032894
  /* Address to which the file was mapped.  NULL if not mapped.  */
Packit 032894
  void *map_address;
Packit 032894
Packit 032894
  /* When created for an archive member this points to the descriptor
Packit 032894
     for the archive. */
Packit 032894
  Elf *parent;
Packit 032894
  Elf *next;             /* Used in list of archive descriptors.  */
Packit 032894
Packit 032894
  /* What kind of file is underneath (ELF file, archive...).  */
Packit 032894
  Elf_Kind kind;
Packit 032894
Packit 032894
  /* Command used to create this descriptor.  */
Packit 032894
  Elf_Cmd cmd;
Packit 032894
Packit 032894
  /* The binary class.  */
Packit 032894
  unsigned int class;
Packit 032894
Packit 032894
  /* The used file descriptor.  -1 if not available anymore.  */
Packit 032894
  int fildes;
Packit 032894
Packit 032894
  /* Offset in the archive this file starts or zero.  */
Packit 032894
  int64_t start_offset;
Packit 032894
Packit 032894
  /* Size of the file in the archive or the entire file size, or ~0
Packit 032894
     for an (yet) unknown size.  */
Packit 032894
  size_t maximum_size;
Packit 032894
Packit 032894
  /* Describes the way the memory was allocated and if the dirty bit is
Packit 032894
     signalled it means that the whole file has to be rewritten since
Packit 032894
     the layout changed.  */
Packit 032894
  int flags;
Packit 032894
Packit 032894
  /* Reference counting for the descriptor.  */
Packit 032894
  int ref_count;
Packit 032894
Packit 032894
  /* Lock to handle multithreaded programs.  */
Packit 032894
  rwlock_define (,lock);
Packit 032894
Packit 032894
  union
Packit 032894
  {
Packit 032894
    struct
Packit 032894
    {
Packit 032894
      /* The next fields are only useful when testing for ==/!= NULL.  */
Packit 032894
      void *ehdr;
Packit 032894
      void *shdr;
Packit 032894
      void *phdr;
Packit 032894
Packit 032894
      Elf_ScnList *scns_last;	/* Last element in the section list.
Packit 032894
				   If NULL the data has not yet been
Packit 032894
				   read from the file.  */
Packit 032894
      Elf_Data_Chunk *rawchunks; /* List of elf_getdata_rawchunk results.  */
Packit 032894
      unsigned int scnincr;	/* Number of sections allocate the last
Packit 032894
				   time.  */
Packit 032894
      int ehdr_flags;		/* Flags (dirty) for ELF header.  */
Packit 032894
      int phdr_flags;		/* Flags (dirty|malloc) for program header.  */
Packit 032894
      int shdr_malloced;	/* Nonzero if shdr array was allocated.  */
Packit 032894
      off_t sizestr_offset;	/* Offset of the size string in the parent
Packit 032894
				   if this is an archive member.  */
Packit 032894
    } elf;
Packit 032894
Packit 032894
    struct
Packit 032894
    {
Packit 032894
      Elf32_Ehdr *ehdr;		/* Pointer to the ELF header.  This is
Packit 032894
				   never malloced.  */
Packit 032894
      Elf32_Shdr *shdr;		/* Used when reading from a file.  */
Packit 032894
      Elf32_Phdr *phdr;		/* Pointer to the program header array.  */
Packit 032894
      Elf_ScnList *scns_last;	/* Last element in the section list.
Packit 032894
				   If NULL the data has not yet been
Packit 032894
				   read from the file.  */
Packit 032894
      Elf_Data_Chunk *rawchunks; /* List of elf_getdata_rawchunk results.  */
Packit 032894
      unsigned int scnincr;	/* Number of sections allocate the last
Packit 032894
				   time.  */
Packit 032894
      int ehdr_flags;		/* Flags (dirty) for ELF header.  */
Packit 032894
      int phdr_flags;		/* Flags (dirty|malloc) for program header.  */
Packit 032894
      int shdr_malloced;	/* Nonzero if shdr array was allocated.  */
Packit 032894
      int64_t sizestr_offset;	/* Offset of the size string in the parent
Packit 032894
				   if this is an archive member.  */
Packit 032894
      Elf32_Ehdr ehdr_mem;	/* Memory used for ELF header when not
Packit 032894
				   mmaped.  */
Packit 032894
      char __e32scnspad[sizeof (Elf64_Ehdr) - sizeof (Elf32_Ehdr)];
Packit 032894
Packit 032894
      /* The section array.  */
Packit 032894
      Elf_ScnList scns;
Packit 032894
    } elf32;
Packit 032894
Packit 032894
    struct
Packit 032894
    {
Packit 032894
      Elf64_Ehdr *ehdr;		/* Pointer to the ELF header.  This is
Packit 032894
				   never malloced.  */
Packit 032894
      Elf64_Shdr *shdr;		/* Used when reading from a file.  */
Packit 032894
      Elf64_Phdr *phdr;		/* Pointer to the program header array.  */
Packit 032894
      Elf_ScnList *scns_last;	/* Last element in the section list.
Packit 032894
				   If NULL the data has not yet been
Packit 032894
				   read from the file.  */
Packit 032894
      Elf_Data_Chunk *rawchunks; /* List of elf_getdata_rawchunk results.  */
Packit 032894
      unsigned int scnincr;	/* Number of sections allocate the last
Packit 032894
				   time.  */
Packit 032894
      int ehdr_flags;		/* Flags (dirty) for ELF header.  */
Packit 032894
      int phdr_flags;		/* Flags (dirty|malloc) for program header.  */
Packit 032894
      int shdr_malloced;	/* Nonzero if shdr array was allocated.  */
Packit 032894
      int64_t sizestr_offset;	/* Offset of the size string in the parent
Packit 032894
				   if this is an archive member.  */
Packit 032894
      Elf64_Ehdr ehdr_mem;	/* Memory used for ELF header when not
Packit 032894
				   mmaped.  */
Packit 032894
Packit 032894
      /* The section array.  */
Packit 032894
      Elf_ScnList scns;
Packit 032894
    } elf64;
Packit 032894
Packit 032894
    struct
Packit 032894
    {
Packit 032894
      Elf *children;		/* List of all descriptors for this archive. */
Packit 032894
      Elf_Arsym *ar_sym;	/* Symbol table returned by elf_getarsym.  */
Packit 032894
      size_t ar_sym_num;	/* Number of entries in `ar_sym'.  */
Packit 032894
      char *long_names;		/* If no index is available but long names
Packit 032894
				   are used this elements points to the data.*/
Packit 032894
      size_t long_names_len;	/* Length of the long name table.  */
Packit 032894
      int64_t offset;		/* Offset in file we are currently at.
Packit 032894
				   elf_next() advances this to the next
Packit 032894
				   member of the archive.  */
Packit 032894
      Elf_Arhdr elf_ar_hdr;	/* Structure returned by 'elf_getarhdr'.  */
Packit 032894
      struct ar_hdr ar_hdr;	/* Header read from file.  */
Packit 032894
      char ar_name[16];		/* NUL terminated ar_name of elf_ar_hdr.  */
Packit 032894
      char raw_name[17];	/* This is a buffer for the NUL terminated
Packit 032894
				   named raw_name used in the elf_ar_hdr.  */
Packit 032894
    } ar;
Packit 032894
  } state;
Packit 032894
Packit 032894
  /* There absolutely never must be anything following the union.  */
Packit 032894
};
Packit 032894
Packit 032894
/* Type of the conversion functions.  These functions will convert the
Packit 032894
   byte order.  */
Packit 032894
typedef void (*xfct_t) (void *, const void *, size_t, int);
Packit 032894
Packit 032894
/* The table with the function pointers.  */
Packit 032894
extern const xfct_t __elf_xfctstom[ELFCLASSNUM - 1][ELF_T_NUM]
Packit 032894
  attribute_hidden;
Packit 032894
Packit 032894
Packit 032894
/* Array with sizes of the external types indexed by ELF version, binary
Packit 032894
   class, and type. */
Packit 032894
extern const size_t __libelf_type_sizes[ELFCLASSNUM - 1][ELF_T_NUM]
Packit 032894
  attribute_hidden;
Packit 032894
/* We often have to access the size for a type in the current version.  */
Packit 032894
# define elf_typesize(class,type,n) \
Packit 032894
  (__libelf_type_sizes[ELFW(ELFCLASS,class) - 1][type] * n)
Packit 032894
Packit 032894
/* The byte value used for filling gaps.  */
Packit 032894
extern int __libelf_fill_byte attribute_hidden;
Packit 032894
Packit 032894
/* EV_CURRENT if the version was set, EV_NONE otherwise.  */
Packit 032894
extern unsigned int __libelf_version attribute_hidden;
Packit 032894
Packit 032894
/* Array with alignment requirements of the internal types indexed by
Packit 032894
   binary class, and type. */
Packit 032894
extern const uint_fast8_t __libelf_type_aligns[ELFCLASSNUM - 1][ELF_T_NUM]
Packit 032894
  attribute_hidden;
Packit 032894
# define __libelf_type_align(class, type)	\
Packit 032894
    (__libelf_type_aligns[class - 1][type] ?: 1)
Packit 032894
Packit 032894
/* Given an Elf handle and a section type returns the Elf_Data d_type.
Packit 032894
   Should not be called when SHF_COMPRESSED is set, the d_type should
Packit 032894
   be ELF_T_BYTE.  */
Packit 032894
extern Elf_Type __libelf_data_type (Elf *elf, int sh_type, GElf_Xword align)
Packit 032894
  internal_function;
Packit 032894
Packit 032894
Packit 032894
/* Create Elf descriptor from memory image.  */
Packit 032894
extern Elf *__libelf_read_mmaped_file (int fildes, void *map_address,
Packit 032894
				       int64_t offset, size_t maxsize,
Packit 032894
				       Elf_Cmd cmd, Elf *parent)
Packit 032894
     internal_function;
Packit 032894
Packit 032894
/* Set error value.  */
Packit 032894
extern void __libelf_seterrno (int value) internal_function;
Packit 032894
Packit 032894
/* Get the next archive header.  */
Packit 032894
extern int __libelf_next_arhdr_wrlock (Elf *elf) internal_function;
Packit 032894
Packit 032894
/* Read all of the file associated with the descriptor.  */
Packit 032894
extern char *__libelf_readall (Elf *elf) internal_function;
Packit 032894
Packit 032894
/* Read the complete section table and convert the byte order if necessary.  */
Packit 032894
extern int __libelf_readsections (Elf *elf) internal_function;
Packit 032894
Packit 032894
/* Store the information for the raw data in the `rawdata_list' element.  */
Packit 032894
extern int __libelf_set_rawdata (Elf_Scn *scn) internal_function;
Packit 032894
extern int __libelf_set_rawdata_wrlock (Elf_Scn *scn) internal_function;
Packit 032894
Packit 032894
Packit 032894
/* Helper functions for elf_update.  */
Packit 032894
extern int64_t __elf32_updatenull_wrlock (Elf *elf, int *change_bop,
Packit 032894
					  size_t shnum) internal_function;
Packit 032894
extern int64_t __elf64_updatenull_wrlock (Elf *elf, int *change_bop,
Packit 032894
					  size_t shnum) internal_function;
Packit 032894
Packit 032894
extern int __elf32_updatemmap (Elf *elf, int change_bo, size_t shnum)
Packit 032894
     internal_function;
Packit 032894
extern int __elf64_updatemmap (Elf *elf, int change_bo, size_t shnum)
Packit 032894
     internal_function;
Packit 032894
extern int __elf32_updatefile (Elf *elf, int change_bo, size_t shnum)
Packit 032894
     internal_function;
Packit 032894
extern int __elf64_updatefile (Elf *elf, int change_bo, size_t shnum)
Packit 032894
     internal_function;
Packit 032894
Packit 032894
Packit 032894
/* Alias for exported functions to avoid PLT entries, and
Packit 032894
   rdlock/wrlock variants of these functions.  */
Packit 032894
extern int __elf_end_internal (Elf *__elf) attribute_hidden;
Packit 032894
extern Elf *__elf_begin_internal (int __fildes, Elf_Cmd __cmd, Elf *__ref)
Packit 032894
     attribute_hidden;
Packit 032894
extern Elf32_Ehdr *__elf32_getehdr_wrlock (Elf *__elf) internal_function;
Packit 032894
extern Elf64_Ehdr *__elf64_getehdr_wrlock (Elf *__elf) internal_function;
Packit 032894
extern Elf32_Ehdr *__elf32_newehdr_internal (Elf *__elf) attribute_hidden;
Packit 032894
extern Elf64_Ehdr *__elf64_newehdr_internal (Elf *__elf) attribute_hidden;
Packit 032894
extern Elf32_Phdr *__elf32_getphdr_internal (Elf *__elf) attribute_hidden;
Packit 032894
extern Elf64_Phdr *__elf64_getphdr_internal (Elf *__elf) attribute_hidden;
Packit 032894
extern Elf32_Phdr *__elf32_getphdr_wrlock (Elf *__elf) attribute_hidden;
Packit 032894
extern Elf64_Phdr *__elf64_getphdr_wrlock (Elf *__elf) attribute_hidden;
Packit 032894
extern Elf32_Phdr *__elf32_newphdr_internal (Elf *__elf, size_t __cnt)
Packit 032894
     attribute_hidden;
Packit 032894
extern Elf64_Phdr *__elf64_newphdr_internal (Elf *__elf, size_t __cnt)
Packit 032894
     attribute_hidden;
Packit 032894
extern Elf_Scn *__elf32_offscn_internal (Elf *__elf, Elf32_Off __offset)
Packit 032894
     attribute_hidden;
Packit 032894
extern Elf_Scn *__elf64_offscn_internal (Elf *__elf, Elf64_Off __offset)
Packit 032894
     attribute_hidden;
Packit 032894
extern int __elf_getphdrnum_rdlock (Elf *__elf, size_t *__dst)
Packit 032894
     internal_function;
Packit 032894
extern int __elf_getphdrnum_chk_rdlock (Elf *__elf, size_t *__dst)
Packit 032894
     internal_function;
Packit 032894
extern int __elf_getshdrnum_rdlock (Elf *__elf, size_t *__dst)
Packit 032894
     internal_function;
Packit 032894
extern int __elf_getshdrstrndx_internal (Elf *__elf, size_t *__dst)
Packit 032894
     attribute_hidden;
Packit 032894
extern Elf32_Shdr *__elf32_getshdr_rdlock (Elf_Scn *__scn) internal_function;
Packit 032894
extern Elf64_Shdr *__elf64_getshdr_rdlock (Elf_Scn *__scn) internal_function;
Packit 032894
extern Elf32_Shdr *__elf32_getshdr_wrlock (Elf_Scn *__scn) internal_function;
Packit 032894
extern Elf64_Shdr *__elf64_getshdr_wrlock (Elf_Scn *__scn) internal_function;
Packit 032894
extern Elf_Scn *__elf_getscn_internal (Elf *__elf, size_t __index)
Packit 032894
     attribute_hidden;
Packit 032894
extern Elf_Scn *__elf_nextscn_internal (Elf *__elf, Elf_Scn *__scn)
Packit 032894
     attribute_hidden;
Packit 032894
extern int __elf_scnshndx_internal (Elf_Scn *__scn) attribute_hidden;
Packit 032894
extern Elf_Data *__elf_getdata_internal (Elf_Scn *__scn, Elf_Data *__data)
Packit 032894
     attribute_hidden;
Packit 032894
extern Elf_Data *__elf_getdata_rdlock (Elf_Scn *__scn, Elf_Data *__data)
Packit 032894
     internal_function;
Packit 032894
extern Elf_Data *__elf_rawdata_internal (Elf_Scn *__scn, Elf_Data *__data)
Packit 032894
     attribute_hidden;
Packit 032894
/* Should be called to setup first section data element if
Packit 032894
   data_list_rear is NULL and we know data_read is set and there is
Packit 032894
   raw data available.  Might upgrade the ELF lock from a read to a
Packit 032894
   write lock.  If the lock is already a write lock set wrlocked.  */
Packit 032894
extern void __libelf_set_data_list_rdlock (Elf_Scn *scn, int wrlocked)
Packit 032894
     internal_function;
Packit 032894
extern char *__elf_strptr_internal (Elf *__elf, size_t __index,
Packit 032894
				    size_t __offset) attribute_hidden;
Packit 032894
extern Elf_Data *__elf32_xlatetom_internal (Elf_Data *__dest,
Packit 032894
					    const Elf_Data *__src,
Packit 032894
					    unsigned int __encode)
Packit 032894
     attribute_hidden;
Packit 032894
extern Elf_Data *__elf64_xlatetom_internal (Elf_Data *__dest,
Packit 032894
					    const Elf_Data *__src,
Packit 032894
					    unsigned int __encode)
Packit 032894
     attribute_hidden;
Packit 032894
extern Elf_Data *__elf32_xlatetof_internal (Elf_Data *__dest,
Packit 032894
					    const Elf_Data *__src,
Packit 032894
					    unsigned int __encode)
Packit 032894
     attribute_hidden;
Packit 032894
extern Elf_Data *__elf64_xlatetof_internal (Elf_Data *__dest,
Packit 032894
					    const Elf_Data *__src,
Packit 032894
					    unsigned int __encode)
Packit 032894
     attribute_hidden;
Packit 032894
extern unsigned int __elf_version_internal (unsigned int __version)
Packit 032894
     attribute_hidden;
Packit 032894
extern unsigned long int __elf_hash_internal (const char *__string)
Packit 032894
       __attribute__ ((__pure__)) attribute_hidden;
Packit 032894
extern long int __elf32_checksum_internal (Elf *__elf) attribute_hidden;
Packit 032894
extern long int __elf64_checksum_internal (Elf *__elf) attribute_hidden;
Packit 032894
Packit 032894
Packit 032894
extern GElf_Ehdr *__gelf_getehdr_rdlock (Elf *__elf, GElf_Ehdr *__dest)
Packit 032894
     internal_function;
Packit 032894
extern size_t __gelf_fsize_internal (Elf *__elf, Elf_Type __type,
Packit 032894
				     size_t __count, unsigned int __version)
Packit 032894
     attribute_hidden;
Packit 032894
extern GElf_Shdr *__gelf_getshdr_internal (Elf_Scn *__scn, GElf_Shdr *__dst)
Packit 032894
     attribute_hidden;
Packit 032894
extern GElf_Sym *__gelf_getsym_internal (Elf_Data *__data, int __ndx,
Packit 032894
					 GElf_Sym *__dst) attribute_hidden;
Packit 032894
Packit 032894
Packit 032894
extern uint32_t __libelf_crc32 (uint32_t crc, unsigned char *buf, size_t len)
Packit 032894
     attribute_hidden;
Packit 032894
Packit 032894
extern void * __libelf_compress (Elf_Scn *scn, size_t hsize, int ei_data,
Packit 032894
				 size_t *orig_size, size_t *orig_addralign,
Packit 032894
				 size_t *size, bool force)
Packit 032894
     internal_function;
Packit 032894
Packit 032894
extern void * __libelf_decompress (void *buf_in, size_t size_in,
Packit 032894
				   size_t size_out) internal_function;
Packit 032894
extern void * __libelf_decompress_elf (Elf_Scn *scn,
Packit 032894
				       size_t *size_out, size_t *addralign)
Packit 032894
     internal_function;
Packit 032894
Packit 032894
Packit 032894
extern void __libelf_reset_rawdata (Elf_Scn *scn, void *buf, size_t size,
Packit 032894
				    size_t align, Elf_Type type)
Packit 032894
     internal_function;
Packit 032894
Packit 032894
Packit 032894
/* We often have to update a flag iff a value changed.  Make this
Packit 032894
   convenient.  */
Packit 032894
#define update_if_changed(var, exp, flag) \
Packit 032894
  do {									      \
Packit 032894
    __typeof__ (var) *_var = &(var);					      \
Packit 032894
    __typeof__ (exp) _exp = (exp);					      \
Packit 032894
    if (*_var != _exp)							      \
Packit 032894
      {									      \
Packit 032894
	*_var = _exp;							      \
Packit 032894
	(flag) |= ELF_F_DIRTY;						      \
Packit 032894
      }									      \
Packit 032894
  } while (0)
Packit 032894
Packit 032894
/* Align offset to 4 bytes as needed for note name and descriptor data.
Packit 032894
   This is almost always used, except for GNU Property notes, which use
Packit 032894
   8 byte padding...  */
Packit 032894
#define NOTE_ALIGN4(n)	(((n) + 3) & -4U)
Packit 032894
Packit 032894
/* Special note padding rule for GNU Property notes.  */
Packit 032894
#define NOTE_ALIGN8(n)	(((n) + 7) & -8U)
Packit 032894
Packit 032894
/* Convenience macro.  */
Packit 032894
#define INVALID_NDX(ndx, type, data) \
Packit 032894
  unlikely ((data)->d_size / sizeof (type) <= (unsigned int) (ndx))
Packit 032894
Packit 032894
#endif  /* libelfP.h */