blob: ca805ac46d19d495f5526675702e42ed3096f3de [file] [log] [blame]
Brian Silverman86497922018-02-10 19:28:39 -05001/* 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. */
80enum
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. */
93enum
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. */
153typedef 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. */
162typedef 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. */
172struct 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. */
254typedef 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. */
264typedef 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. */
276struct 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. */
411typedef void (*xfct_t) (void *, const void *, size_t, int);
412
413/* The table with the function pointers. */
414extern const xfct_t __elf_xfctstom[EV_NUM - 1][EV_NUM - 1][ELFCLASSNUM - 1][ELF_T_NUM] attribute_hidden;
415extern const xfct_t __elf_xfctstof[EV_NUM - 1][EV_NUM - 1][ELFCLASSNUM - 1][ELF_T_NUM] attribute_hidden;
416
417
418/* Array with sizes of the external types indexed by ELF version, binary
419 class, and type. */
420extern const size_t __libelf_type_sizes[EV_NUM - 1][ELFCLASSNUM - 1][ELF_T_NUM] attribute_hidden;
421/* We often have to access the size for a type in the current version. */
422#if EV_NUM != 2
423# define elf_typesize(class,type,n) \
424 elfw2(class,fsize) (type, n, __libelf_version)
425#else
426# define elf_typesize(class,type,n) \
427 (__libelf_type_sizes[EV_CURRENT - 1][ELFW(ELFCLASS,class) - 1][type] * n)
428#endif
429
430/* Currently selected version of the ELF specification. */
431extern unsigned int __libelf_version attribute_hidden;
432
433/* The byte value used for filling gaps. */
434extern int __libelf_fill_byte attribute_hidden;
435
436/* Nonzero if the version was set. */
437extern int __libelf_version_initialized attribute_hidden;
438
439/* Index for __libelf_type_sizes et al. */
440#if EV_NUM == 2
441# define LIBELF_EV_IDX 0
442#else
443# define LIBELF_EV_IDX (__libelf_version - 1)
444#endif
445
446#if !ALLOW_UNALIGNED
447/* Array with alignment requirements of the internal types indexed by ELF
448 version, binary class, and type. */
449extern const uint_fast8_t __libelf_type_aligns[EV_NUM - 1][ELFCLASSNUM - 1][ELF_T_NUM] attribute_hidden;
450# define __libelf_type_align(class, type) \
451 (__libelf_type_aligns[LIBELF_EV_IDX][class - 1][type] ?: 1)
452#else
453# define __libelf_type_align(class, type) 1
454#endif
455
456/* Given an Elf handle and a section type returns the Elf_Data d_type.
457 Should not be called when SHF_COMPRESSED is set, the d_type should
458 be ELF_T_BYTE. */
459extern Elf_Type __libelf_data_type (Elf *elf, int sh_type) internal_function;
460
461/* The libelf API does not have such a function but it is still useful.
462 Get the memory size for the given type.
463
464 These functions cannot be marked internal since they are aliases
465 of the export elfXX_fsize functions.*/
466extern size_t __elf32_msize (Elf_Type __type, size_t __count,
467 unsigned int __version);
468extern size_t __elf64_msize (Elf_Type __type, size_t __count,
469 unsigned int __version);
470
471
472/* Create Elf descriptor from memory image. */
473extern Elf *__libelf_read_mmaped_file (int fildes, void *map_address,
474 off_t offset, size_t maxsize,
475 Elf_Cmd cmd, Elf *parent)
476 internal_function;
477
478/* Set error value. */
479extern void __libelf_seterrno (int value) internal_function;
480
481/* Get the next archive header. */
482extern int __libelf_next_arhdr_wrlock (Elf *elf) internal_function;
483
484/* Read all of the file associated with the descriptor. */
485extern char *__libelf_readall (Elf *elf) internal_function;
486
487/* Read the complete section table and convert the byte order if necessary. */
488extern int __libelf_readsections (Elf *elf) internal_function;
489
490/* Store the information for the raw data in the `rawdata_list' element. */
491extern int __libelf_set_rawdata (Elf_Scn *scn) internal_function;
492extern int __libelf_set_rawdata_wrlock (Elf_Scn *scn) internal_function;
493
494
495/* Helper functions for elf_update. */
496extern off_t __elf32_updatenull_wrlock (Elf *elf, int *change_bop,
497 size_t shnum) internal_function;
498extern off_t __elf64_updatenull_wrlock (Elf *elf, int *change_bop,
499 size_t shnum) internal_function;
500
501extern int __elf32_updatemmap (Elf *elf, int change_bo, size_t shnum)
502 internal_function;
503extern int __elf64_updatemmap (Elf *elf, int change_bo, size_t shnum)
504 internal_function;
505extern int __elf32_updatefile (Elf *elf, int change_bo, size_t shnum)
506 internal_function;
507extern int __elf64_updatefile (Elf *elf, int change_bo, size_t shnum)
508 internal_function;
509
510
511/* Alias for exported functions to avoid PLT entries, and
512 rdlock/wrlock variants of these functions. */
513extern int __elf_end_internal (Elf *__elf) attribute_hidden;
514extern Elf *__elf_begin_internal (int __fildes, Elf_Cmd __cmd, Elf *__ref)
515 attribute_hidden;
516extern Elf32_Ehdr *__elf32_getehdr_wrlock (Elf *__elf) internal_function;
517extern Elf64_Ehdr *__elf64_getehdr_wrlock (Elf *__elf) internal_function;
518extern Elf32_Ehdr *__elf32_newehdr_internal (Elf *__elf) attribute_hidden;
519extern Elf64_Ehdr *__elf64_newehdr_internal (Elf *__elf) attribute_hidden;
520extern Elf32_Phdr *__elf32_getphdr_internal (Elf *__elf) attribute_hidden;
521extern Elf64_Phdr *__elf64_getphdr_internal (Elf *__elf) attribute_hidden;
522extern Elf32_Phdr *__elf32_getphdr_wrlock (Elf *__elf) attribute_hidden;
523extern Elf64_Phdr *__elf64_getphdr_wrlock (Elf *__elf) attribute_hidden;
524extern Elf32_Phdr *__elf32_newphdr_internal (Elf *__elf, size_t __cnt)
525 attribute_hidden;
526extern Elf64_Phdr *__elf64_newphdr_internal (Elf *__elf, size_t __cnt)
527 attribute_hidden;
528extern Elf_Scn *__elf32_offscn_internal (Elf *__elf, Elf32_Off __offset)
529 attribute_hidden;
530extern Elf_Scn *__elf64_offscn_internal (Elf *__elf, Elf64_Off __offset)
531 attribute_hidden;
532extern int __elf_getphdrnum_rdlock (Elf *__elf, size_t *__dst)
533 internal_function;
534extern int __elf_getphdrnum_chk_rdlock (Elf *__elf, size_t *__dst)
535 internal_function;
536extern int __elf_getshdrnum_rdlock (Elf *__elf, size_t *__dst)
537 internal_function;
538extern int __elf_getshdrstrndx_internal (Elf *__elf, size_t *__dst)
539 attribute_hidden;
540extern Elf32_Shdr *__elf32_getshdr_rdlock (Elf_Scn *__scn) internal_function;
541extern Elf64_Shdr *__elf64_getshdr_rdlock (Elf_Scn *__scn) internal_function;
542extern Elf32_Shdr *__elf32_getshdr_wrlock (Elf_Scn *__scn) internal_function;
543extern Elf64_Shdr *__elf64_getshdr_wrlock (Elf_Scn *__scn) internal_function;
544extern Elf_Scn *__elf_getscn_internal (Elf *__elf, size_t __index)
545 attribute_hidden;
546extern Elf_Scn *__elf_nextscn_internal (Elf *__elf, Elf_Scn *__scn)
547 attribute_hidden;
548extern int __elf_scnshndx_internal (Elf_Scn *__scn) attribute_hidden;
549extern Elf_Data *__elf_getdata_internal (Elf_Scn *__scn, Elf_Data *__data)
550 attribute_hidden;
551extern Elf_Data *__elf_getdata_rdlock (Elf_Scn *__scn, Elf_Data *__data)
552 internal_function;
553extern Elf_Data *__elf_rawdata_internal (Elf_Scn *__scn, Elf_Data *__data)
554 attribute_hidden;
555/* Should be called to setup first section data element if
556 data_list_rear is NULL and we know data_read is set and there is
557 raw data available. Might upgrade the ELF lock from a read to a
558 write lock. If the lock is already a write lock set wrlocked. */
559extern void __libelf_set_data_list_rdlock (Elf_Scn *scn, int wrlocked)
560 internal_function;
561extern char *__elf_strptr_internal (Elf *__elf, size_t __index,
562 size_t __offset) attribute_hidden;
563extern Elf_Data *__elf32_xlatetom_internal (Elf_Data *__dest,
564 const Elf_Data *__src,
565 unsigned int __encode)
566 attribute_hidden;
567extern Elf_Data *__elf64_xlatetom_internal (Elf_Data *__dest,
568 const Elf_Data *__src,
569 unsigned int __encode)
570 attribute_hidden;
571extern Elf_Data *__elf32_xlatetof_internal (Elf_Data *__dest,
572 const Elf_Data *__src,
573 unsigned int __encode)
574 attribute_hidden;
575extern Elf_Data *__elf64_xlatetof_internal (Elf_Data *__dest,
576 const Elf_Data *__src,
577 unsigned int __encode)
578 attribute_hidden;
579extern unsigned int __elf_version_internal (unsigned int __version)
580 attribute_hidden;
581extern unsigned long int __elf_hash_internal (const char *__string)
582 __attribute__ ((__pure__)) attribute_hidden;
583extern long int __elf32_checksum_internal (Elf *__elf) attribute_hidden;
584extern long int __elf64_checksum_internal (Elf *__elf) attribute_hidden;
585
586
587extern GElf_Ehdr *__gelf_getehdr_rdlock (Elf *__elf, GElf_Ehdr *__dest)
588 internal_function;
589extern size_t __gelf_fsize_internal (Elf *__elf, Elf_Type __type,
590 size_t __count, unsigned int __version)
591 attribute_hidden;
592extern GElf_Shdr *__gelf_getshdr_internal (Elf_Scn *__scn, GElf_Shdr *__dst)
593 attribute_hidden;
594extern GElf_Sym *__gelf_getsym_internal (Elf_Data *__data, int __ndx,
595 GElf_Sym *__dst) attribute_hidden;
596
597
598extern uint32_t __libelf_crc32 (uint32_t crc, unsigned char *buf, size_t len)
599 attribute_hidden;
600
601extern void * __libelf_compress (Elf_Scn *scn, size_t hsize, int ei_data,
602 size_t *orig_size, size_t *orig_addralign,
603 size_t *size, bool force)
604 internal_function;
605
606extern void * __libelf_decompress (void *buf_in, size_t size_in,
607 size_t size_out) internal_function;
608extern void * __libelf_decompress_elf (Elf_Scn *scn,
609 size_t *size_out, size_t *addralign)
610 internal_function;
611
612
613extern void __libelf_reset_rawdata (Elf_Scn *scn, void *buf, size_t size,
614 size_t align, Elf_Type type)
615 internal_function;
616
617
618/* We often have to update a flag iff a value changed. Make this
619 convenient. */
620#define update_if_changed(var, exp, flag) \
621 do { \
622 __typeof__ (var) *_var = &(var); \
623 __typeof__ (exp) _exp = (exp); \
624 if (*_var != _exp) \
625 { \
626 *_var = _exp; \
627 (flag) |= ELF_F_DIRTY; \
628 } \
629 } while (0)
630
631/* Align offset to 4 bytes as needed for note name and descriptor data. */
632#define NOTE_ALIGN(n) (((n) + 3) & -4U)
633
634/* Convenience macro. */
635#define INVALID_NDX(ndx, type, data) \
636 unlikely ((data)->d_size / sizeof (type) <= (unsigned int) (ndx))
637
638#endif /* libelfP.h */