diff --git a/emu-rv32i.c b/emu-rv32i.c index b64cae1..59aa83a 100644 --- a/emu-rv32i.c +++ b/emu-rv32i.c @@ -2053,7 +2053,7 @@ int main(int argc, char** argv) } } - /* set .text segment as the base address */ + /* set .text section as the base address */ scn = NULL; size_t shstrndx; elf_getshdrstrndx(elf, &shstrndx); @@ -2080,7 +2080,9 @@ int main(int argc, char** argv) scn = NULL; while ((scn = elf_nextscn(elf, scn)) != NULL) { gelf_getshdr(scn, &shdr); - if (shdr.sh_type == SHT_PROGBITS) { + + /* filter NULL address sections and .bss */ + if (shdr.sh_addr && shdr.sh_type != SHT_NOBITS) { Elf_Data *data = elf_getdata(scn, NULL); if (shdr.sh_addr >= ram_start) { for (size_t i = 0; i < shdr.sh_size; i++) {