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