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