From 037f21fbb4720842305e599dd06dfcf056eb2b78 Mon Sep 17 00:00:00 2001 From: HexRabbit Date: Wed, 13 Nov 2019 02:23:52 +0800 Subject: [PATCH 1/2] Support glibc compiled static ELF Now emulator load every segments from binary except NULL address segments and `.bss` --- emu-rv32i.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/emu-rv32i.c b/emu-rv32i.c index b64cae1..a0cf8e7 100644 --- a/emu-rv32i.c +++ b/emu-rv32i.c @@ -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 segments 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++) { From 6f64e9dd3b96c9feabed56c167515a446b77ff9b Mon Sep 17 00:00:00 2001 From: HexRabbit Date: Wed, 13 Nov 2019 03:02:37 +0800 Subject: [PATCH 2/2] Correct the use of section/segment --- emu-rv32i.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/emu-rv32i.c b/emu-rv32i.c index a0cf8e7..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); @@ -2081,7 +2081,7 @@ int main(int argc, char** argv) while ((scn = elf_nextscn(elf, scn)) != NULL) { gelf_getshdr(scn, &shdr); - /* filter NULL address segments and .bss */ + /* 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) {