Home | History | Annotate | Download | only in libelf
      1 /* Internal interfaces for libelf.
      2    Copyright (C) 1998-2003, 2005, 2006, 2007 Red Hat, Inc.
      3    This file is part of Red Hat elfutils.
      4    Contributed by Ulrich Drepper <drepper (at) redhat.com>, 1998.
      5 
      6    Red Hat elfutils is free software; you can redistribute it and/or modify
      7    it under the terms of the GNU General Public License as published by the
      8    Free Software Foundation; version 2 of the License.
      9 
     10    Red Hat elfutils is distributed in the hope that it will be useful, but
     11    WITHOUT ANY WARRANTY; without even the implied warranty of
     12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     13    General Public License for more details.
     14 
     15    You should have received a copy of the GNU General Public License along
     16    with Red Hat elfutils; if not, write to the Free Software Foundation,
     17    Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
     18 
     19    In addition, as a special exception, Red Hat, Inc. gives You the
     20    additional right to link the code of Red Hat elfutils with code licensed
     21    under any Open Source Initiative certified open source license
     22    (http://www.opensource.org/licenses/index.php) which requires the
     23    distribution of source code with any binary distribution and to
     24    distribute linked combinations of the two.  Non-GPL Code permitted under
     25    this exception must only link to the code of Red Hat elfutils through
     26    those well defined interfaces identified in the file named EXCEPTION
     27    found in the source code files (the "Approved Interfaces").  The files
     28    of Non-GPL Code may instantiate templates or use macros or inline
     29    functions from the Approved Interfaces without causing the resulting
     30    work to be covered by the GNU General Public License.  Only Red Hat,
     31    Inc. may make changes or additions to the list of Approved Interfaces.
     32    Red Hat's grant of this exception is conditioned upon your not adding
     33    any new exceptions.  If you wish to add a new Approved Interface or
     34    exception, please contact Red Hat.  You must obey the GNU General Public
     35    License in all respects for all of the Red Hat elfutils code and other
     36    code used in conjunction with Red Hat elfutils except the Non-GPL Code
     37    covered by this exception.  If you modify this file, you may extend this
     38    exception to your version of the file, but you are not obligated to do
     39    so.  If you do not wish to provide this exception without modification,
     40    you must delete this exception statement from your version and license
     41    this file solely under the GPL without exception.
     42 
     43    Red Hat elfutils is an included package of the Open Invention Network.
     44    An included package of the Open Invention Network is a package for which
     45    Open Invention Network licensees cross-license their patents.  No patent
     46    license is granted, either expressly or impliedly, by designation as an
     47    included package.  Should you wish to participate in the Open Invention
     48    Network licensing program, please visit www.openinventionnetwork.com
     49    <http://www.openinventionnetwork.com>.  */
     50 
     51 #ifndef _LIBELFP_H
     52 #define _LIBELFP_H 1
     53 
     54 #ifdef HAVE_CONFIG_H
     55 # include <config.h>
     56 #endif
     57 
     58 #include <ar.h>
     59 #include <gelf.h>
     60 
     61 #include <errno.h>
     62 #include <stdint.h>
     63 #include <stdio.h>
     64 #include <string.h>
     65 
     66 /* gettext helper macros.  */
     67 #define _(Str) dgettext ("libelf", Str)
     68 
     69 
     70 /* Helper Macros to write 32 bit and 64 bit functions.  */
     71 #define __elfw2_(Bits, Name) __elf##Bits##_##Name
     72 #define elfw2_(Bits, Name) elf##Bits##_##Name
     73 #define ElfW2_(Bits, Name) Elf##Bits##_##Name
     74 #define ELFW2_(Bits, Name) ELF##Bits##_##Name
     75 #define ELFW_(Name, Bits) Name##Bits
     76 #define __elfw2(Bits, Name) __elfw2_(Bits, Name)
     77 #define elfw2(Bits, Name) elfw2_(Bits, Name)
     78 #define ElfW2(Bits, Name) ElfW2_(Bits, Name)
     79 #define ELFW2(Bits, Name) ELFW2_(Bits, Name)
     80 #define ELFW(Name, Bits)  ELFW_(Name, Bits)
     81 
     82 
     83 /* Sizes of the external types, for 32 bits objects.  */
     84 #define ELF32_FSZ_ADDR   4
     85 #define ELF32_FSZ_OFF    4
     86 #define ELF32_FSZ_HALF   2
     87 #define ELF32_FSZ_WORD   4
     88 #define ELF32_FSZ_SWORD  4
     89 #define ELF32_FSZ_XWORD  8
     90 #define ELF32_FSZ_SXWORD 8
     91 
     92 /* Same for 64 bits objects.  */
     93 #define ELF64_FSZ_ADDR   8
     94 #define ELF64_FSZ_OFF    8
     95 #define ELF64_FSZ_HALF   2
     96 #define ELF64_FSZ_WORD   4
     97 #define ELF64_FSZ_SWORD  4
     98 #define ELF64_FSZ_XWORD  8
     99 #define ELF64_FSZ_SXWORD 8
    100 
    101 
    102 /* This is an extension of the ELF_F_* enumeration.  The values here are
    103    not part of the library interface, they are only used internally.  */
    104 enum
    105 {
    106   ELF_F_MMAPPED = 0x40,
    107   ELF_F_MALLOCED = 0x80,
    108   ELF_F_FILEDATA = 0x100
    109 };
    110 
    111 
    112 /* Get definition of all the external types.  */
    113 #include "exttypes.h"
    114 
    115 
    116 /* Error values.  */
    117 enum
    118 {
    119   ELF_E_NOERROR = 0,
    120   ELF_E_UNKNOWN_ERROR,
    121   ELF_E_UNKNOWN_VERSION,
    122   ELF_E_UNKNOWN_TYPE,
    123   ELF_E_INVALID_HANDLE,
    124   ELF_E_SOURCE_SIZE,
    125   ELF_E_DEST_SIZE,
    126   ELF_E_INVALID_ENCODING,
    127   ELF_E_NOMEM,
    128   ELF_E_INVALID_FILE,
    129   ELF_E_INVALID_OP,
    130   ELF_E_NO_VERSION,
    131   ELF_E_INVALID_CMD,
    132   ELF_E_RANGE,
    133   ELF_E_ARCHIVE_FMAG,
    134   ELF_E_INVALID_ARCHIVE,
    135   ELF_E_NO_ARCHIVE,
    136   ELF_E_NO_INDEX,
    137   ELF_E_READ_ERROR,
    138   ELF_E_WRITE_ERROR,
    139   ELF_E_INVALID_CLASS,
    140   ELF_E_INVALID_INDEX,
    141   ELF_E_INVALID_OPERAND,
    142   ELF_E_INVALID_SECTION,
    143   ELF_E_INVALID_COMMAND,
    144   ELF_E_WRONG_ORDER_EHDR,
    145   ELF_E_FD_DISABLED,
    146   ELF_E_FD_MISMATCH,
    147   ELF_E_OFFSET_RANGE,
    148   ELF_E_NOT_NUL_SECTION,
    149   ELF_E_DATA_MISMATCH,
    150   ELF_E_INVALID_SECTION_HEADER,
    151   ELF_E_INVALID_DATA,
    152   ELF_E_DATA_ENCODING,
    153   ELF_E_SECTION_TOO_SMALL,
    154   ELF_E_INVALID_ALIGN,
    155   ELF_E_INVALID_SHENTSIZE,
    156   ELF_E_UPDATE_RO,
    157   ELF_E_NOFILE,
    158   ELF_E_GROUP_NOT_REL,
    159   ELF_E_INVALID_PHDR,
    160   ELF_E_NO_PHDR,
    161   ELF_E_INVALID_OFFSET,
    162   /* Keep this as the last entry.  */
    163   ELF_E_NUM
    164 };
    165 
    166 
    167 /* The visible `Elf_Data' type is not sufficent for some operations due
    168    to a misdesigned interface.  Extend it for internal purposes.  */
    169 typedef struct
    170 {
    171   Elf_Data d;
    172   Elf_Scn *s;
    173 } Elf_Data_Scn;
    174 
    175 
    176 /* List of `Elf_Data' descriptors.  This is what makes up the section
    177    contents.  */
    178 typedef struct Elf_Data_List
    179 {
    180   /* `data' *must* be the first element in the struct.  */
    181   Elf_Data_Scn data;
    182   struct Elf_Data_List *next;
    183   int flags;
    184 } Elf_Data_List;
    185 
    186 
    187 /* Descriptor for ELF section.  */
    188 struct Elf_Scn
    189 {
    190   /* We have to distinguish several different situations:
    191 
    192      1. the section is user created.  Therefore there is no file or memory
    193         region to read the data from.  Here we have two different subcases:
    194 
    195         a) data was not yet added (before the first `elf_newdata' call)
    196 
    197         b) at least one data set is available
    198 
    199      2. this is a section from a file/memory region.  We have to read the
    200         current content in one data block if we have to.  But we don't
    201         read the data until it is necessary.  So we have the subcases:
    202 
    203         a) the section in the file has size zero (for whatever reason)
    204 
    205         b) the data of the file is not (yet) read
    206 
    207         c) the data is read and available.
    208 
    209      In addition to this we have different data sets, the raw and the converted
    210      data.  This distinction only exists for the data read from the file.
    211      All user-added data set (all but the first when read from the file or
    212      all of them for user-create sections) are the same in both formats.
    213      We don't create the converted data before it is necessary.
    214 
    215      The `data_read' element signals whether data is available in the
    216      raw format.
    217 
    218      If there is data from the file/memory region or if read one data
    219      set is added the `rawdata_list_read' pointer in non-NULL and points
    220      to the last filled data set.  `raw_datalist_rear' is therefore NULL
    221      only if there is no data set at all.
    222 
    223      This so far allows to distinguish all but two cases (given that the
    224      `rawdata_list' and `data_list' entries are initialized to zero) is
    225      between not yet loaded data from the file/memory region and a section
    226      with zero size and type ELF_T_BYTE.   */
    227   Elf_Data_List data_list;	/* List of data buffers.  */
    228   Elf_Data_List *data_list_rear; /* Pointer to the rear of the data list. */
    229 
    230   Elf_Data_Scn rawdata;		/* Uninterpreted data of the section.  */
    231 
    232   int data_read;		/* Nonzero if the section was created by the
    233 				   user or if the data from the file/memory
    234 				   is read.  */
    235   int shndx_index;		/* Index of the extended section index
    236 				   table for this symbol table (if this
    237 				   section is a symbol table).  */
    238 
    239   size_t index;			/* Index of this section.  */
    240   struct Elf *elf;		/* The underlying ELF file.  */
    241 
    242   union
    243   {
    244     Elf32_Shdr *e32;		/* Pointer to 32bit section header.  */
    245     Elf64_Shdr *e64;		/* Pointer to 64bit section header.  */
    246   } shdr;
    247 
    248   unsigned int shdr_flags;	/* Section header modified?  */
    249   unsigned int flags;		/* Section changed in size?  */
    250 
    251   char *rawdata_base;		/* The unmodified data of the section.  */
    252   char *data_base;		/* The converted data of the section.  */
    253 
    254   struct Elf_ScnList *list;	/* Pointer the the section list element the
    255 				   data is in.  */
    256 };
    257 
    258 
    259 /* List of section.  */
    260 typedef struct Elf_ScnList
    261 {
    262   unsigned int cnt;		/* Number of elements of 'data' used.  */
    263   unsigned int max;		/* Number of elements of 'data' allocated.  */
    264   struct Elf_ScnList *next;	/* Next block of sections.  */
    265   struct Elf_Scn data[0];	/* Section data.  */
    266 } Elf_ScnList;
    267 
    268 
    269 /* elf_getdata_rawchunk result.  */
    270 typedef struct Elf_Data_Chunk
    271 {
    272   Elf_Data_Scn data;
    273   union
    274   {
    275     Elf_Scn dummy_scn;
    276     struct Elf_Data_Chunk *next;
    277   };
    278 } Elf_Data_Chunk;
    279 
    280 
    281 /* The ELF descriptor.  */
    282 struct Elf
    283 {
    284   /* What kind of file is underneath (ELF file, archive...).  */
    285   Elf_Kind kind;
    286 
    287   /* Command used to create this descriptor.  */
    288   Elf_Cmd cmd;
    289 
    290   /* The binary class.  */
    291   unsigned int class;
    292 
    293   /* The used file descriptor.  -1 if not available anymore.  */
    294   int fildes;
    295 
    296   /* Offset in the archive this file starts or zero.  */
    297   off_t start_offset;
    298 
    299   /* Size of the file in the archive or the entire file size, or ~0
    300      for an (yet) unknown size.  */
    301   size_t maximum_size;
    302 
    303   /* Address to which the file was mapped.  NULL if not mapped.  */
    304   void *map_address;
    305 
    306   /* Describes the way the memory was allocated and if the dirty bit is
    307      signalled it means that the whole file has to be rewritten since
    308      the layout changed.  */
    309   int flags;
    310 
    311   /* When created for an archive member this points to the descriptor
    312      for the archive. */
    313   Elf *parent;
    314 
    315   /* Lock to handle multithreaded programs.  */
    316   rwlock_define (,lock);
    317 
    318   /* Reference counting for the descriptor.  */
    319   int ref_count;
    320 
    321   struct Elf *next;             /* Used in list of archive descriptors.  */
    322 
    323   union
    324   {
    325     struct
    326     {
    327       int ehdr_flags;		/* Flags (dirty) for ELF header.  */
    328       int phdr_flags;		/* Flags (dirty|malloc) for program header.  */
    329       int shdr_malloced;	/* Nonzero if shdr array was allocated.  */
    330 
    331       /* The next fields are only useful when testing for ==/!= NULL.  */
    332       void *ehdr;
    333       void *shdr;
    334       void *phdr;
    335 
    336       Elf_ScnList *scns_last;	/* Last element in the section list.
    337 				   If NULL the data has not yet been
    338 				   read from the file.  */
    339       Elf_Data_Chunk *rawchunks; /* List of elf_getdata_rawchunk results.  */
    340       unsigned int scnincr;	/* Number of sections allocate the last
    341 				   time.  */
    342       off64_t sizestr_offset;	/* Offset of the size string in the parent
    343 				   if this is an archive member.  */
    344     } elf;
    345 
    346     struct
    347     {
    348       int ehdr_flags;		/* Flags (dirty) for ELF header.  */
    349       int phdr_flags;		/* Flags (dirty|malloc) for program header.  */
    350       int shdr_malloced;	/* Nonzero if shdr array was allocated.  */
    351 
    352       Elf32_Ehdr *ehdr;		/* Pointer to the ELF header.  This is
    353 				   never malloced.  */
    354       Elf32_Shdr *shdr;		/* Used when reading from a file.  */
    355       Elf32_Phdr *phdr;		/* Pointer to the program header array.  */
    356       Elf_ScnList *scns_last;	/* Last element in the section list.
    357 				   If NULL the data has not yet been
    358 				   read from the file.  */
    359       Elf_Data_Chunk *rawchunks; /* List of elf_getdata_rawchunk results.  */
    360       unsigned int scnincr;	/* Number of sections allocate the last
    361 				   time.  */
    362       off64_t sizestr_offset;	/* Offset of the size string in the parent
    363 				   if this is an archive member.  */
    364       Elf32_Ehdr ehdr_mem;	/* Memory used for ELF header when not
    365 				   mmaped.  */
    366       char __e32scnspad[sizeof (Elf64_Ehdr) - sizeof (Elf32_Ehdr)];
    367 
    368       /* The section array.  */
    369       Elf_ScnList scns;
    370     } elf32;
    371 
    372     struct
    373     {
    374       int ehdr_flags;		/* Flags (dirty) for ELF header.  */
    375       int phdr_flags;		/* Flags (dirty|malloc) for program header.  */
    376       int shdr_malloced;	/* Nonzero if shdr array was allocated.  */
    377 
    378       Elf64_Ehdr *ehdr;		/* Pointer to the ELF header.  This is
    379 				   never malloced.  */
    380       Elf64_Shdr *shdr;		/* Used when reading from a file.  */
    381       Elf64_Phdr *phdr;		/* Pointer to the program header array.  */
    382       Elf_ScnList *scns_last;	/* Last element in the section list.
    383 				   If NULL the data has not yet been
    384 				   read from the file.  */
    385       Elf_Data_Chunk *rawchunks; /* List of elf_getdata_rawchunk results.  */
    386       unsigned int scnincr;	/* Number of sections allocate the last
    387 				   time.  */
    388       off64_t sizestr_offset;	/* Offset of the size string in the parent
    389 				   if this is an archive member.  */
    390       Elf64_Ehdr ehdr_mem;	/* Memory used for ELF header when not
    391 				   mmaped.  */
    392 
    393       /* The section array.  */
    394       Elf_ScnList scns;
    395     } elf64;
    396 
    397     struct
    398     {
    399       int has_index;		/* Set when file has index.  0 means
    400 				   undecided, > 0 means it has one.  */
    401       Elf_Arsym *ar_sym;	/* Symbol table returned by elf_getarsym.  */
    402       size_t ar_sym_num;	/* Number of entries in `ar_sym'.  */
    403       char *long_names;		/* If no index is available but long names
    404 				   are used this elements points to the data.*/
    405       size_t long_names_len;	/* Length of the long name table.  */
    406       off_t offset;		/* Offset in file we are currently at.
    407 				   elf_next() advances this to the next
    408 				   member of the archive.  */
    409       Elf_Arhdr elf_ar_hdr;	/* Structure returned by 'elf_getarhdr'.  */
    410       struct ar_hdr ar_hdr;	/* Header read from file.  */
    411       char ar_name[16];		/* NUL terminated ar_name of elf_ar_hdr.  */
    412       char raw_name[17];	/* This is a buffer for the NUL terminated
    413 				   named raw_name used in the elf_ar_hdr.  */
    414       struct Elf *children;	/* List of all descriptors for this archive. */
    415     } ar;
    416   } state;
    417 
    418   /* There absolutely never must be anything following the union.  */
    419 };
    420 
    421 /* Type of the conversion functions.  These functions will convert the
    422    byte order.  */
    423 typedef void (*xfct_t) (void *, const void *, size_t, int);
    424 
    425 /* The table with the function pointers.  */
    426 extern const xfct_t __elf_xfctstom[EV_NUM - 1][EV_NUM - 1][ELFCLASSNUM - 1][ELF_T_NUM] attribute_hidden;
    427 extern const xfct_t __elf_xfctstof[EV_NUM - 1][EV_NUM - 1][ELFCLASSNUM - 1][ELF_T_NUM] attribute_hidden;
    428 
    429 
    430 /* Array with sizes of the external types indexed by ELF version, binary
    431    class, and type. */
    432 extern const size_t __libelf_type_sizes[EV_NUM - 1][ELFCLASSNUM - 1][ELF_T_NUM] attribute_hidden;
    433 /* We often have to access the size for a type in the current version.  */
    434 #if EV_NUM != 2
    435 # define elf_typesize(class,type,n) \
    436   elfw2(class,fsize) (type, n, __libelf_version)
    437 #else
    438 # define elf_typesize(class,type,n) \
    439   (__libelf_type_sizes[EV_CURRENT - 1][ELFW(ELFCLASS,class) - 1][type] * n)
    440 #endif
    441 
    442 /* Currently selected version of the ELF specification.  */
    443 extern unsigned int __libelf_version attribute_hidden;
    444 
    445 /* The byte value used for filling gaps.  */
    446 extern int __libelf_fill_byte attribute_hidden;
    447 
    448 /* Nonzero if the version was set.  */
    449 extern int __libelf_version_initialized attribute_hidden;
    450 
    451 /* Index for __libelf_type_sizes et al.  */
    452 #if EV_NUM == 2
    453 # define LIBELF_EV_IDX	0
    454 #else
    455 # define LIBELF_EV_IDX	(__libelf_version - 1)
    456 #endif
    457 
    458 #if !ALLOW_UNALIGNED
    459 /* Array with alignment requirements of the internal types indexed by ELF
    460    version, binary class, and type. */
    461 extern const uint_fast8_t __libelf_type_aligns[EV_NUM - 1][ELFCLASSNUM - 1][ELF_T_NUM] attribute_hidden;
    462 # define __libelf_type_align(class, type)	\
    463     (__libelf_type_aligns[LIBELF_EV_IDX][class - 1][type] ?: 1)
    464 #else
    465 # define __libelf_type_align(class, type)	1
    466 #endif
    467 
    468 /* The libelf API does not have such a function but it is still useful.
    469    Get the memory size for the given type.
    470 
    471    These functions cannot be marked internal since they are aliases
    472    of the export elfXX_fsize functions.*/
    473 extern size_t __elf32_msize (Elf_Type __type, size_t __count,
    474 			     unsigned int __version);
    475 extern size_t __elf64_msize (Elf_Type __type, size_t __count,
    476 			     unsigned int __version);
    477 
    478 
    479 /* Create Elf descriptor from memory image.  */
    480 extern Elf *__libelf_read_mmaped_file (int fildes, void *map_address,
    481 				       off_t offset, size_t maxsize,
    482 				       Elf_Cmd cmd, Elf *parent)
    483      internal_function;
    484 
    485 /* Set error value.  */
    486 extern void __libelf_seterrno (int value) internal_function;
    487 
    488 /* Get the next archive header.  */
    489 extern int __libelf_next_arhdr_wrlock (Elf *elf) internal_function;
    490 
    491 /* Read all of the file associated with the descriptor.  */
    492 extern char *__libelf_readall (Elf *elf) internal_function;
    493 
    494 /* Read the complete section table and convert the byte order if necessary.  */
    495 extern int __libelf_readsections (Elf *elf) internal_function;
    496 
    497 /* Store the information for the raw data in the `rawdata_list' element.  */
    498 extern int __libelf_set_rawdata (Elf_Scn *scn) internal_function;
    499 extern int __libelf_set_rawdata_wrlock (Elf_Scn *scn) internal_function;
    500 
    501 
    502 /* Helper functions for elf_update.  */
    503 extern off_t __elf32_updatenull_wrlock (Elf *elf, int *change_bop,
    504 					size_t shnum) internal_function;
    505 extern off_t __elf64_updatenull_wrlock (Elf *elf, int *change_bop,
    506 					size_t shnum) internal_function;
    507 
    508 extern int __elf32_updatemmap (Elf *elf, int change_bo, size_t shnum)
    509      internal_function;
    510 extern int __elf64_updatemmap (Elf *elf, int change_bo, size_t shnum)
    511      internal_function;
    512 extern int __elf32_updatefile (Elf *elf, int change_bo, size_t shnum)
    513      internal_function;
    514 extern int __elf64_updatefile (Elf *elf, int change_bo, size_t shnum)
    515      internal_function;
    516 
    517 
    518 /* Alias for exported functions to avoid PLT entries, and
    519    rdlock/wrlock variants of these functions.  */
    520 extern int __elf_end_internal (Elf *__elf) attribute_hidden;
    521 extern Elf *__elf_begin_internal (int __fildes, Elf_Cmd __cmd, Elf *__ref)
    522      attribute_hidden;
    523 extern Elf32_Ehdr *__elf32_getehdr_wrlock (Elf *__elf) internal_function;
    524 extern Elf64_Ehdr *__elf64_getehdr_wrlock (Elf *__elf) internal_function;
    525 extern Elf32_Ehdr *__elf32_newehdr_internal (Elf *__elf) attribute_hidden;
    526 extern Elf64_Ehdr *__elf64_newehdr_internal (Elf *__elf) attribute_hidden;
    527 extern Elf32_Phdr *__elf32_getphdr_internal (Elf *__elf) attribute_hidden;
    528 extern Elf64_Phdr *__elf64_getphdr_internal (Elf *__elf) attribute_hidden;
    529 extern Elf32_Phdr *__elf32_getphdr_wrlock (Elf *__elf) attribute_hidden;
    530 extern Elf64_Phdr *__elf64_getphdr_wrlock (Elf *__elf) attribute_hidden;
    531 extern Elf32_Phdr *__elf32_newphdr_internal (Elf *__elf, size_t __cnt)
    532      attribute_hidden;
    533 extern Elf64_Phdr *__elf64_newphdr_internal (Elf *__elf, size_t __cnt)
    534      attribute_hidden;
    535 extern Elf_Scn *__elf32_offscn_internal (Elf *__elf, Elf32_Off __offset)
    536   attribute_hidden;
    537 extern Elf_Scn *__elf64_offscn_internal (Elf *__elf, Elf64_Off __offset)
    538   attribute_hidden;
    539 extern int __elf_getshnum_rdlock (Elf *__elf, size_t *__dst) internal_function;
    540 extern int __elf_getshstrndx_internal (Elf *__elf, size_t *__dst)
    541      attribute_hidden;
    542 extern Elf32_Shdr *__elf32_getshdr_rdlock (Elf_Scn *__scn) internal_function;
    543 extern Elf64_Shdr *__elf64_getshdr_rdlock (Elf_Scn *__scn) internal_function;
    544 extern Elf32_Shdr *__elf32_getshdr_wrlock (Elf_Scn *__scn) internal_function;
    545 extern Elf64_Shdr *__elf64_getshdr_wrlock (Elf_Scn *__scn) internal_function;
    546 extern Elf_Scn *__elf_getscn_internal (Elf *__elf, size_t __index)
    547      attribute_hidden;
    548 extern Elf_Scn *__elf_nextscn_internal (Elf *__elf, Elf_Scn *__scn)
    549      attribute_hidden;
    550 extern int __elf_scnshndx_internal (Elf_Scn *__scn) attribute_hidden;
    551 extern Elf_Data *__elf_getdata_internal (Elf_Scn *__scn, Elf_Data *__data)
    552      attribute_hidden;
    553 extern Elf_Data *__elf_getdata_rdlock (Elf_Scn *__scn, Elf_Data *__data)
    554      internal_function;
    555 extern Elf_Data *__elf_rawdata_internal (Elf_Scn *__scn, Elf_Data *__data)
    556      attribute_hidden;
    557 extern char *__elf_strptr_internal (Elf *__elf, size_t __index,
    558 				    size_t __offset) attribute_hidden;
    559 extern Elf_Data *__elf32_xlatetom_internal (Elf_Data *__dest,
    560 					    const Elf_Data *__src,
    561 					    unsigned int __encode)
    562      attribute_hidden;
    563 extern Elf_Data *__elf64_xlatetom_internal (Elf_Data *__dest,
    564 					    const Elf_Data *__src,
    565 					    unsigned int __encode)
    566      attribute_hidden;
    567 extern Elf_Data *__elf32_xlatetof_internal (Elf_Data *__dest,
    568 					    const Elf_Data *__src,
    569 					    unsigned int __encode)
    570      attribute_hidden;
    571 extern Elf_Data *__elf64_xlatetof_internal (Elf_Data *__dest,
    572 					    const Elf_Data *__src,
    573 					    unsigned int __encode)
    574      attribute_hidden;
    575 extern unsigned int __elf_version_internal (unsigned int __version)
    576      attribute_hidden;
    577 extern unsigned long int __elf_hash_internal (const char *__string)
    578        __attribute__ ((__pure__, visibility ("hidden")));
    579 extern long int __elf32_checksum_internal (Elf *__elf) attribute_hidden;
    580 extern long int __elf64_checksum_internal (Elf *__elf) attribute_hidden;
    581 
    582 
    583 extern GElf_Ehdr *__gelf_getehdr_rdlock (Elf *__elf, GElf_Ehdr *__dest)
    584      internal_function;
    585 extern size_t __gelf_fsize_internal (Elf *__elf, Elf_Type __type,
    586 				     size_t __count, unsigned int __version)
    587      attribute_hidden;
    588 extern GElf_Shdr *__gelf_getshdr_internal (Elf_Scn *__scn, GElf_Shdr *__dst)
    589      attribute_hidden;
    590 extern GElf_Sym *__gelf_getsym_internal (Elf_Data *__data, int __ndx,
    591 					 GElf_Sym *__dst) attribute_hidden;
    592 
    593 
    594 extern uint32_t __libelf_crc32 (uint32_t crc, unsigned char *buf, size_t len)
    595      attribute_hidden;
    596 
    597 
    598 /* We often have to update a flag iff a value changed.  Make this
    599    convenient.  */
    600 #define update_if_changed(var, exp, flag) \
    601   do {									      \
    602     __typeof__ (var) *_var = &(var);					      \
    603     __typeof__ (exp) _exp = (exp);					      \
    604     if (*_var != _exp)							      \
    605       {									      \
    606 	*_var = _exp;							      \
    607 	(flag) |= ELF_F_DIRTY;						      \
    608       }									      \
    609   } while (0)
    610 
    611 /* Align offset to 4 bytes as needed for note name and descriptor data.  */
    612 #define NOTE_ALIGN(n)	(((n) + 3) & -4U)
    613 
    614 #endif  /* libelfP.h */
    615