Zephyr Project API 4.0.0
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
elf.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2023 Intel Corporation
3 * Copyright (c) 2024 Schneider Electric
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 *
7 */
8#ifndef ZEPHYR_LLEXT_ELF_H
9#define ZEPHYR_LLEXT_ELF_H
10
11#include <stdint.h>
12
24#ifdef __cplusplus
25extern "C" {
26#endif
27
38
53
54
66#define EI_NIDENT 16
67
101
135
137#define ET_REL 1
138
140#define ET_EXEC 2
141
143#define ET_DYN 3
144
146#define ET_CORE 4
147
173
199
201#define SHT_NULL 0x0
202#define SHT_PROGBITS 0x1
203#define SHT_SYMTAB 0x2
204#define SHT_STRTAB 0x3
205#define SHT_RELA 0x4
206#define SHT_NOBITS 0x8
207#define SHT_REL 0x9
208#define SHT_DYNSYM 0xB
209#define SHT_INIT_ARRAY 0xe
210#define SHT_FINI_ARRAY 0xf
211#define SHT_PREINIT_ARRAY 0x10
214#define SHF_WRITE 0x1
215#define SHF_ALLOC 0x2
216#define SHF_EXECINSTR 0x4
218#define SHF_BASIC_TYPE_MASK (SHF_WRITE | SHF_ALLOC | SHF_EXECINSTR)
219
237
255
257#define SHN_UNDEF 0
258#define SHN_LORESERVE 0xff00
259#define SHN_ABS 0xfff1
260#define SHN_COMMON 0xfff2
261#define SHN_HIRESERVE 0xffff
264#define STT_NOTYPE 0
265#define STT_OBJECT 1
266#define STT_FUNC 2
267#define STT_SECTION 3
268#define STT_FILE 4
269#define STT_COMMON 5
270#define STT_LOOS 10
271#define STT_HIOS 12
272#define STT_LOPROC 13
273#define STT_HIPROC 15
276#define STB_LOCAL 0
277#define STB_GLOBAL 1
278#define STB_WEAK 2
279#define STB_LOOS 10
280#define STB_HIOS 12
281#define STB_LOPROC 13
282#define STB_HIPROC 15
289#define ELF32_ST_BIND(i) ((i) >> 4)
290
296#define ELF32_ST_TYPE(i) ((i) & 0xf)
297
303#define ELF64_ST_BIND(i) ((i) >> 4)
304
305
311#define ELF64_ST_TYPE(i) ((i) & 0xf)
312
326
340
346#define ELF32_R_SYM(i) ((i) >> 8)
347
353#define ELF32_R_TYPE(i) ((i) & 0xff)
354
368
382
387#define ELF64_R_SYM(i) ((i) >> 32)
388
394#define ELF64_R_TYPE(i) ((i) & 0xffffffff)
395
404struct elf32_phdr {
405 elf32_word p_type;
406 elf32_off p_offset;
407 elf32_addr p_vaddr;
408 elf32_addr p_paddr;
409 elf32_word p_filesz;
410 elf32_word p_memsz;
411 elf32_word p_flags;
412 elf32_word p_align;
413};
414
418struct elf64_phdr {
419 elf64_word p_type;
420 elf64_off p_offset;
421 elf64_addr p_vaddr;
422 elf64_addr p_paddr;
423 elf64_xword p_filesz;
424 elf64_xword p_memsz;
425 elf64_word p_flags;
426 elf64_xword p_align;
427};
428
432#define PT_LOAD 1
433
437struct elf32_dyn {
438 elf32_sword d_tag;
439 union {
440 elf32_word d_val;
441 elf32_addr d_ptr;
442 } d_un;
443};
444
448struct elf64_dyn {
449 elf64_sxword d_tag;
450 union {
451 elf64_xword d_val;
452 elf64_addr d_ptr;
453 } d_un;
454};
457#if defined(CONFIG_64BIT) || defined(__DOXYGEN__)
459typedef struct elf64_ehdr elf_ehdr_t;
461typedef struct elf64_shdr elf_shdr_t;
463typedef struct elf64_phdr elf_phdr_t;
471typedef struct elf64_rel elf_rel_t;
473typedef struct elf64_rela elf_rela_t;
475typedef struct elf64_sym elf_sym_t;
477#define ELF_R_SYM ELF64_R_SYM
479#define ELF_R_TYPE ELF64_R_TYPE
481#define ELF_ST_BIND ELF64_ST_BIND
483#define ELF_ST_TYPE ELF64_ST_TYPE
484#else
486typedef struct elf32_ehdr elf_ehdr_t;
488typedef struct elf32_shdr elf_shdr_t;
490typedef struct elf32_phdr elf_phdr_t;
492typedef elf32_addr elf_addr;
494typedef elf32_half elf_half;
496typedef elf32_word elf_word;
498typedef struct elf32_rel elf_rel_t;
500typedef struct elf32_rela elf_rela_t;
502typedef struct elf32_sym elf_sym_t;
504#define ELF_R_SYM ELF32_R_SYM
506#define ELF_R_TYPE ELF32_R_TYPE
508#define ELF_ST_BIND ELF32_ST_BIND
510#define ELF_ST_TYPE ELF32_ST_TYPE
511#endif
512
513#ifdef __cplusplus
514}
515#endif
516
521#endif /* ZEPHYR_LLEXT_ELF_H */
int32_t elf32_sword
Signed integer.
Definition elf.h:35
uint16_t elf32_half
Unsigned medium integer.
Definition elf.h:31
elf64_xword elf_word
Machine sized integer.
Definition elf.h:469
int32_t elf64_sword
Signed integer.
Definition elf.h:46
uint16_t elf64_half
Unsigned medium integer.
Definition elf.h:42
int64_t elf64_sxword
Signed long integer.
Definition elf.h:50
uint64_t elf64_addr
Unsigned program address.
Definition elf.h:40
uint32_t elf32_addr
Unsigned program address.
Definition elf.h:29
uint64_t elf64_xword
Unsigned long integer.
Definition elf.h:52
uint64_t elf64_off
Unsigned file offset.
Definition elf.h:44
elf64_addr elf_addr
Machine sized program address.
Definition elf.h:465
uint32_t elf64_word
Unsigned integer.
Definition elf.h:48
uint32_t elf32_off
Unsigned file offset.
Definition elf.h:33
uint32_t elf32_word
Unsigned integer.
Definition elf.h:37
elf64_half elf_half
Machine sized small integer.
Definition elf.h:467
struct elf64_phdr elf_phdr_t
Machine sized program header structure.
Definition elf.h:463
#define EI_NIDENT
ELF identifier block.
Definition elf.h:66
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__INT32_TYPE__ int32_t
Definition stdint.h:74
__UINT64_TYPE__ uint64_t
Definition stdint.h:91
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
__INT64_TYPE__ int64_t
Definition stdint.h:75
ELF Header(32-bit)
Definition elf.h:71
elf32_off e_shoff
Section header table offset.
Definition elf.h:85
elf32_half e_machine
Machine type.
Definition elf.h:77
elf32_half e_phentsize
Program header count.
Definition elf.h:91
elf32_word e_flags
Processor specific flags.
Definition elf.h:87
elf32_addr e_entry
Virtual address of entry.
Definition elf.h:81
elf32_half e_phnum
Program header count.
Definition elf.h:93
elf32_half e_shentsize
Section header size.
Definition elf.h:95
elf32_half e_ehsize
ELF header size.
Definition elf.h:89
elf32_half e_shstrndx
Section header containing section header string table.
Definition elf.h:99
elf32_word e_version
Object file version.
Definition elf.h:79
elf32_half e_shnum
Section header count.
Definition elf.h:97
unsigned char e_ident[16]
Magic string identifying ELF binary.
Definition elf.h:73
elf32_half e_type
Type of ELF.
Definition elf.h:75
elf32_off e_phoff
Program header table offset.
Definition elf.h:83
Relocation entry for 32-bit ELFs.
Definition elf.h:320
elf32_addr r_offset
Offset in the section to perform a relocation.
Definition elf.h:322
elf32_word r_info
Information about the relocation, related symbol and type.
Definition elf.h:324
Relocation entry for 32-bit ELFs with addend.
Definition elf.h:332
elf32_sword r_addend
Offset to be applied to the symbol address.
Definition elf.h:338
elf32_word r_info
Information about the relocation, related symbol and type.
Definition elf.h:336
elf32_addr r_offset
Offset in the section to perform a relocation.
Definition elf.h:334
Section Header(32-bit)
Definition elf.h:151
elf32_addr sh_addr
Address of section in the image.
Definition elf.h:159
elf32_word sh_name
Section header name index in section header string table.
Definition elf.h:153
elf32_word sh_type
Section type.
Definition elf.h:155
elf32_word sh_flags
Section header attributes.
Definition elf.h:157
elf32_word sh_size
Section size in bytes.
Definition elf.h:163
elf32_word sh_info
Section info, depends on section type.
Definition elf.h:167
elf32_word sh_addralign
Section address alignment.
Definition elf.h:169
elf32_off sh_offset
Location of section in the ELF binary in bytes.
Definition elf.h:161
elf32_word sh_entsize
Section contains table of fixed size entries sh_entsize bytes large.
Definition elf.h:171
elf32_word sh_link
Section header table link index, depends on section type.
Definition elf.h:165
Symbol table entry(32-bit)
Definition elf.h:223
elf32_half st_shndx
Symbols related section given by section header index.
Definition elf.h:235
elf32_word st_name
Name of the symbol as an index into the symbol string table.
Definition elf.h:225
elf32_addr st_value
Value or location of the symbol.
Definition elf.h:227
unsigned char st_other
Symbol visibility.
Definition elf.h:233
unsigned char st_info
Symbol binding and type information.
Definition elf.h:231
elf32_word st_size
Size of the symbol.
Definition elf.h:229
ELF Header(64-bit)
Definition elf.h:105
elf64_addr e_entry
Virtual address of entry.
Definition elf.h:115
elf64_off e_shoff
Section header table offset.
Definition elf.h:119
elf64_half e_shentsize
Section header size.
Definition elf.h:129
elf64_half e_phnum
Program header count.
Definition elf.h:127
elf64_half e_shstrndx
Section header containing section header string table.
Definition elf.h:133
elf64_half e_phentsize
Program header size.
Definition elf.h:125
elf64_word e_flags
Processor specific flags.
Definition elf.h:121
elf64_half e_ehsize
ELF header size.
Definition elf.h:123
elf64_word e_version
Object file version.
Definition elf.h:113
elf64_half e_type
Type of ELF.
Definition elf.h:109
elf64_off e_phoff
Program header table offset.
Definition elf.h:117
elf64_half e_machine
Machine type.
Definition elf.h:111
unsigned char e_ident[16]
Magic string identifying ELF binary.
Definition elf.h:107
elf64_half e_shnum
Section header count.
Definition elf.h:131
Relocation entry for 64-bit ELFs.
Definition elf.h:362
elf64_addr r_offset
Offset in the section to perform a relocation.
Definition elf.h:364
elf64_xword r_info
Information about the relocation, related symbol and type.
Definition elf.h:366
Relocation entry for 64-bit ELFs with addend.
Definition elf.h:374
elf64_sxword r_addend
Offset to be applied to the symbol address.
Definition elf.h:380
elf64_addr r_offset
Offset in the section to perform a relocation.
Definition elf.h:376
elf64_xword r_info
Information about the relocation, related symbol and type.
Definition elf.h:378
Section Header(64-bit)
Definition elf.h:177
elf64_xword sh_size
Section size in bytes.
Definition elf.h:189
elf64_xword sh_entsize
Section contains table of fixed size entries sh_entsize bytes large.
Definition elf.h:197
elf64_word sh_link
Section header table link index, depends on section type.
Definition elf.h:191
elf64_addr sh_addr
Address of section in the image.
Definition elf.h:185
elf64_off sh_offset
Location of section in the ELF binary in bytes.
Definition elf.h:187
elf64_xword sh_addralign
Section address alignment.
Definition elf.h:195
elf64_word sh_info
Section info, depends on section type.
Definition elf.h:193
elf64_xword sh_flags
Section header attributes.
Definition elf.h:183
elf64_word sh_type
Section type.
Definition elf.h:181
elf64_word sh_name
Section header name index in section header string table.
Definition elf.h:179
Symbol table entry(64-bit)
Definition elf.h:241
elf64_half st_shndx
Symbols related section given by section header index.
Definition elf.h:249
elf64_addr st_value
Value or location of the symbol.
Definition elf.h:251
unsigned char st_other
Symbol visibility.
Definition elf.h:247
unsigned char st_info
Symbol binding and type information.
Definition elf.h:245
elf64_xword st_size
Size of the symbol.
Definition elf.h:253
elf64_word st_name
Name of the symbol as an index into the symbol string table.
Definition elf.h:243