diff --git a/libs/libc/machine/arm64/arch_elf.c b/libs/libc/machine/arm64/arch_elf.c index cf23f35bf33..210409a64fa 100644 --- a/libs/libc/machine/arm64/arch_elf.c +++ b/libs/libc/machine/arm64/arch_elf.c @@ -485,11 +485,20 @@ int up_relocateadd(const Elf64_Rela *rel, const Elf64_Sym *sym, uint64_t val; int ret = 0; + /* Only R_AARCH64_NONE may come without a symbol (symbol index 0) */ + + if (sym == NULL && ELF64_R_TYPE(rel->r_info) != R_AARCH64_NONE) + { + berr("ERROR: Relocation type %d has no symbol\n", + (int)ELF64_R_TYPE(rel->r_info)); + return -EINVAL; + } + /* addr corresponds to P in the AArch64 ELF document. */ /* val corresponds to (S + A) in the AArch64 ELF document. */ - val = sym->st_value + rel->r_addend; + val = (sym != NULL ? sym->st_value : 0) + rel->r_addend; /* Handle the relocation by relocation type */