summaryrefslogtreecommitdiff
path: root/src/base/loader
diff options
context:
space:
mode:
authorGabe Black <gblack@eecs.umich.edu>2011-06-12 23:52:21 -0700
committerGabe Black <gblack@eecs.umich.edu>2011-06-12 23:52:21 -0700
commit91622602c29f847d9844ec66a1db4ca3740901d3 (patch)
tree8bbd9337b2f0f9ffae8d497de9dd87db9be471e3 /src/base/loader
parent7bc68151b701931307a7d333f55e44baff665302 (diff)
downloadgem5-91622602c29f847d9844ec66a1db4ca3740901d3.tar.xz
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.
Diffstat (limited to 'src/base/loader')
-rw-r--r--src/base/loader/elf_object.cc20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/base/loader/elf_object.cc b/src/base/loader/elf_object.cc
index 6fcbd0ae3..1b1841a45 100644
--- a/src/base/loader/elf_object.cc
+++ b/src/base/loader/elf_object.cc
@@ -266,12 +266,20 @@ ElfObject::ElfObject(const string &_filename, int _fd,
gelf_getshdr(section, &shdr);
char * secName = elf_strptr(elf, ehdr.e_shstrndx, shdr.sh_name);
- if (!strcmp(".text", secName)) {
- textSecStart = shdr.sh_addr;
- } else if (!strcmp(".data", secName)) {
- dataSecStart = shdr.sh_addr;
- } else if (!strcmp(".bss", secName)) {
- bssSecStart = shdr.sh_addr;
+ if (secName) {
+ if (!strcmp(".text", secName)) {
+ textSecStart = shdr.sh_addr;
+ } else if (!strcmp(".data", secName)) {
+ dataSecStart = shdr.sh_addr;
+ } else if (!strcmp(".bss", secName)) {
+ 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);