Skip to content

Commit a648d76

Browse files
committed
lib/elf: Only add bss span to mem to skip if highest address PHDR
Fixes #504
1 parent 28f19d1 commit a648d76

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

common/lib/elf.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,9 @@ bool elf64_load(uint8_t *elf, uint64_t *entry_point, uint64_t *_slide, uint32_t
877877

878878
memcpy((void *)(uintptr_t)load_addr, elf + (phdr->p_offset), phdr->p_filesz);
879879

880-
bss_size = phdr->p_memsz - phdr->p_filesz;
880+
if (phdr->p_vaddr + phdr->p_memsz == max_vaddr) {
881+
bss_size = phdr->p_memsz - phdr->p_filesz;
882+
}
881883

882884
if (!elf64_apply_relocations(elf, hdr, (void *)(uintptr_t)load_addr, phdr->p_vaddr, phdr->p_memsz, slide)) {
883885
panic(true, "elf: Failed to apply relocations");

0 commit comments

Comments
 (0)