summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorFangrui Song <maskray@google.com>2019-05-16 13:24:04 +0000
committerFangrui Song <maskray@google.com>2019-05-16 13:24:04 +0000
commite183340c29db62e3c93c59c403984ad675d72c83 (patch)
tree21ec750631cf5febc8acfa3d2d6b35fc72538e96 /llvm/lib
parent1b93a24c297117c455a126f1c3e858fefe410c2f (diff)
downloadbcm5719-llvm-e183340c29db62e3c93c59c403984ad675d72c83.tar.gz
bcm5719-llvm-e183340c29db62e3c93c59c403984ad675d72c83.zip
Recommit [Object] Change object::SectionRef::getContents() to return Expected<StringRef>
r360876 didn't fix 2 call sites in clang. Expected<ArrayRef<uint8_t>> may be better but use Expected<StringRef> for now. Follow-up of D61781. llvm-svn: 360892
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/DebugInfo/DWARF/DWARFContext.cpp10
-rw-r--r--llvm/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp8
-rw-r--r--llvm/lib/DebugInfo/Symbolize/Symbolize.cpp9
-rw-r--r--llvm/lib/ExecutionEngine/JITLink/MachOAtomGraphBuilder.cpp10
-rw-r--r--llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp6
-rw-r--r--llvm/lib/Object/ELFObjectFile.cpp11
-rw-r--r--llvm/lib/Object/IRObjectFile.cpp10
-rw-r--r--llvm/lib/Object/Object.cpp8
-rw-r--r--llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp13
-rw-r--r--llvm/lib/XRay/InstrumentationMap.cpp7
10 files changed, 55 insertions, 37 deletions
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
index 720fadb0dc7..160a171176a 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
@@ -1410,8 +1410,14 @@ public:
// Try to obtain an already relocated version of this section.
// Else use the unrelocated section from the object file. We'll have to
// apply relocations ourselves later.
- if (!L || !L->getLoadedSectionContents(*RelocatedSection, Data))
- Section.getContents(Data);
+ if (!L || !L->getLoadedSectionContents(*RelocatedSection, Data)) {
+ Expected<StringRef> E = Section.getContents();
+ if (E)
+ Data = *E;
+ else
+ // maybeDecompress below will error.
+ consumeError(E.takeError());
+ }
if (auto Err = maybeDecompress(Section, Name, Data)) {
ErrorPolicy EP = HandleError(createError(
diff --git a/llvm/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp b/llvm/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp
index 5d453def7b4..fc529630e97 100644
--- a/llvm/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp
+++ b/llvm/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp
@@ -53,13 +53,13 @@ SymbolizableObjectFile::create(object::ObjectFile *Obj,
if (Obj->getArch() == Triple::ppc64) {
for (section_iterator Section : Obj->sections()) {
StringRef Name;
- StringRef Data;
if (auto EC = Section->getName(Name))
return EC;
if (Name == ".opd") {
- if (auto EC = Section->getContents(Data))
- return EC;
- OpdExtractor.reset(new DataExtractor(Data, Obj->isLittleEndian(),
+ Expected<StringRef> E = Section->getContents();
+ if (!E)
+ return errorToErrorCode(E.takeError());
+ OpdExtractor.reset(new DataExtractor(*E, Obj->isLittleEndian(),
Obj->getBytesInAddress()));
OpdAddress = Section->getAddress();
break;
diff --git a/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp b/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp
index 7e91a20416b..00e4139c0ba 100644
--- a/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp
+++ b/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp
@@ -221,9 +221,12 @@ bool getGNUDebuglinkContents(const ObjectFile *Obj, std::string &DebugName,
Section.getName(Name);
Name = Name.substr(Name.find_first_not_of("._"));
if (Name == "gnu_debuglink") {
- StringRef Data;
- Section.getContents(Data);
- DataExtractor DE(Data, Obj->isLittleEndian(), 0);
+ Expected<StringRef> ContentsOrErr = Section.getContents();
+ if (!ContentsOrErr) {
+ consumeError(ContentsOrErr.takeError());
+ return false;
+ }
+ DataExtractor DE(*ContentsOrErr, Obj->isLittleEndian(), 0);
uint32_t Offset = 0;
if (const char *DebugNameStr = DE.getCStr(&Offset)) {
// 4-byte align the offset.
diff --git a/llvm/lib/ExecutionEngine/JITLink/MachOAtomGraphBuilder.cpp b/llvm/lib/ExecutionEngine/JITLink/MachOAtomGraphBuilder.cpp
index d1cf8755e75..1501c7ad0bc 100644
--- a/llvm/lib/ExecutionEngine/JITLink/MachOAtomGraphBuilder.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/MachOAtomGraphBuilder.cpp
@@ -136,14 +136,14 @@ Error MachOAtomGraphBuilder::parseSections() {
if (!SecRef.isVirtual()) {
// If this section has content then record it.
- StringRef Content;
- if (auto EC = SecRef.getContents(Content))
- return errorCodeToError(EC);
- if (Content.size() != SecRef.getSize())
+ Expected<StringRef> Content = SecRef.getContents();
+ if (!Content)
+ return Content.takeError();
+ if (Content->size() != SecRef.getSize())
return make_error<JITLinkError>("Section content size does not match "
"declared size for " +
Name);
- MachOSec.setContent(Content);
+ MachOSec.setContent(*Content);
} else {
// If this is a zero-fill section then just record the size.
MachOSec.setZeroFill(SecRef.getSize());
diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
index 2fd677ab13a..f99868db443 100644
--- a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
+++ b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
@@ -792,8 +792,10 @@ RuntimeDyldImpl::emitSection(const ObjectFile &Obj,
if (!IsVirtual && !IsZeroInit) {
// In either case, set the location of the unrelocated section in memory,
// since we still process relocations for it even if we're not applying them.
- if (auto EC = Section.getContents(data))
- return errorCodeToError(EC);
+ if (Expected<StringRef> E = Section.getContents())
+ data = *E;
+ else
+ return E.takeError();
pData = data.data();
}
diff --git a/llvm/lib/Object/ELFObjectFile.cpp b/llvm/lib/Object/ELFObjectFile.cpp
index cc1eeefec26..c0ac7a357f8 100644
--- a/llvm/lib/Object/ELFObjectFile.cpp
+++ b/llvm/lib/Object/ELFObjectFile.cpp
@@ -377,12 +377,13 @@ ELFObjectFileBase::getPltAddresses() const {
}
if (!Plt || !RelaPlt || !GotPlt)
return {};
- StringRef PltContents;
- if (Plt->getContents(PltContents))
+ Expected<StringRef> PltContents = Plt->getContents();
+ if (!PltContents) {
+ consumeError(PltContents.takeError());
return {};
- ArrayRef<uint8_t> PltBytes((const uint8_t *)PltContents.data(),
- Plt->getSize());
- auto PltEntries = MIA->findPltEntries(Plt->getAddress(), PltBytes,
+ }
+ auto PltEntries = MIA->findPltEntries(Plt->getAddress(),
+ arrayRefFromStringRef(*PltContents),
GotPlt->getAddress(), Triple);
// Build a map from GOT entry virtual address to PLT entry virtual address.
DenseMap<uint64_t, uint64_t> GotToPlt;
diff --git a/llvm/lib/Object/IRObjectFile.cpp b/llvm/lib/Object/IRObjectFile.cpp
index debe7899bfe..636f1521262 100644
--- a/llvm/lib/Object/IRObjectFile.cpp
+++ b/llvm/lib/Object/IRObjectFile.cpp
@@ -74,12 +74,12 @@ Expected<MemoryBufferRef>
IRObjectFile::findBitcodeInObject(const ObjectFile &Obj) {
for (const SectionRef &Sec : Obj.sections()) {
if (Sec.isBitcode()) {
- StringRef SecContents;
- if (std::error_code EC = Sec.getContents(SecContents))
- return errorCodeToError(EC);
- if (SecContents.size() <= 1)
+ Expected<StringRef> Contents = Sec.getContents();
+ if (!Contents)
+ return Contents.takeError();
+ if (Contents->size() <= 1)
return errorCodeToError(object_error::bitcode_section_not_found);
- return MemoryBufferRef(SecContents, Obj.getFileName());
+ return MemoryBufferRef(*Contents, Obj.getFileName());
}
}
diff --git a/llvm/lib/Object/Object.cpp b/llvm/lib/Object/Object.cpp
index 77e27ec3e8f..e2511b7aed0 100644
--- a/llvm/lib/Object/Object.cpp
+++ b/llvm/lib/Object/Object.cpp
@@ -247,10 +247,10 @@ uint64_t LLVMGetSectionSize(LLVMSectionIteratorRef SI) {
}
const char *LLVMGetSectionContents(LLVMSectionIteratorRef SI) {
- StringRef ret;
- if (std::error_code ec = (*unwrap(SI))->getContents(ret))
- report_fatal_error(ec.message());
- return ret.data();
+ if (Expected<StringRef> E = (*unwrap(SI))->getContents())
+ return E->data();
+ else
+ report_fatal_error(E.takeError());
}
uint64_t LLVMGetSectionAddress(LLVMSectionIteratorRef SI) {
diff --git a/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp b/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
index fd522dc309e..b93c1805665 100644
--- a/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
+++ b/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
@@ -348,8 +348,10 @@ Expected<bool> RawCoverageMappingDummyChecker::isDummy() {
}
Error InstrProfSymtab::create(SectionRef &Section) {
- if (auto EC = Section.getContents(Data))
- return errorCodeToError(EC);
+ Expected<StringRef> DataOrErr = Section.getContents();
+ if (!DataOrErr)
+ return DataOrErr.takeError();
+ Data = *DataOrErr;
Address = Section.getAddress();
// If this is a linked PE/COFF file, then we have to skip over the null byte
@@ -687,8 +689,11 @@ static Error loadBinaryFormat(MemoryBufferRef ObjectBuffer,
return E;
// Get the contents of the given sections.
- if (auto EC = CoverageSection->getContents(CoverageMapping))
- return errorCodeToError(EC);
+ if (Expected<StringRef> E = CoverageSection->getContents())
+ CoverageMapping = *E;
+ else
+ return E.takeError();
+
if (Error E = ProfileNames.create(*NamesSection))
return E;
diff --git a/llvm/lib/XRay/InstrumentationMap.cpp b/llvm/lib/XRay/InstrumentationMap.cpp
index 862949f578c..2eeb4559021 100644
--- a/llvm/lib/XRay/InstrumentationMap.cpp
+++ b/llvm/lib/XRay/InstrumentationMap.cpp
@@ -78,9 +78,10 @@ loadObj(StringRef Filename, object::OwningBinary<object::ObjectFile> &ObjFile,
"Failed to find XRay instrumentation map.",
std::make_error_code(std::errc::executable_format_error));
- if (I->getContents(Contents))
- return errorCodeToError(
- std::make_error_code(std::errc::executable_format_error));
+ if (Expected<StringRef> E = I->getContents())
+ Contents = *E;
+ else
+ return E.takeError();
RelocMap Relocs;
if (ObjFile.getBinary()->isELF()) {
OpenPOWER on IntegriCloud