elf: Improve detection of relocatable ELFs

This commit is contained in:
mintsuki 2023-05-13 00:05:50 +02:00
parent 836d1c2038
commit 7989064599

View File

@ -20,6 +20,9 @@
#define DT_RELA 0x00000007 #define DT_RELA 0x00000007
#define DT_RELASZ 0x00000008 #define DT_RELASZ 0x00000008
#define DT_RELAENT 0x00000009 #define DT_RELAENT 0x00000009
#define DT_FLAGS_1 0x6ffffffb
#define DF_1_PIE 0x08000000
#define ABI_SYSV 0x00 #define ABI_SYSV 0x00
#define ARCH_X86_64 0x3e #define ARCH_X86_64 0x3e
@ -150,6 +153,11 @@ static bool elf64_is_relocatable(uint8_t *elf, struct elf64_hdr *hdr) {
struct elf64_dyn *dyn = (void *)elf + (phdr->p_offset + j * sizeof(struct elf64_dyn)); struct elf64_dyn *dyn = (void *)elf + (phdr->p_offset + j * sizeof(struct elf64_dyn));
switch (dyn->d_tag) { switch (dyn->d_tag) {
case DT_FLAGS_1:
if (dyn->d_un & DF_1_PIE) {
return true;
}
break;
case DT_RELA: case DT_RELA:
return true; return true;
} }