[lld] r359774 - [Object] Change getSectionName() to return Expected<StringRef>
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Thu May 2 03:32:03 PDT 2019
Author: maskray
Date: Thu May 2 03:32:03 2019
New Revision: 359774
URL: http://llvm.org/viewvc/llvm-project?rev=359774&view=rev
Log:
[Object] Change getSectionName() to return Expected<StringRef>
Summary:
It currently receives an output parameter and returns
std::error_code. Expected<StringRef> fits for this purpose perfectly.
Differential Revision: https://reviews.llvm.org/D61421
Modified:
lld/trunk/COFF/Chunks.cpp
lld/trunk/COFF/InputFiles.cpp
Modified: lld/trunk/COFF/Chunks.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Chunks.cpp?rev=359774&r1=359773&r2=359774&view=diff
==============================================================================
--- lld/trunk/COFF/Chunks.cpp (original)
+++ lld/trunk/COFF/Chunks.cpp Thu May 2 03:32:03 2019
@@ -33,7 +33,8 @@ SectionChunk::SectionChunk(ObjFile *F, c
: Chunk(SectionKind), File(F), Header(H),
Relocs(File->getCOFFObj()->getRelocations(Header)), Repl(this) {
// Initialize SectionName.
- File->getCOFFObj()->getSectionName(Header, SectionName);
+ if (Expected<StringRef> E = File->getCOFFObj()->getSectionName(Header))
+ SectionName = *E;
Alignment = Header->getAlignment();
Modified: lld/trunk/COFF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/InputFiles.cpp?rev=359774&r1=359773&r2=359774&view=diff
==============================================================================
--- lld/trunk/COFF/InputFiles.cpp (original)
+++ lld/trunk/COFF/InputFiles.cpp Thu May 2 03:32:03 2019
@@ -168,9 +168,11 @@ SectionChunk *ObjFile::readSection(uint3
const coff_section *Sec = getSection(SectionNumber);
StringRef Name;
- if (auto EC = COFFObj->getSectionName(Sec, Name))
+ if (Expected<StringRef> E = COFFObj->getSectionName(Sec))
+ Name = *E;
+ else
fatal("getSectionName failed: #" + Twine(SectionNumber) + ": " +
- EC.message());
+ toString(E.takeError()));
if (Name == ".drectve") {
ArrayRef<uint8_t> Data;
@@ -242,7 +244,8 @@ void ObjFile::readAssociativeDefinition(
COFFObj->getSymbolName(Sym, Name);
const coff_section *ParentSec = getSection(ParentIndex);
- COFFObj->getSectionName(ParentSec, ParentName);
+ if (Expected<StringRef> E = COFFObj->getSectionName(ParentSec))
+ ParentName = *E;
error(toString(this) + ": associative comdat " + Name + " (sec " +
Twine(SectionNumber) + ") has invalid reference to section " +
ParentName + " (sec " + Twine(ParentIndex) + ")");
More information about the llvm-commits
mailing list