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