diff options
author | George Rimar <grimar@accesssoftek.com> | 2019-08-14 08:56:55 +0000 |
---|---|---|
committer | George Rimar <grimar@accesssoftek.com> | 2019-08-14 08:56:55 +0000 |
commit | 468919e18231d0c30b5c0f84a87145db06e3554b (patch) | |
tree | e1dbabaed556c88253db5a4bc75935b923ecf595 /llvm/lib | |
parent | a0c6a3571422826e856002714d9bb008584fe8b3 (diff) | |
download | bcm5719-llvm-468919e18231d0c30b5c0f84a87145db06e3554b.tar.gz bcm5719-llvm-468919e18231d0c30b5c0f84a87145db06e3554b.zip |
Revert r368812 "[llvm/Object] - Convert SectionRef::getName() to return Expected<>"
It broke clang BB: http://lab.llvm.org:8011/builders/clang-x86_64-debian-fast/builds/16455
llvm-svn: 368813
Diffstat (limited to 'llvm/lib')
17 files changed, 63 insertions, 113 deletions
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp index 2379ba66aa3..4b66a305a3d 100644 --- a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp @@ -1506,11 +1506,7 @@ public: StringMap<unsigned> SectionAmountMap; for (const SectionRef &Section : Obj.sections()) { StringRef Name; - if (auto NameOrErr = Section.getName()) - Name = *NameOrErr; - else - consumeError(NameOrErr.takeError()); - + Section.getName(Name); ++SectionAmountMap[Name]; SectionNames.push_back({ Name, true }); @@ -1575,15 +1571,12 @@ public: continue; StringRef RelSecName; - if (auto NameOrErr = RelocatedSection->getName()) - RelSecName = *NameOrErr; - else - consumeError(NameOrErr.takeError()); + StringRef RelSecData; + RelocatedSection->getName(RelSecName); // If the section we're relocating was relocated already by the JIT, // then we used the relocated version above, so we do not need to process // relocations for it now. - StringRef RelSecData; if (L && L->getLoadedSectionContents(*RelocatedSection, RelSecData)) continue; diff --git a/llvm/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp b/llvm/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp index b4d49d9ff95..bc4070b1d81 100644 --- a/llvm/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp +++ b/llvm/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp @@ -54,11 +54,10 @@ SymbolizableObjectFile::create(const object::ObjectFile *Obj, // PowerPC64 ELF. if (Obj->getArch() == Triple::ppc64) { for (section_iterator Section : Obj->sections()) { - Expected<StringRef> NameOrErr = Section->getName(); - if (!NameOrErr) - return errorToErrorCode(NameOrErr.takeError()); - - if (*NameOrErr == ".opd") { + StringRef Name; + if (auto EC = Section->getName(Name)) + return EC; + if (Name == ".opd") { Expected<StringRef> E = Section->getContents(); if (!E) return errorToErrorCode(E.takeError()); diff --git a/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp b/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp index a5559373b05..271d0cc6f44 100644 --- a/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp +++ b/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp @@ -259,11 +259,7 @@ bool getGNUDebuglinkContents(const ObjectFile *Obj, std::string &DebugName, return false; for (const SectionRef &Section : Obj->sections()) { StringRef Name; - if (Expected<StringRef> NameOrErr = Section.getName()) - Name = *NameOrErr; - else - consumeError(NameOrErr.takeError()); - + Section.getName(Name); Name = Name.substr(Name.find_first_not_of("._")); if (Name == "gnu_debuglink") { Expected<StringRef> ContentsOrErr = Section.getContents(); diff --git a/llvm/lib/ExecutionEngine/JITLink/MachOAtomGraphBuilder.cpp b/llvm/lib/ExecutionEngine/JITLink/MachOAtomGraphBuilder.cpp index 92c7e49039a..1501c7ad0bc 100644 --- a/llvm/lib/ExecutionEngine/JITLink/MachOAtomGraphBuilder.cpp +++ b/llvm/lib/ExecutionEngine/JITLink/MachOAtomGraphBuilder.cpp @@ -96,10 +96,9 @@ Error MachOAtomGraphBuilder::parseSections() { assert((SecRef.getAlignment() <= std::numeric_limits<uint32_t>::max()) && "Section alignment does not fit in 32 bits"); - Expected<StringRef> NameOrErr = SecRef.getName(); - if (!NameOrErr) - return NameOrErr.takeError(); - StringRef Name = *NameOrErr; + StringRef Name; + if (auto EC = SecRef.getName(Name)) + return errorCodeToError(EC); unsigned SectionIndex = SecRef.getIndex() + 1; diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp index 4b328624ccd..f73d1c61edf 100644 --- a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp +++ b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp @@ -535,10 +535,9 @@ Error RuntimeDyldImpl::computeTotalAllocSize(const ObjectFile &Obj, bool IsCode = Section.isText(); bool IsReadOnly = isReadOnlyData(Section); - Expected<StringRef> NameOrErr = Section.getName(); - if (!NameOrErr) - return NameOrErr.takeError(); - StringRef Name = *NameOrErr; + StringRef Name; + if (auto EC = Section.getName(Name)) + return errorCodeToError(EC); uint64_t StubBufSize = computeSectionStubBufSize(Obj, Section); @@ -778,10 +777,9 @@ RuntimeDyldImpl::emitSection(const ObjectFile &Obj, // anyway, so we should guarantee that the alignment is always at least 1. Alignment = std::max(1u, Alignment); - Expected<StringRef> NameOrErr = Section.getName(); - if (!NameOrErr) - return NameOrErr.takeError(); - StringRef Name = *NameOrErr; + StringRef Name; + if (auto EC = Section.getName(Name)) + return errorCodeToError(EC); StubBufSize = computeSectionStubBufSize(Obj, Section); diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp index e3ace265f9c..60041a45e2b 100644 --- a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp +++ b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp @@ -160,13 +160,9 @@ createRTDyldELFObject(MemoryBufferRef Buffer, const ObjectFile &SourceObject, // Iterate over all sections in the object. auto SI = SourceObject.section_begin(); for (const auto &Sec : Obj->sections()) { - Expected<StringRef> NameOrErr = Sec.getName(); - if (!NameOrErr) { - consumeError(NameOrErr.takeError()); - continue; - } - - if (*NameOrErr != "") { + StringRef SectionName; + Sec.getName(SectionName); + if (SectionName != "") { DataRefImpl ShdrRef = Sec.getRawDataRefImpl(); Elf_Shdr *shdr = const_cast<Elf_Shdr *>( reinterpret_cast<const Elf_Shdr *>(ShdrRef.p)); @@ -571,11 +567,10 @@ Error RuntimeDyldELF::findPPC64TOCSection(const ELFObjectFileBase &Obj, // The TOC consists of sections .got, .toc, .tocbss, .plt in that // order. The TOC starts where the first of these sections starts. - for (auto &Section : Obj.sections()) { - Expected<StringRef> NameOrErr = Section.getName(); - if (!NameOrErr) - return NameOrErr.takeError(); - StringRef SectionName = *NameOrErr; + for (auto &Section: Obj.sections()) { + StringRef SectionName; + if (auto EC = Section.getName(SectionName)) + return errorCodeToError(EC); if (SectionName == ".got" || SectionName == ".toc" @@ -610,10 +605,9 @@ Error RuntimeDyldELF::findOPDEntrySection(const ELFObjectFileBase &Obj, if (RelSecI == Obj.section_end()) continue; - Expected<StringRef> NameOrErr = RelSecI->getName(); - if (!NameOrErr) - return NameOrErr.takeError(); - StringRef RelSectionName = *NameOrErr; + StringRef RelSectionName; + if (auto EC = RelSecI->getName(RelSectionName)) + return errorCodeToError(EC); if (RelSectionName != ".opd") continue; @@ -1885,14 +1879,8 @@ Error RuntimeDyldELF::finalizeLoad(const ObjectFile &Obj, ObjSectionToIDMap::iterator i, e; for (i = SectionMap.begin(), e = SectionMap.end(); i != e; ++i) { const SectionRef &Section = i->first; - StringRef Name; - Expected<StringRef> NameOrErr = Section.getName(); - if (NameOrErr) - Name = *NameOrErr; - else - consumeError(NameOrErr.takeError()); - + Section.getName(Name); if (Name == ".eh_frame") { UnregisteredEHFrameSections.push_back(i->second); break; diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp index fbdfb8d5c3a..202c3ca1c50 100644 --- a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp +++ b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp @@ -233,10 +233,7 @@ RuntimeDyldMachOCRTPBase<Impl>::finalizeLoad(const ObjectFile &Obj, for (const auto &Section : Obj.sections()) { StringRef Name; - if (Expected<StringRef> NameOrErr = Section.getName()) - Name = *NameOrErr; - else - consumeError(NameOrErr.takeError()); + Section.getName(Name); // Force emission of the __text, __eh_frame, and __gcc_except_tab sections // if they're present. Otherwise call down to the impl to handle other diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFX86_64.h b/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFX86_64.h index dc4af08583d..d2d74534cf9 100644 --- a/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFX86_64.h +++ b/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFX86_64.h @@ -284,14 +284,14 @@ public: // Look for and record the EH frame section IDs. for (const auto &SectionPair : SectionMap) { const object::SectionRef &Section = SectionPair.first; - Expected<StringRef> NameOrErr = Section.getName(); - if (!NameOrErr) - return NameOrErr.takeError(); + StringRef Name; + if (auto EC = Section.getName(Name)) + return errorCodeToError(EC); // Note unwind info is stored in .pdata but often points to .xdata // with an IMAGE_REL_AMD64_ADDR32NB relocation. Using a memory manager // that keeps sections ordered in relation to __ImageBase is necessary. - if ((*NameOrErr) == ".pdata") + if (Name == ".pdata") UnregisteredEHFrameSections.push_back(SectionPair.second); } return Error::success(); diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOARM.h b/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOARM.h index a76958a9e2c..3bec8b979f7 100644 --- a/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOARM.h +++ b/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOARM.h @@ -289,10 +289,7 @@ public: Error finalizeSection(const ObjectFile &Obj, unsigned SectionID, const SectionRef &Section) { StringRef Name; - if (Expected<StringRef> NameOrErr = Section.getName()) - Name = *NameOrErr; - else - consumeError(NameOrErr.takeError()); + Section.getName(Name); if (Name == "__nl_symbol_ptr") return populateIndirectSymbolPointersSection(cast<MachOObjectFile>(Obj), diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOI386.h b/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOI386.h index 523deb29b72..f0de27ba14b 100644 --- a/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOI386.h +++ b/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOI386.h @@ -128,10 +128,7 @@ public: Error finalizeSection(const ObjectFile &Obj, unsigned SectionID, const SectionRef &Section) { StringRef Name; - if (Expected<StringRef> NameOrErr = Section.getName()) - Name = *NameOrErr; - else - consumeError(NameOrErr.takeError()); + Section.getName(Name); if (Name == "__jump_table") return populateJumpTable(cast<MachOObjectFile>(Obj), Section, SectionID); diff --git a/llvm/lib/Object/COFFObjectFile.cpp b/llvm/lib/Object/COFFObjectFile.cpp index afd68694deb..854664e679d 100644 --- a/llvm/lib/Object/COFFObjectFile.cpp +++ b/llvm/lib/Object/COFFObjectFile.cpp @@ -994,12 +994,11 @@ std::error_code COFFObjectFile::getSection(int32_t Index, std::error_code COFFObjectFile::getSection(StringRef SectionName, const coff_section *&Result) const { Result = nullptr; + StringRef SecName; for (const SectionRef &Section : sections()) { - auto NameOrErr = Section.getName(); - if (!NameOrErr) - return errorToErrorCode(NameOrErr.takeError()); - - if (*NameOrErr == SectionName) { + if (std::error_code E = Section.getName(SecName)) + return E; + if (SecName == SectionName) { Result = getCOFFSection(Section); return std::error_code(); } diff --git a/llvm/lib/Object/Decompressor.cpp b/llvm/lib/Object/Decompressor.cpp index 11efd857d1a..53b8e846e5f 100644 --- a/llvm/lib/Object/Decompressor.cpp +++ b/llvm/lib/Object/Decompressor.cpp @@ -77,15 +77,10 @@ bool Decompressor::isGnuStyle(StringRef Name) { } bool Decompressor::isCompressed(const object::SectionRef &Section) { - if (Section.isCompressed()) - return true; - - Expected<StringRef> SecNameOrErr = Section.getName(); - if (SecNameOrErr) - return isGnuStyle(*SecNameOrErr); - - consumeError(SecNameOrErr.takeError()); - return false; + StringRef Name; + if (Section.getName(Name)) + return false; + return Section.isCompressed() || isGnuStyle(Name); } bool Decompressor::isCompressedELFSection(uint64_t Flags, StringRef Name) { diff --git a/llvm/lib/Object/ELFObjectFile.cpp b/llvm/lib/Object/ELFObjectFile.cpp index f3b0347088a..9945018d957 100644 --- a/llvm/lib/Object/ELFObjectFile.cpp +++ b/llvm/lib/Object/ELFObjectFile.cpp @@ -392,13 +392,9 @@ ELFObjectFileBase::getPltAddresses() const { return {}; Optional<SectionRef> Plt = None, RelaPlt = None, GotPlt = None; for (const SectionRef &Section : sections()) { - Expected<StringRef> NameOrErr = Section.getName(); - if (!NameOrErr) { - consumeError(NameOrErr.takeError()); + StringRef Name; + if (Section.getName(Name)) continue; - } - StringRef Name = *NameOrErr; - if (Name == ".plt") Plt = Section; else if (Name == ".rela.plt" || Name == ".rel.plt") diff --git a/llvm/lib/Object/MachOObjectFile.cpp b/llvm/lib/Object/MachOObjectFile.cpp index 179166ddbd3..3bfbfe06944 100644 --- a/llvm/lib/Object/MachOObjectFile.cpp +++ b/llvm/lib/Object/MachOObjectFile.cpp @@ -1986,12 +1986,13 @@ Expected<SectionRef> MachOObjectFile::getSection(unsigned SectionIndex) const { } Expected<SectionRef> MachOObjectFile::getSection(StringRef SectionName) const { + StringRef SecName; for (const SectionRef &Section : sections()) { - auto NameOrErr = Section.getName(); - if (!NameOrErr) - return NameOrErr.takeError(); - if (*NameOrErr == SectionName) + if (std::error_code E = Section.getName(SecName)) + return errorCodeToError(E); + if (SecName == SectionName) { return Section; + } } return errorCodeToError(object_error::parse_failed); } @@ -3994,11 +3995,7 @@ BindRebaseSegInfo::BindRebaseSegInfo(const object::MachOObjectFile *Obj) { uint64_t CurSegAddress; for (const SectionRef &Section : Obj->sections()) { SectionInfo Info; - Expected<StringRef> NameOrErr = Section.getName(); - if (!NameOrErr) - consumeError(NameOrErr.takeError()); - else - Info.SectionName = *NameOrErr; + Section.getName(Info.SectionName); Info.Address = Section.getAddress(); Info.Size = Section.getSize(); Info.SegmentName = diff --git a/llvm/lib/Object/Object.cpp b/llvm/lib/Object/Object.cpp index b518e2d02c9..d84798cc6dd 100644 --- a/llvm/lib/Object/Object.cpp +++ b/llvm/lib/Object/Object.cpp @@ -251,10 +251,10 @@ void LLVMMoveToNextSymbol(LLVMSymbolIteratorRef SI) { // SectionRef accessors const char *LLVMGetSectionName(LLVMSectionIteratorRef SI) { - auto NameOrErr = (*unwrap(SI))->getName(); - if (!NameOrErr) - report_fatal_error(NameOrErr.takeError()); - return NameOrErr->data(); + StringRef ret; + if (std::error_code ec = (*unwrap(SI))->getName(ret)) + report_fatal_error(ec.message()); + return ret.data(); } uint64_t LLVMGetSectionSize(LLVMSectionIteratorRef SI) { diff --git a/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp b/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp index e70bc318b84..e193e10f91d 100644 --- a/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp +++ b/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp @@ -666,11 +666,11 @@ static Expected<SectionRef> lookupSection(ObjectFile &OF, StringRef Name) { }; Name = stripSuffix(Name); + StringRef FoundName; for (const auto &Section : OF.sections()) { - Expected<StringRef> NameOrErr = Section.getName(); - if (!NameOrErr) - return NameOrErr.takeError(); - if (stripSuffix(*NameOrErr) == Name) + if (auto EC = Section.getName(FoundName)) + return errorCodeToError(EC); + if (stripSuffix(FoundName) == Name) return Section; } return make_error<CoverageMapError>(coveragemap_error::no_data_found); diff --git a/llvm/lib/XRay/InstrumentationMap.cpp b/llvm/lib/XRay/InstrumentationMap.cpp index 7453613c703..7de953d46b7 100644 --- a/llvm/lib/XRay/InstrumentationMap.cpp +++ b/llvm/lib/XRay/InstrumentationMap.cpp @@ -67,11 +67,10 @@ loadObj(StringRef Filename, object::OwningBinary<object::ObjectFile> &ObjFile, StringRef Contents = ""; const auto &Sections = ObjFile.getBinary()->sections(); auto I = llvm::find_if(Sections, [&](object::SectionRef Section) { - Expected<StringRef> NameOrErr = Section.getName(); - if (NameOrErr) - return *NameOrErr == "xray_instr_map"; - consumeError(NameOrErr.takeError()); - return false; + StringRef Name = ""; + if (Section.getName(Name)) + return false; + return Name == "xray_instr_map"; }); if (I == Sections.end()) |