Zephyr Project API 3.7.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
211#define SHF_WRITE 0x1
212#define SHF_ALLOC 0x2
213#define SHF_EXECINSTR 0x4
232
250
252#define SHN_UNDEF 0
253#define SHN_LORESERVE 0xff00
254#define SHN_ABS 0xfff1
255#define SHN_COMMON 0xfff2
256#define SHN_HIRESERVE 0xffff
259#define STT_NOTYPE 0
260#define STT_OBJECT 1
261#define STT_FUNC 2
262#define STT_SECTION 3
263#define STT_FILE 4
264#define STT_COMMON 5
265#define STT_LOOS 10
266#define STT_HIOS 12
267#define STT_LOPROC 13
268#define STT_HIPROC 15
271#define STB_LOCAL 0
272#define STB_GLOBAL 1
273#define STB_WEAK 2
274#define STB_LOOS 10
275#define STB_HIOS 12
276#define STB_LOPROC 13
277#define STB_HIPROC 15
284#define ELF32_ST_BIND(i) ((i) >> 4)
285
291#define ELF32_ST_TYPE(i) ((i) & 0xf)
292
298#define ELF64_ST_BIND(i) ((i) >> 4)
299
300
306#define ELF64_ST_TYPE(i) ((i) & 0xf)
307
321
335
341#define ELF32_R_SYM(i) ((i) >> 8)
342
348#define ELF32_R_TYPE(i) ((i) & 0xff)
349
363
377
382#define ELF64_R_SYM(i) ((i) >> 32)
383
389#define ELF64_R_TYPE(i) ((i) & 0xffffffff)
390
395#define R_386_NONE 0
396#define R_386_32 1
397#define R_386_PC32 2
398#define R_386_GOT32 3
399#define R_386_PLT32 4
400#define R_386_COPY 5
401#define R_386_GLOB_DAT 6
402#define R_386_JMP_SLOT 7
403#define R_386_RELATIVE 8
404#define R_386_GOTOFF 9
405
406#define R_ARM_NONE 0
407#define R_ARM_PC24 1
408#define R_ARM_ABS32 2
409#define R_ARM_REL32 3
410#define R_ARM_COPY 20
411#define R_ARM_GLOB_DAT 21
412#define R_ARM_JUMP_SLOT 22
413#define R_ARM_RELATIVE 23
414#define R_ARM_CALL 28
415#define R_ARM_JUMP24 29
416#define R_ARM_TARGET1 38
417#define R_ARM_V4BX 40
418#define R_ARM_PREL31 42
419#define R_ARM_MOVW_ABS_NC 43
420#define R_ARM_MOVT_ABS 44
421#define R_ARM_MOVW_PREL_NC 45
422#define R_ARM_MOVT_PREL 46
423#define R_ARM_ALU_PC_G0_NC 57
424#define R_ARM_ALU_PC_G1_NC 59
425#define R_ARM_LDR_PC_G2 63
426
427#define R_ARM_THM_CALL 10
428#define R_ARM_THM_JUMP24 30
429#define R_ARM_THM_MOVW_ABS_NC 47
430#define R_ARM_THM_MOVT_ABS 48
431#define R_ARM_THM_MOVW_PREL_NC 49
432#define R_ARM_THM_MOVT_PREL 50
433
434#define R_XTENSA_NONE 0
435#define R_XTENSA_32 1
436#define R_XTENSA_SLOT0_OP 20
447struct elf32_phdr {
448 elf32_word p_type;
449 elf32_off p_offset;
450 elf32_addr p_vaddr;
451 elf32_addr p_paddr;
452 elf32_word p_filesz;
453 elf32_word p_memsz;
454 elf32_word p_flags;
455 elf32_word p_align;
456};
457
461struct elf64_phdr {
462 elf64_word p_type;
463 elf64_off p_offset;
464 elf64_addr p_vaddr;
465 elf64_addr p_paddr;
466 elf64_xword p_filesz;
467 elf64_xword p_memsz;
468 elf64_word p_flags;
469 elf64_xword p_align;
470};
471
475#define PT_LOAD 1
476
480struct elf32_dyn {
481 elf32_sword d_tag;
482 union {
483 elf32_word d_val;
484 elf32_addr d_ptr;
485 } d_un;
486};
487
491struct elf64_dyn {
492 elf64_sxword d_tag;
493 union {
494 elf64_xword d_val;
495 elf64_addr d_ptr;
496 } d_un;
497};
500#if defined(CONFIG_64BIT) || defined(__DOXYGEN__)
502typedef struct elf64_ehdr elf_ehdr_t;
504typedef struct elf64_shdr elf_shdr_t;
506typedef struct elf64_phdr elf_phdr_t;
514typedef struct elf64_rel elf_rel_t;
516typedef struct elf64_rela elf_rela_t;
518typedef struct elf64_sym elf_sym_t;
520#define ELF_R_SYM ELF64_R_SYM
522#define ELF_R_TYPE ELF64_R_TYPE
524#define ELF_ST_BIND ELF64_ST_BIND
526#define ELF_ST_TYPE ELF64_ST_TYPE
527#else
529typedef struct elf32_ehdr elf_ehdr_t;
531typedef struct elf32_shdr elf_shdr_t;
533typedef struct elf32_phdr elf_phdr_t;
535typedef elf32_addr elf_addr;
537typedef elf32_half elf_half;
539typedef elf32_word elf_word;
541typedef struct elf32_rel elf_rel_t;
543typedef struct elf32_rela elf_rela_t;
545typedef struct elf32_sym elf_sym_t;
547#define ELF_R_SYM ELF32_R_SYM
549#define ELF_R_TYPE ELF32_R_TYPE
551#define ELF_ST_BIND ELF32_ST_BIND
553#define ELF_ST_TYPE ELF32_ST_TYPE
554#endif
555
556#ifdef __cplusplus
557}
558#endif
559
564#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:512
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:508
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:510
struct elf64_phdr elf_phdr_t
Machine sized program header structure.
Definition elf.h:506
#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:315
elf32_addr r_offset
Offset in the section to perform a relocation.
Definition elf.h:317
elf32_word r_info
Information about the relocation, related symbol and type.
Definition elf.h:319
Relocation entry for 32-bit ELFs with addend.
Definition elf.h:327
elf32_sword r_addend
Offset to be applied to the symbol address.
Definition elf.h:333
elf32_word r_info
Information about the relocation, related symbol and type.
Definition elf.h:331
elf32_addr r_offset
Offset in the section to perform a relocation.
Definition elf.h:329
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:218
elf32_half st_shndx
Symbols related section given by section header index.
Definition elf.h:230
elf32_word st_name
Name of the symbol as an index into the symbol string table.
Definition elf.h:220
elf32_addr st_value
Value or location of the symbol.
Definition elf.h:222
unsigned char st_other
Symbol visibility.
Definition elf.h:228
unsigned char st_info
Symbol binding and type information.
Definition elf.h:226
elf32_word st_size
Size of the symbol.
Definition elf.h:224
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:357
elf64_addr r_offset
Offset in the section to perform a relocation.
Definition elf.h:359
elf64_xword r_info
Information about the relocation, related symbol and type.
Definition elf.h:361
Relocation entry for 64-bit ELFs with addend.
Definition elf.h:369
elf64_sxword r_addend
Offset to be applied to the symbol address.
Definition elf.h:375
elf64_addr r_offset
Offset in the section to perform a relocation.
Definition elf.h:371
elf64_xword r_info
Information about the relocation, related symbol and type.
Definition elf.h:373
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:236
elf64_half st_shndx
Symbols related section given by section header index.
Definition elf.h:244
elf64_addr st_value
Value or location of the symbol.
Definition elf.h:246
unsigned char st_other
Symbol visibility.
Definition elf.h:242
unsigned char st_info
Symbol binding and type information.
Definition elf.h:240
elf64_xword st_size
Size of the symbol.
Definition elf.h:248
elf64_word st_name
Name of the symbol as an index into the symbol string table.
Definition elf.h:238