Zephyr Project API 4.1.99
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
217#define SHF_MASKOS 0x0ff00000
218#define SHF_LLEXT_HAS_RELOCS 0x00100000
220#define SHF_BASIC_TYPE_MASK (SHF_WRITE | SHF_ALLOC | SHF_EXECINSTR)
221
239
257
259#define SHN_UNDEF 0
260#define SHN_LORESERVE 0xff00
261#define SHN_ABS 0xfff1
262#define SHN_COMMON 0xfff2
263#define SHN_HIRESERVE 0xffff
266#define STT_NOTYPE 0
267#define STT_OBJECT 1
268#define STT_FUNC 2
269#define STT_SECTION 3
270#define STT_FILE 4
271#define STT_COMMON 5
272#define STT_LOOS 10
273#define STT_HIOS 12
274#define STT_LOPROC 13
275#define STT_HIPROC 15
278#define STB_LOCAL 0
279#define STB_GLOBAL 1
280#define STB_WEAK 2
281#define STB_LOOS 10
282#define STB_HIOS 12
283#define STB_LOPROC 13
284#define STB_HIPROC 15
291#define ELF32_ST_BIND(i) ((i) >> 4)
292
298#define ELF32_ST_TYPE(i) ((i) & 0xf)
299
305#define ELF64_ST_BIND(i) ((i) >> 4)
306
307
313#define ELF64_ST_TYPE(i) ((i) & 0xf)
314
328
342
348#define ELF32_R_SYM(i) ((i) >> 8)
349
355#define ELF32_R_TYPE(i) ((i) & 0xff)
356
370
384
389#define ELF64_R_SYM(i) ((i) >> 32)
390
396#define ELF64_R_TYPE(i) ((i) & 0xffffffff)
397
406struct elf32_phdr {
407 elf32_word p_type;
408 elf32_off p_offset;
409 elf32_addr p_vaddr;
410 elf32_addr p_paddr;
411 elf32_word p_filesz;
412 elf32_word p_memsz;
413 elf32_word p_flags;
414 elf32_word p_align;
415};
416
420struct elf64_phdr {
421 elf64_word p_type;
422 elf64_off p_offset;
423 elf64_addr p_vaddr;
424 elf64_addr p_paddr;
425 elf64_xword p_filesz;
426 elf64_xword p_memsz;
427 elf64_word p_flags;
428 elf64_xword p_align;
429};
430
434#define PT_LOAD 1
435
439struct elf32_dyn {
440 elf32_sword d_tag;
441 union {
442 elf32_word d_val;
443 elf32_addr d_ptr;
444 } d_un;
445};
446
450struct elf64_dyn {
451 elf64_sxword d_tag;
452 union {
453 elf64_xword d_val;
454 elf64_addr d_ptr;
455 } d_un;
456};
459#if defined(CONFIG_64BIT) || defined(__DOXYGEN__)
461typedef struct elf64_ehdr elf_ehdr_t;
463typedef struct elf64_shdr elf_shdr_t;
465typedef struct elf64_phdr elf_phdr_t;
473typedef struct elf64_rel elf_rel_t;
475typedef struct elf64_rela elf_rela_t;
477typedef struct elf64_sym elf_sym_t;
479#define ELF_R_SYM ELF64_R_SYM
481#define ELF_R_TYPE ELF64_R_TYPE
483#define ELF_ST_BIND ELF64_ST_BIND
485#define ELF_ST_TYPE ELF64_ST_TYPE
486#else
488typedef struct elf32_ehdr elf_ehdr_t;
490typedef struct elf32_shdr elf_shdr_t;
492typedef struct elf32_phdr elf_phdr_t;
494typedef elf32_addr elf_addr;
496typedef elf32_half elf_half;
498typedef elf32_word elf_word;
500typedef struct elf32_rel elf_rel_t;
502typedef struct elf32_rela elf_rela_t;
504typedef struct elf32_sym elf_sym_t;
506#define ELF_R_SYM ELF32_R_SYM
508#define ELF_R_TYPE ELF32_R_TYPE
510#define ELF_ST_BIND ELF32_ST_BIND
512#define ELF_ST_TYPE ELF32_ST_TYPE
513#endif
514
515#ifdef __cplusplus
516}
517#endif
518
523#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:471
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:467
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:469
struct elf64_phdr elf_phdr_t
Machine sized program header structure.
Definition elf.h:465
#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:322
elf32_addr r_offset
Offset in the section to perform a relocation.
Definition elf.h:324
elf32_word r_info
Information about the relocation, related symbol and type.
Definition elf.h:326
Relocation entry for 32-bit ELFs with addend.
Definition elf.h:334
elf32_sword r_addend
Offset to be applied to the symbol address.
Definition elf.h:340
elf32_word r_info
Information about the relocation, related symbol and type.
Definition elf.h:338
elf32_addr r_offset
Offset in the section to perform a relocation.
Definition elf.h:336
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:225
elf32_half st_shndx
Symbols related section given by section header index.
Definition elf.h:237
elf32_word st_name
Name of the symbol as an index into the symbol string table.
Definition elf.h:227
elf32_addr st_value
Value or location of the symbol.
Definition elf.h:229
unsigned char st_other
Symbol visibility.
Definition elf.h:235
unsigned char st_info
Symbol binding and type information.
Definition elf.h:233
elf32_word st_size
Size of the symbol.
Definition elf.h:231
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:364
elf64_addr r_offset
Offset in the section to perform a relocation.
Definition elf.h:366
elf64_xword r_info
Information about the relocation, related symbol and type.
Definition elf.h:368
Relocation entry for 64-bit ELFs with addend.
Definition elf.h:376
elf64_sxword r_addend
Offset to be applied to the symbol address.
Definition elf.h:382
elf64_addr r_offset
Offset in the section to perform a relocation.
Definition elf.h:378
elf64_xword r_info
Information about the relocation, related symbol and type.
Definition elf.h:380
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:243
elf64_half st_shndx
Symbols related section given by section header index.
Definition elf.h:251
elf64_addr st_value
Value or location of the symbol.
Definition elf.h:253
unsigned char st_other
Symbol visibility.
Definition elf.h:249
unsigned char st_info
Symbol binding and type information.
Definition elf.h:247
elf64_xword st_size
Size of the symbol.
Definition elf.h:255
elf64_word st_name
Name of the symbol as an index into the symbol string table.
Definition elf.h:245