diff --git a/inc/drivers/builtin/elf/dynamic.h b/inc/drivers/builtin/elf/dynamic.h new file mode 100644 index 0000000..3cd62be --- /dev/null +++ b/inc/drivers/builtin/elf/dynamic.h @@ -0,0 +1,23 @@ +// This file is part of noxos and licensed under the MIT open source license + +#ifndef NOXOS_DYNAMIC_H +#define NOXOS_DYNAMIC_H + +#include + +typedef enum { + ELF_DYNAMIC_TAG_NULL, + ELF_DYNAMIC_TAG_NEEDED, + ELF_DYNAMIC_TAG_PLT_REL_SIZE, + ELF_DYNAMIC_TAG_HASH, + ELF_DYNAMIC_TAG_STRTAB, + ELF_DYNAMIC_TAG_RELA, + ELF_DYNAMIC_TAG_RELA_SIZE +} elf_dynamic_tag_E; + +typedef struct { + uint32_t tag; + uint64_t value; +} elf_dynamic_T; + +#endif //NOXOS_DYNAMIC_H \ No newline at end of file diff --git a/inc/drivers/builtin/elf/section.h b/inc/drivers/builtin/elf/section.h index 442df2b..14af740 100644 --- a/inc/drivers/builtin/elf/section.h +++ b/inc/drivers/builtin/elf/section.h @@ -13,7 +13,7 @@ typedef enum { ELF_SECTION_STRING_TABLE, ELF_SECTION_RELOCATION_A, ELF_SECTION_HASH, - ELF_SECTION_DYNAMIC_LINK, + ELF_SECTION_DYNAMIC, ELF_SECTION_NOTE, ELF_SECTION_NOBITS, diff --git a/src/drivers/builtin/elf/relocation.c b/src/drivers/builtin/elf/relocation.c index 250542e..47ed718 100644 --- a/src/drivers/builtin/elf/relocation.c +++ b/src/drivers/builtin/elf/relocation.c @@ -4,14 +4,23 @@ #include void elf_relocate(elf_executable_T* executable, uint8_t* buffer, void* address) { - elf_section_T* sections = (elf_section_T*)&buffer[executable->header.offset_section_header]; + elf_section_T* sections = (elf_section_T*)&buffer[executable->header.offset_section_header]; + elf_section_T* section_dynamic = NULL; for (uint32_t i = 0; i < executable->header.num_section_header_entries; i++) { - if (sections[i].type != ELF_SECTION_RELOCATION_A) continue; - - uint32_t num_relocations = sections[i].length / sections[i].entry_size; - elf_section_T* related_section = §ions[sections[i].info]; - - DEBUG("Found RELA section -> relocations: %d section: 0x%x", num_relocations, related_section); - + if (sections[i].type != ELF_SECTION_DYNAMIC) continue; + section_dynamic = §ions[i]; + DEBUG("Found DYNAMIC section %d", i); + break; } + if (section_dynamic == NULL) { + log(LOG_ERROR, "Failed to relocate ELF executable (no .dynamic section found)"); + return; + } + +// elf_section_T* section_rela = ; +// +// uint32_t num_relocations = sections[i].length / sections[i].entry_size; +// elf_section_T* related_section = §ions[sections[i].info]; + +// DEBUG("Found RELA section -> relocations: %d section: 0x%x", num_relocations, related_section); }