|
PatchworkOS
da8a090
A non-POSIX operating system.
|
Executable and linkable format definitions. More...
Executable and linkable format definitions.
The ELF (Executable and Linkable Format) is a commonly utilized file format for generic binary files, including executables, object code, shared libraries, etc. and we utilize it in various parts of the operating system.
Only 64-bit ELF is implemented/handled in PatchworkOS.
For the sake of alignment with the ELF specification we use the same naming conventions, even if they are different from the usual conventions used in PatchworkOS.
Data Structures | |
| struct | Elf64_Ehdr |
| ELF64 Header. More... | |
| struct | Elf64_Shdr |
| ELF64 Section Header. More... | |
| struct | Elf64_Sym |
| ELF64 Symbol Table Entry. More... | |
| struct | Elf64_Rel |
| ELF64 Rel Entry without addend. More... | |
| struct | Elf64_Rela |
| ELF64 Rela Entry with addend. More... | |
| struct | Elf64_Phdr |
| ELF64 Program Header. More... | |
| struct | Elf64_File |
| ELF File Helper structure. More... | |
Macros | |
| #define | ELF64_ST_BIND(i) ((i) >> 4) |
Extract the binding from st_info. | |
| #define | ELF64_ST_TYPE(i) ((i) & 0xf) |
Extract the type from st_info. | |
| #define | ELF64_ST_INFO(b, t) (((b) << 4) + ((t) & 0xf)) |
Create an st_info value from binding and type. | |
| #define | ELF64_R_SYM(i) ((i) >> 32) |
Extract the symbol index from r_info. | |
| #define | ELF64_R_TYPE(i) ((i) & 0xffffffffL) |
Extract the type from r_info. | |
| #define | ELF64_R_INFO(s, t) (((s) << 32) + ((t) & 0xffffffffL)) |
Create an r_info value from symbol index and type. | |
| #define | ELF64_GET_PHDR(elf, index) ((Elf64_Phdr*)((uint8_t*)(elf)->header + (elf)->header->e_phoff + ((index) * (elf)->header->e_phentsize))) |
| Get the program header at the given index from an ELF file. | |
| #define | ELF64_GET_SHDR(elf, index) ((Elf64_Shdr*)((uint8_t*)(elf)->header + (elf)->header->e_shoff + ((index) * (elf)->header->e_shentsize))) |
| Get the section header at the given index from an ELF file. | |
| #define | ELF64_AT_OFFSET(elf, offset) ((void*)((uint8_t*)(elf)->header + (offset))) |
| Get a pointer to a location in the ELF file at the given offset. | |
Typedefs | |
| typedef uint64_t | Elf64_Addr |
| ELF64 Unsigned program address. | |
| typedef uint64_t | Elf64_Off |
| ELF64 Unsigned file offset. | |
| typedef uint16_t | Elf64_Half |
| ELF64 Unsigned medium integer. | |
| typedef uint32_t | Elf64_Word |
| ELF64 Unsigned integer. | |
| typedef int32_t | Elf64_Sword |
| ELF64 Signed integer. | |
| typedef uint64_t | Elf64_Xword |
| ELF64 Unsigned long integer. | |
| typedef uint64_t | Elf64_Sxword |
| ELF64 Signed long integer. | |
Enumerations | |
| enum | Elf64_Ident_Indexes { EI_MAG0 = 0 , EI_MAG1 = 1 , EI_MAG2 = 2 , EI_MAG3 = 3 , EI_CLASS = 4 , EI_DATA = 5 , EI_VERSION = 6 , EI_OSABI = 7 , EI_ABIVERSION = 8 , EI_PAD = 9 , EI_NIDENT = 16 } |
Indices for e_ident[]. More... | |
| enum | Elf64_Magic { ELFMAG0 = 0x7f , ELFMAG1 = 'E' , ELFMAG2 = 'L' , ELFMAG3 = 'F' } |
Expected magic values in e_ident[EI_MAG0] to e_ident[EI_MAG3]. More... | |
| enum | Elf64_Class { ELFCLASSNONE = 0 , ELFCLASS32 = 1 , ELFCLASS64 = 2 } |
File class values for e_ident[EI_CLASS]. More... | |
| enum | Elf64_Data { ELFDATANONE = 0 , ELFDATALSB = 1 , ELFDATAMSB = 2 } |
Data encoding values for e_ident[EI_DATA]. More... | |
| enum | Elf64_Version { EV_NONE = 0 , EV_CURRENT = 1 } |
Version values for e_ident[EI_VERSION] and e_version. More... | |
| enum | Elf64_OsAbi { ELFOSABI_NONE = 0 , ELFOSABI_HPUX = 1 , ELFOSABI_NETBSD = 2 , ELFOSABI_GNU = 3 , ELFOSABI_LINUX = 3 , ELFOSABI_SOLARIS = 6 , ELFOSABI_AIX = 7 , ELFOSABI_IRIX = 8 , ELFOSABI_FREEBSD = 9 , ELFOSABI_TRU64 = 10 , ELFOSABI_MODESTO = 11 , ELFOSABI_OPENBSD = 12 , ELFOSABI_OPENVMS = 13 , ELFOSABI_NSK = 14 , ELFOSABI_AROS = 15 , ELFOSABI_FENIXOS = 16 , ELFOSABI_CLOUDABI = 17 , ELFOSABI_OPENVOS = 18 } |
OS/ABI identification values for e_ident[EI_OSABI]. More... | |
| enum | Elf64_Type { ET_NONE = 0 , ET_REL = 1 , ET_EXEC = 2 , ET_DYN = 3 , ET_CORE = 4 } |
Object file type values for e_type. More... | |
| enum | Elf64_Machine { EM_NONE = 0 , EM_M32 = 1 , EM_SPARC = 2 , EM_386 = 3 , EM_68K = 4 , EM_88K = 5 , EM_IAMCU = 6 , EM_860 = 7 , EM_MIPS = 8 , EM_S370 = 9 , EM_MIPS_RS3_LE = 10 , EM_PARISC = 15 , EM_VPP500 = 17 , EM_SPARC32PLUS = 18 , EM_960 = 19 , EM_PPC = 20 , EM_PPC64 = 21 , EM_S390 = 22 , EM_SPU = 23 , EM_V800 = 36 , EM_FR20 = 37 , EM_RH32 = 38 , EM_RCE = 39 , EM_ARM = 40 , EM_ALPHA = 41 , EM_SH = 42 , EM_SPARCV9 = 43 , EM_TRICORE = 44 , EM_ARC = 45 , EM_H8_300 = 46 , EM_H8_300H = 47 , EM_H8S = 48 , EM_H8_500 = 49 , EM_IA_64 = 50 , EM_MIPS_X = 51 , EM_COLDFIRE = 52 , EM_68HC12 = 53 , EM_MMA = 54 , EM_PCP = 55 , EM_NCPU = 56 , EM_NDR1 = 57 , EM_STARCORE = 58 , EM_ME16 = 59 , EM_ST100 = 60 , EM_TINYJ = 61 , EM_X86_64 = 62 , EM_PDSP = 63 , EM_PDP10 = 64 , EM_PDP11 = 65 , EM_FX66 = 66 , EM_ST9PLUS = 67 , EM_ST7 = 68 , EM_68HC16 = 69 , EM_68HC11 = 70 , EM_68HC08 = 71 , EM_68HC05 = 72 , EM_SVX = 73 , EM_ST19 = 74 , EM_VAX = 75 , EM_CRIS = 76 , EM_JAVELIN = 77 , EM_FIREPATH = 78 , EM_ZSP = 79 , EM_MMIX = 80 , EM_HUANY = 81 , EM_PRISM = 82 , EM_AVR = 83 , EM_FR30 = 84 , EM_D10V = 85 , EM_D30V = 86 , EM_V850 = 87 , EM_M32R = 88 , EM_MN10300 = 89 , EM_MN10200 = 90 , EM_PJ = 91 , EM_OPENRISC = 92 , EM_ARC_COMPACT = 93 , EM_XTENSA = 94 , EM_VIDEOCORE = 95 , EM_TMM_GPP = 96 , EM_NS32K = 97 , EM_TPC = 98 , EM_SNP1K = 99 , EM_ST200 = 100 , EM_IP2K = 101 , EM_MAX = 102 , EM_CR = 103 , EM_F2MC16 = 104 , EM_MSP430 = 105 , EM_BLACKFIN = 106 , EM_SE_C33 = 107 , EM_SEP = 108 , EM_ARCA = 109 , EM_UNICORE = 110 , EM_EXCESS = 111 , EM_DXP = 112 , EM_ALTERA_NIOS2 = 113 , EM_CRX = 114 , EM_XGATE = 115 , EM_C166 = 116 , EM_M16C = 117 , EM_DSPIC30F = 118 , EM_CE = 119 , EM_M32C = 120 , EM_TSK3000 = 131 , EM_RS08 = 132 , EM_SHARC = 133 , EM_ECOG2 = 134 , EM_SCORE7 = 135 , EM_DSP24 = 136 , EM_VIDEOCORE3 = 137 , EM_LATTICEMICO32 = 138 , EM_SE_C17 = 139 , EM_TI_C6000 = 140 , EM_TI_C2000 = 141 , EM_TI_C5500 = 142 , EM_TI_ARP32 = 143 , EM_TI_PRU = 144 , EM_MMDSP_PLUS = 160 , EM_CYPRESS_M8C = 161 , EM_R32C = 162 , EM_TRIMEDIA = 163 , EM_QDSP6 = 164 , EM_8051 = 165 , EM_STXP7X = 166 , EM_NDS32 = 167 , EM_ECOG1 = 168 , EM_ECOG1X = 168 , EM_MAXQ30 = 169 , EM_XIMO16 = 170 , EM_MANIK = 171 , EM_CRAYNV2 = 172 , EM_RX = 173 , EM_METAG = 174 , EM_MCST_ELBRUS = 175 , EM_ECOG16 = 176 , EM_CR16 = 177 , EM_ETPU = 178 , EM_SLE9X = 179 , EM_L10M = 180 , EM_K10M = 181 , EM_AARCH64 = 183 , EM_AVR32 = 185 , EM_STM8 = 186 , EM_TILE64 = 187 , EM_TILEPRO = 188 , EM_MICROBLAZE = 189 , EM_CUDA = 190 , EM_TILEGX = 191 , EM_CLOUDSHIELD = 192 , EM_COREA_1ST = 193 , EM_COREA_2ND = 194 , EM_ARC_COMPACT2 = 195 , EM_OPEN8 = 196 , EM_RL78 = 197 , EM_VIDEOCORE5 = 198 , EM_78KOR = 199 , EM_56800EX = 200 , EM_BA1 = 201 , EM_BA2 = 202 , EM_XCORE = 203 , EM_MCHP_PIC = 204 , EM_INTEL205 = 205 , EM_INTEL206 = 206 , EM_INTEL207 = 207 , EM_INTEL208 = 208 , EM_INTEL209 = 209 , EM_KM32 = 210 , EM_KMX32 = 211 , EM_KMX16 = 212 , EM_KMX8 = 213 , EM_KVARC = 214 , EM_CDP = 215 , EM_COGE = 216 , EM_COOL = 217 , EM_NORC = 218 , EM_CSR_KALIMBA = 219 , EM_Z80 = 220 , EM_VISIUM = 221 , EM_FT32 = 222 , EM_MOXIE = 223 , EM_AMDGPU = 224 , EM_RISCV = 243 , EM_LANAI = 244 , EM_CEVA = 245 , EM_CEVA_X2 = 246 , EM_BPF = 247 , EM_GRAPHCORE_IPU = 248 , EM_IMG1 = 249 , EM_NFP = 250 , EM_VE = 251 , EM_CSKY = 252 , EM_ARC_COMPACT3_64 = 253 , EM_MCS6502 = 254 , EM_ARC_COMPACT3 = 255 , EM_KVX = 256 , EM_65816 = 257 , EM_LOONGARCH = 258 , EM_KF32 = 259 , EM_U16_U8CORE = 260 , EM_TACHYUM = 261 , EM_56800EF = 262 , EM_SBF = 263 , EM_AIENGINE = 264 , EM_SIMA_MLA = 265 , EM_BANG = 266 , EM_LOONGGPU = 267 , EM_SW64 = 268 , EM_AIECTRLCODE = 269 } |
Machine architecture values for e_machine. More... | |
| enum | Elf64_Shn_Indexes { SHN_UNDEF = 0 , SHN_LORESERVE = 0xff00 , SHN_LOPROC = 0xff00 , SHN_HIPROC = 0xff1f , SHN_LOOS = 0xff20 , SHN_HIOS = 0xff3f , SHN_ABS = 0xfff1 , SHN_COMMON = 0xfff2 , SHN_XINDEX = 0xffff , SHN_HIRESERVE = 0xffff } |
| Special section indexes. More... | |
| enum | Elf64_Section_Types { SHT_NULL = 0 , SHT_PROGBITS = 1 , SHT_SYMTAB = 2 , SHT_STRTAB = 3 , SHT_RELA = 4 , SHT_HASH = 5 , SHT_DYNAMIC = 6 , SHT_NOTE = 7 , SHT_NOBITS = 8 , SHT_REL = 9 , SHT_SHLIB = 10 , SHT_DYNSYM = 11 , SHT_INIT_ARRAY = 14 , SHT_FINI_ARRAY = 15 , SHT_PREINIT_ARRAY = 16 , SHT_GROUP = 17 , SHT_SYMTAB_SHNDX = 18 , SHT_RELR = 19 , SHT_LOOS = 0x60000000 , SHT_HIOS = 0x6fffffff , SHT_LOPROC = 0x70000000 , SHT_HIPROC = 0x7fffffff , SHT_LOUSER = 0x80000000 , SHT_HIUSER = 0xffffffff } |
Section type values for sh_type. More... | |
| enum | Elf64_Section_Flags { SHF_WRITE = 0x1 , SHF_ALLOC = 0x2 , SHF_EXECINSTR = 0x4 , SHF_MERGE = 0x10 , SHF_STRINGS = 0x20 , SHF_INFO_LINK = 0x40 , SHF_LINK_ORDER = 0x80 , SHF_OS_NONCONFORMING = 0x100 , SHF_GROUP = 0x200 , SHF_TLS = 0x400 , SHF_COMPRESSED = 0x800 , SHF_MASKOS = 0x0ff00000 , SHF_MASKPROC = 0xf0000000 } |
Section flag values for sh_flags. More... | |
| enum | Elf64_Symbol_Binding { STB_LOCAL = 0 , STB_GLOBAL = 1 , STB_WEAK = 2 , STB_LOOS = 10 , STB_HIOS = 12 , STB_LOPROC = 13 , STB_HIPROC = 15 } |
Symbol binding values stored in st_info. More... | |
| enum | Elf64_Symbol_Type { STT_NOTYPE = 0 , STT_OBJECT = 1 , STT_FUNC = 2 , STT_SECTION = 3 , STT_FILE = 4 , STT_LOOS = 10 , STT_HIOS = 12 , STT_LOPROC = 13 , STT_HIPROC = 15 } |
Symbol type values stored in st_info. More... | |
| enum | Elf64_Relocation_Types_x86_64 { R_X86_64_NONE = 0 , R_X86_64_64 = 1 , R_X86_64_PC32 = 2 , R_X86_64_GOT32 = 3 , R_X86_64_PLT32 = 4 , R_X86_64_COPY = 5 , R_X86_64_GLOB_DAT = 6 , R_X86_64_JUMP_SLOT = 7 , R_X86_64_RELATIVE = 8 , R_X86_64_GOTPCREL = 9 , R_X86_64_32 = 10 , R_X86_64_32S = 11 , R_X86_64_16 = 12 , R_X86_64_PC16 = 13 , R_X86_64_8 = 14 , R_X86_64_PC8 = 15 , R_X86_64_DTPMOD64 = 16 , R_X86_64_DTPOFF64 = 17 , R_X86_64_TPOFF64 = 18 , R_X86_64_TLSGD = 19 , R_X86_64_TLSLD = 20 , R_X86_64_DTPOFF32 = 21 , R_X86_64_GOTTPOFF = 22 , R_X86_64_TPOFF32 = 23 , R_X86_64_PC64 = 24 , R_X86_64_GOTOFF64 = 25 , R_X86_64_GOTPC32 = 26 , R_X86_64_SIZE32 = 32 , R_X86_64_SIZE64 = 33 , R_X86_64_GOTPC32_TLSDESC = 34 , R_X86_64_TLSDESC_CALL = 35 , R_X86_64_TLSDESC = 36 , R_X86_64_IRELATIVE = 37 } |
Relocation type values for r_info. More... | |
| enum | Elf64_Program_Types { PT_NULL = 0 , PT_LOAD = 1 , PT_DYNAMIC = 2 , PT_INTERP = 3 , PT_NOTE = 4 , PT_SHLIB = 5 , PT_PHDR = 6 , PT_TLS = 7 , PT_LOOS = 0x60000000 , PT_HIOS = 0x6fffffff , PT_LOPROC = 0x70000000 , PT_HIPROC = 0x7fffffff } |
Segment type values for p_type. More... | |
| enum | Elf64_Program_Flags { PF_X = 0x1 , PF_W = 0x2 , PF_R = 0x4 , PF_MASKOS = 0x0ff00000 , PF_MASKPROC = 0xf0000000 } |
Segment flag values for p_flags. More... | |
Functions | |
| uint64_t | elf64_validate (Elf64_File *elf, void *data, uint64_t size) |
Validate a files content and initalize a ELF64_File structure using it. | |
| void | elf64_get_loadable_bounds (const Elf64_File *elf, Elf64_Addr *minAddr, Elf64_Addr *maxAddr) |
| Get the loadable virtual memory bounds of an ELF file. | |
| void | elf64_load_segments (const Elf64_File *elf, Elf64_Addr base, Elf64_Off offset) |
| Load all loadable segments of an ELF file into memory. | |
| uint64_t | elf64_relocate (const Elf64_File *elf, Elf64_Addr base, Elf64_Off offset, void *(*resolve_symbol)(const char *name, void *private), void *private) |
| Perform relocations on an ELF file loaded into memory. | |
| const char * | elf64_get_string (const Elf64_File *elf, Elf64_Xword strTabIndex, Elf64_Off offset) |
| Get a string from the string table section at the given offset. | |
| Elf64_Shdr * | elf64_get_section_by_name (const Elf64_File *elf, const char *name) |
| Get a section by its name. | |
| const char * | elf64_get_section_name (const Elf64_File *elf, const Elf64_Shdr *section) |
| Get the name of a section. | |
| Elf64_Sym * | elf64_get_symbol_by_index (const Elf64_File *elf, Elf64_Xword symbolIndex) |
| Get a symbol by its index from the symbol table. | |
| Elf64_Sym * | elf64_get_symbol_by_name (const Elf64_File *elf, const char *name) |
| Get a symbol by its name from the symbol table. | |
| const char * | elf64_get_symbol_name (const Elf64_File *elf, const Elf64_Sym *symbol) |
| Get the name of a symbol. | |
| Elf64_Sym * | elf64_get_dynamic_symbol_by_index (const Elf64_File *elf, Elf64_Xword symbolIndex) |
| Get a dynamic symbol by its index from the dynamic symbol table. | |
| const char * | elf64_get_dynamic_symbol_name (const Elf64_File *elf, const Elf64_Sym *symbol) |
| Get the name of a dynamic symbol. | |
| #define ELF64_ST_BIND | ( | i | ) | ((i) >> 4) |
| #define ELF64_ST_TYPE | ( | i | ) | ((i) & 0xf) |
| #define ELF64_ST_INFO | ( | b, | |
| t | |||
| ) | (((b) << 4) + ((t) & 0xf)) |
Create an st_info value from binding and type.
| b | The binding value |
| t | The type value |
st_info value | #define ELF64_R_SYM | ( | i | ) | ((i) >> 32) |
Extract the symbol index from r_info.
| i | The r_info value |
| #define ELF64_R_TYPE | ( | i | ) | ((i) & 0xffffffffL) |
Extract the type from r_info.
| i | The r_info value |
| #define ELF64_R_INFO | ( | s, | |
| t | |||
| ) | (((s) << 32) + ((t) & 0xffffffffL)) |
Create an r_info value from symbol index and type.
| s | The symbol index |
| t | The type value |
r_info value | #define ELF64_GET_PHDR | ( | elf, | |
| index | |||
| ) | ((Elf64_Phdr*)((uint8_t*)(elf)->header + (elf)->header->e_phoff + ((index) * (elf)->header->e_phentsize))) |
| #define ELF64_GET_SHDR | ( | elf, | |
| index | |||
| ) | ((Elf64_Shdr*)((uint8_t*)(elf)->header + (elf)->header->e_shoff + ((index) * (elf)->header->e_shentsize))) |
| #define ELF64_AT_OFFSET | ( | elf, | |
| offset | |||
| ) | ((void*)((uint8_t*)(elf)->header + (offset))) |
| typedef uint64_t Elf64_Addr |
ELF64 Unsigned program address.
ELF64 Unsigned file offset.
| typedef uint16_t Elf64_Half |
ELF64 Unsigned medium integer.
| typedef uint32_t Elf64_Word |
ELF64 Unsigned integer.
| typedef int32_t Elf64_Sword |
ELF64 Signed integer.
| typedef uint64_t Elf64_Xword |
ELF64 Unsigned long integer.
| typedef uint64_t Elf64_Sxword |
ELF64 Signed long integer.
| enum Elf64_Ident_Indexes |
Indices for e_ident[].
| enum Elf64_Magic |
| enum Elf64_Class |
| enum Elf64_Data |
| enum Elf64_Version |
| enum Elf64_OsAbi |
OS/ABI identification values for e_ident[EI_OSABI].
Defines the expected operating system or ABI for the file.
Even if we are in fact not Linux or GNU, we still expect this value or 0 since we for the most part follow the same conventions.
We ignore the "ABI Version" field e_ident[EI_ABIVERSION] entirely.
| enum Elf64_Type |
| enum Elf64_Machine |
Machine architecture values for e_machine.
| enum Elf64_Shn_Indexes |
Special section indexes.
| enum Elf64_Section_Types |
Section type values for sh_type.
| enum Elf64_Section_Flags |
Section flag values for sh_flags.
| enum Elf64_Symbol_Binding |
Symbol binding values stored in st_info.
| enum Elf64_Symbol_Type |
Symbol type values stored in st_info.
Relocation type values for r_info.
The associated comments describe the calculation performed for each relocation type where:
Additionally the size of the relocated field is indicated (word8, word16, word32, word64).
Most of these are not used.
| enum Elf64_Program_Types |
Segment type values for p_type.
| enum Elf64_Program_Flags |
Segment flag values for p_flags.
A segment is allowed to be readable even if the PF_R flag is not set.
| uint64_t elf64_validate | ( | Elf64_File * | elf, |
| void * | data, | ||
| uint64_t | size | ||
| ) |
Validate a files content and initalize a ELF64_File structure using it.
The idea behind this function is to verify every aspect of a ELF file such that other functions acting on the ELF64 file do not need to perform any validation.
The reason this does not read from a file is such that it will be generic and usable in user space, in the kernel and the bootloader.
Having to load the entire file might seem wasteful, but its actually very important in order to avoid a situation where we validate the file, another process modifies it, and then we read actual data later on causing a TOCTOU vulnerability.
| elf | Pointer to the structure to initialize |
| data | Pointer to the ELF file data in memory, caller retains ownership |
| size | Size of the ELF file data in bytes |
0. On failure, a non-zero error code. Check the implementation. Does not use ERR or errno. Definition at line 3 of file elf64_validate.c.
| void elf64_get_loadable_bounds | ( | const Elf64_File * | elf, |
| Elf64_Addr * | minAddr, | ||
| Elf64_Addr * | maxAddr | ||
| ) |
Get the loadable virtual memory bounds of an ELF file.
| elf | The ELF file |
| minAddr | Output pointer to store the minimum loadable virtual address |
| maxAddr | Output pointer to store the maximum loadable virtual address |
Definition at line 3 of file elf64_get_loadable_bounds.c.
| void elf64_load_segments | ( | const Elf64_File * | elf, |
| Elf64_Addr | base, | ||
| Elf64_Off | offset | ||
| ) |
Load all loadable segments of an ELF file into memory.
Each segment has virtual addresses specified in p_vaddr which is where the segment is intended to be loaded in memory. But we may not want to load it directly to that address, we might have a buffer where we wish to place the segments instead. Either way, we must still place the segments at the correct offsets relative to each other. Leading to the slightly unintuitive parameters of this function.
The final address where a segment is loaded is calculated as base + (p_vaddr - offset), meaning that if you wish to load a file directly to its intended virtual addresses, you would do:
If you wanted to load the contents to a buffer located at buffer which could later be mapped to the intended virtual addresses or if you wanted to load relocatable code, you would do:
base
- (p_vaddr - offset) for each segment.
| elf | The ELF file |
| base | The base address to load the segments into |
| offset | The offset in bytes to subtract from each segment's virtual address when loading |
Definition at line 3 of file elf64_load_segments.c.
| uint64_t elf64_relocate | ( | const Elf64_File * | elf, |
| Elf64_Addr | base, | ||
| Elf64_Off | offset, | ||
| void *(*)(const char *name, void *private) | resolve_symbol, | ||
| void * | private | ||
| ) |
Perform relocations on an ELF file loaded into memory.
This function will process all relocation sections in the ELF file and apply the relocations to the loaded segments in memory, including resolving symbol addresses using the provided callback as necessary.
Relocations are necessary when a ELF file contains references to symbols whose addresses are not known at compile time, for example the ELF file might be a shared library or kernel module.
Check elf64_load_segments() for an explanation of the base and offset parameters.
The resolve_symbol callback is used to resolve symbol names to addresses, this will be utilized for relocations of undefined symbols. Should return NULL if the symbol could not be resolved.
TOOD: Implement more relocation types as needed.
| elf | The ELF file |
| base | The base address where the segments are loaded in memory |
| offset | The offset in bytes that was subtracted from each segment's virtual address when loading |
| resolve_symbol | Callback function to resolve symbol names to addresses |
| private | Private data pointer passed to the resolve_symbol callback |
0. On failure, ERR. Definition at line 3 of file elf64_relocate.c.
| const char * elf64_get_string | ( | const Elf64_File * | elf, |
| Elf64_Xword | strTabIndex, | ||
| Elf64_Off | offset | ||
| ) |
Get a string from the string table section at the given offset.
| elf | The ELF file |
| strTabIndex | The index of the string table section to use |
| offset | The offset in bytes into the string table |
NULL if not found Definition at line 3 of file elf64_get_string.c.
| Elf64_Shdr * elf64_get_section_by_name | ( | const Elf64_File * | elf, |
| const char * | name | ||
| ) |
Get a section by its name.
| elf | The ELF file |
| name | The name of the section to find |
NULL if not found Definition at line 3 of file elf64_get_section_by_name.c.
| const char * elf64_get_section_name | ( | const Elf64_File * | elf, |
| const Elf64_Shdr * | section | ||
| ) |
Get the name of a section.
| elf | The ELF file |
| section | The section to get the name of |
NULL if not found Definition at line 3 of file elf64_get_section_name.c.
| Elf64_Sym * elf64_get_symbol_by_index | ( | const Elf64_File * | elf, |
| Elf64_Xword | symbolIndex | ||
| ) |
Get a symbol by its index from the symbol table.
| elf | The ELF file |
| symbolIndex | The index of the symbol to get |
NULL if not found Definition at line 3 of file elf64_get_symbol_by_index.c.
| Elf64_Sym * elf64_get_symbol_by_name | ( | const Elf64_File * | elf, |
| const char * | name | ||
| ) |
Get a symbol by its name from the symbol table.
| elf | The ELF file |
| name | The name of the symbol to find |
NULL if not found Definition at line 3 of file elf64_get_symbol_by_name.c.
| const char * elf64_get_symbol_name | ( | const Elf64_File * | elf, |
| const Elf64_Sym * | symbol | ||
| ) |
Get the name of a symbol.
| elf | The ELF file |
| symbol | The symbol to get the name of |
NULL if not found Definition at line 3 of file elf64_get_symbol_name.c.
| Elf64_Sym * elf64_get_dynamic_symbol_by_index | ( | const Elf64_File * | elf, |
| Elf64_Xword | symbolIndex | ||
| ) |
Get a dynamic symbol by its index from the dynamic symbol table.
Dynamic symbols are, for example, found in .rela.* sections used for dynamic linking.
| elf | The ELF file |
| symbolIndex | The index of the dynamic symbol to get |
NULL if not found Definition at line 3 of file elf64_get_dynamic_symbol_by_index.c.
| const char * elf64_get_dynamic_symbol_name | ( | const Elf64_File * | elf, |
| const Elf64_Sym * | symbol | ||
| ) |
Get the name of a dynamic symbol.
| elf | The ELF file |
| symbol | The dynamic symbol to get the name of |
NULL if not found Definition at line 3 of file elf64_get_dynamic_symbol_name.c.