Loader: Handle bad section names when loading an ELF file.
If there's a problem when reading the section names from a supposed ELF file, this change makes gem5 print an error message as returned by libelf and die. Previously these sorts of errors would make gem5 segfault when it tried to access the section name through a NULL pointer.
This commit is contained in:
parent
7bc68151b7
commit
91622602c2
1 changed files with 14 additions and 6 deletions
|
@ -266,6 +266,7 @@ ElfObject::ElfObject(const string &_filename, int _fd,
|
||||||
gelf_getshdr(section, &shdr);
|
gelf_getshdr(section, &shdr);
|
||||||
char * secName = elf_strptr(elf, ehdr.e_shstrndx, shdr.sh_name);
|
char * secName = elf_strptr(elf, ehdr.e_shstrndx, shdr.sh_name);
|
||||||
|
|
||||||
|
if (secName) {
|
||||||
if (!strcmp(".text", secName)) {
|
if (!strcmp(".text", secName)) {
|
||||||
textSecStart = shdr.sh_addr;
|
textSecStart = shdr.sh_addr;
|
||||||
} else if (!strcmp(".data", secName)) {
|
} else if (!strcmp(".data", secName)) {
|
||||||
|
@ -273,6 +274,13 @@ ElfObject::ElfObject(const string &_filename, int _fd,
|
||||||
} else if (!strcmp(".bss", secName)) {
|
} else if (!strcmp(".bss", secName)) {
|
||||||
bssSecStart = shdr.sh_addr;
|
bssSecStart = shdr.sh_addr;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Elf_Error errorNum = (Elf_Error)elf_errno();
|
||||||
|
if (errorNum != ELF_E_NONE) {
|
||||||
|
const char *errorMessage = elf_errmsg(errorNum);
|
||||||
|
fatal("Error from libelf: %s.\n", errorMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
section = elf_getscn(elf, ++secIdx);
|
section = elf_getscn(elf, ++secIdx);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue