Improve error message for files with no sections
Bug: http://b/25801618
Change-Id: I4f4f368e727ff48c84781279e3d17d4ac2d1b6b0
diff --git a/linker/linker_phdr.cpp b/linker/linker_phdr.cpp
index 347983e..4070a63 100644
--- a/linker/linker_phdr.cpp
+++ b/linker/linker_phdr.cpp
@@ -268,6 +268,11 @@
bool ElfReader::ReadSectionHeaders() {
shdr_num_ = header_.e_shnum;
+ if (shdr_num_ == 0) {
+ DL_ERR("\"%s\" there are no section headers in this file", name_.c_str());
+ return false;
+ }
+
if (!shdr_fragment_.Map(fd_, file_offset_, header_.e_shoff, shdr_num_ * sizeof(ElfW(Shdr)))) {
DL_ERR("\"%s\" shdr mmap failed: %s", name_.c_str(), strerror(errno));
return false;
@@ -288,7 +293,7 @@
}
if (dynamic_shdr == nullptr) {
- DL_ERR("\"%s\" .dynamic section was not found", name_.c_str());
+ DL_ERR("\"%s\" .dynamic section header was not found", name_.c_str());
return false;
}