From b76123fed80eb3cf45a8b0b82b40fde516642a88 Mon Sep 17 00:00:00 2001 From: Dmitriy Ivanov Date: Fri, 20 Nov 2015 10:42:02 -0800 Subject: [PATCH] Improve error message for files with no sections Bug: http://b/25801618 Change-Id: I4f4f368e727ff48c84781279e3d17d4ac2d1b6b0 --- linker/linker_phdr.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/linker/linker_phdr.cpp b/linker/linker_phdr.cpp index 347983eb9..4070a6345 100644 --- a/linker/linker_phdr.cpp +++ b/linker/linker_phdr.cpp @@ -268,6 +268,11 @@ bool ElfReader::ReadProgramHeaders() { 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 @@ bool ElfReader::ReadDynamicSection() { } 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; }