Skip to content

Commit

Permalink
lib/elf: Do not perform any additional checks if an ELF is both ET_DY…
Browse files Browse the repository at this point in the history
…N and has a PT_DYNAMIC segment
  • Loading branch information
mintsuki committed May 24, 2024
1 parent a9afcf8 commit 1811c7f
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion common/lib/elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
#include <mm/pmm.h>
#include <fs/file.h>

#define ET_NONE 0
#define ET_REL 1
#define ET_EXEC 2
#define ET_DYN 3

#define PT_LOAD 0x00000001
#define PT_DYNAMIC 0x00000002
#define PT_INTERP 0x00000003
Expand All @@ -31,7 +36,6 @@
#define ARCH_RISCV 0xf3
#define BITS_LE 0x01
#define ELFCLASS64 0x02
#define ET_DYN 0x0003
#define SHT_RELA 0x00000004
#define R_X86_64_RELATIVE 0x00000008
#define R_AARCH64_RELATIVE 0x00000403
Expand Down Expand Up @@ -154,6 +158,10 @@ static bool elf64_is_relocatable(uint8_t *elf, struct elf64_hdr *hdr) {
continue;
}

if (hdr->type == ET_DYN) {
return true;
}

for (uint16_t j = 0; j < phdr->p_filesz / sizeof(struct elf64_dyn); j++) {
struct elf64_dyn *dyn = (void *)elf + (phdr->p_offset + j * sizeof(struct elf64_dyn));

Expand Down

0 comments on commit 1811c7f

Please sign in to comment.