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