aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/DebugInfo/DWARFUnit.cpp
diff options
context:
space:
mode:
authorAlexey Samsonov <vonosmas@gmail.com>2014-09-05 19:29:45 +0000
committerAlexey Samsonov <vonosmas@gmail.com>2014-09-05 19:29:45 +0000
commitd3e121331bafa274b654bf2e1691cde628b7ff55 (patch)
tree2d7c338cd2fbd0a25618f9d4433502243a9f105b /llvm/lib/DebugInfo/DWARFUnit.cpp
parente4d4801c3a644923c672e25dc3a76bef9973c494 (diff)
downloadllvm-d3e121331bafa274b654bf2e1691cde628b7ff55.zip
llvm-d3e121331bafa274b654bf2e1691cde628b7ff55.tar.gz
llvm-d3e121331bafa274b654bf2e1691cde628b7ff55.tar.bz2
[DWARF parser] Fix nasty memory corruption in .dwo files handling.
Forge a test case where llvm-symbolizer has to use external .dwo file to produce the inlining information. llvm-svn: 217270
Diffstat (limited to 'llvm/lib/DebugInfo/DWARFUnit.cpp')
-rw-r--r--llvm/lib/DebugInfo/DWARFUnit.cpp20
1 files changed, 9 insertions, 11 deletions
diff --git a/llvm/lib/DebugInfo/DWARFUnit.cpp b/llvm/lib/DebugInfo/DWARFUnit.cpp
index fe75ebe..2bb7933 100644
--- a/llvm/lib/DebugInfo/DWARFUnit.cpp
+++ b/llvm/lib/DebugInfo/DWARFUnit.cpp
@@ -235,11 +235,14 @@ size_t DWARFUnit::extractDIEsIfNeeded(bool CUDieOnly) {
return DieArray.size();
}
-DWARFUnit::DWOHolder::DWOHolder(std::unique_ptr<object::ObjectFile> DWOFile)
- : DWOFile(std::move(DWOFile)),
- DWOContext(
- cast<DWARFContext>(DIContext::getDWARFContext(*this->DWOFile))),
- DWOU(nullptr) {
+DWARFUnit::DWOHolder::DWOHolder(StringRef DWOPath)
+ : DWOFile(), DWOContext(), DWOU(nullptr) {
+ auto Obj = object::ObjectFile::createObjectFile(DWOPath);
+ if (!Obj)
+ return;
+ DWOFile = std::move(Obj.get());
+ DWOContext.reset(
+ cast<DWARFContext>(DIContext::getDWARFContext(*DWOFile.getBinary())));
if (DWOContext->getNumDWOCompileUnits() > 0)
DWOU = DWOContext->getDWOCompileUnitAtIndex(0);
}
@@ -261,12 +264,7 @@ bool DWARFUnit::parseDWO() {
sys::path::append(AbsolutePath, CompilationDir);
}
sys::path::append(AbsolutePath, DWOFileName);
- ErrorOr<object::OwningBinary<object::ObjectFile>> DWOFile =
- object::ObjectFile::createObjectFile(AbsolutePath);
- if (!DWOFile)
- return false;
- // Reset DWOHolder.
- DWO = llvm::make_unique<DWOHolder>(std::move(DWOFile->getBinary()));
+ DWO = llvm::make_unique<DWOHolder>(AbsolutePath);
DWARFUnit *DWOCU = DWO->getUnit();
// Verify that compile unit in .dwo file is valid.
if (!DWOCU || DWOCU->getDWOId() != getDWOId()) {