From 7bd8d994978d6404a79b28e04a802d070c45ba16 Mon Sep 17 00:00:00 2001 From: Kevin Enderby Date: Mon, 2 May 2016 20:28:12 +0000 Subject: =?UTF-8?q?Thread=20Expected<...>=20up=20from=20libObject=E2=80=99?= =?UTF-8?q?s=20getType()=20for=20symbols=20to=20allow=20llvm-objdump=20to?= =?UTF-8?q?=20produce=20a=20good=20error=20message.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Produce another specific error message for a malformed Mach-O file when a symbol’s section index is more than the number of sections. The existing test case in test/Object/macho-invalid.test for macho-invalid-section-index-getSectionRawName now reports the error with the message indicating that a symbol at a specific index has a bad section index and that bad section index value. Again converting interfaces to Expected<> from ErrorOr<> does involve touching a number of places. Where the existing code reported the error with a string message or an error code it was converted to do the same. Also there some were bugs in the existing code that did not deal with the old ErrorOr<> return values.  So now with Expected<> since they must be checked and the error handled, I added a TODO and a comment: "// TODO: Actually report errors helpfully" and a call something like consumeError(NameOrErr.takeError()) so the buggy code will not crash since needed to deal with the Error. llvm-svn: 268298 --- llvm/lib/Object/MachOObjectFile.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'llvm/lib/Object/MachOObjectFile.cpp') diff --git a/llvm/lib/Object/MachOObjectFile.cpp b/llvm/lib/Object/MachOObjectFile.cpp index a182c4f..2240dc8 100644 --- a/llvm/lib/Object/MachOObjectFile.cpp +++ b/llvm/lib/Object/MachOObjectFile.cpp @@ -508,7 +508,7 @@ uint64_t MachOObjectFile::getCommonSymbolSizeImpl(DataRefImpl DRI) const { return getNValue(DRI); } -ErrorOr +Expected MachOObjectFile::getSymbolType(DataRefImpl Symb) const { MachO::nlist_base Entry = getSymbolTableEntryBase(this, Symb); uint8_t n_type = Entry.n_type; @@ -521,9 +521,9 @@ MachOObjectFile::getSymbolType(DataRefImpl Symb) const { case MachO::N_UNDF : return SymbolRef::ST_Unknown; case MachO::N_SECT : - ErrorOr SecOrError = getSymbolSection(Symb); + Expected SecOrError = getSymbolSection(Symb); if (!SecOrError) - return SecOrError.getError(); + return SecOrError.takeError(); section_iterator Sec = *SecOrError; if (Sec->isData() || Sec->isBSS()) return SymbolRef::ST_Data; @@ -571,7 +571,7 @@ uint32_t MachOObjectFile::getSymbolFlags(DataRefImpl DRI) const { return Result; } -ErrorOr +Expected MachOObjectFile::getSymbolSection(DataRefImpl Symb) const { MachO::nlist_base Entry = getSymbolTableEntryBase(this, Symb); uint8_t index = Entry.n_sect; @@ -581,9 +581,10 @@ MachOObjectFile::getSymbolSection(DataRefImpl Symb) const { DataRefImpl DRI; DRI.d.a = index - 1; if (DRI.d.a >= Sections.size()){ - // Diagnostic("bad section index (" + index + ") for symbol at index " + - // SymbolIndex); - return object_error::parse_failed; + return malformedError(*this, Twine("truncated or malformed object (bad " + "section index: ") + Twine((int)index) + Twine(" for " + "symbol at index ") + Twine(getSymbolIndex(Symb)) + + Twine(")")); } return section_iterator(SectionRef(DRI, this)); } -- cgit v1.1