[llvm] r217270 - [DWARF parser] Fix nasty memory corruption in .dwo files handling.
Alexey Samsonov
vonosmas at gmail.com
Fri Sep 5 12:29:46 PDT 2014
Author: samsonov
Date: Fri Sep 5 14:29:45 2014
New Revision: 217270
URL: http://llvm.org/viewvc/llvm-project?rev=217270&view=rev
Log:
[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.
Added:
llvm/trunk/test/DebugInfo/Inputs/split-dwarf-test (with props)
llvm/trunk/test/DebugInfo/Inputs/split-dwarf-test.cc
llvm/trunk/test/DebugInfo/Inputs/split-dwarf-test.dwo (with props)
Modified:
llvm/trunk/lib/DebugInfo/DWARFUnit.cpp
llvm/trunk/lib/DebugInfo/DWARFUnit.h
llvm/trunk/test/DebugInfo/llvm-symbolizer.test
Modified: llvm/trunk/lib/DebugInfo/DWARFUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARFUnit.cpp?rev=217270&r1=217269&r2=217270&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARFUnit.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARFUnit.cpp Fri Sep 5 14:29:45 2014
@@ -235,11 +235,14 @@ size_t DWARFUnit::extractDIEsIfNeeded(bo
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()) {
Modified: llvm/trunk/lib/DebugInfo/DWARFUnit.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARFUnit.h?rev=217270&r1=217269&r2=217270&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARFUnit.h (original)
+++ llvm/trunk/lib/DebugInfo/DWARFUnit.h Fri Sep 5 14:29:45 2014
@@ -51,11 +51,11 @@ class DWARFUnit {
std::vector<DWARFDebugInfoEntryMinimal> DieArray;
class DWOHolder {
- std::unique_ptr<object::ObjectFile> DWOFile;
+ object::OwningBinary<object::ObjectFile> DWOFile;
std::unique_ptr<DWARFContext> DWOContext;
DWARFUnit *DWOU;
public:
- DWOHolder(std::unique_ptr<object::ObjectFile> DWOFile);
+ DWOHolder(StringRef DWOPath);
DWARFUnit *getUnit() const { return DWOU; }
};
std::unique_ptr<DWOHolder> DWO;
Added: llvm/trunk/test/DebugInfo/Inputs/split-dwarf-test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/Inputs/split-dwarf-test?rev=217270&view=auto
==============================================================================
Binary file - no diff available.
Propchange: llvm/trunk/test/DebugInfo/Inputs/split-dwarf-test
------------------------------------------------------------------------------
svn:executable = *
Propchange: llvm/trunk/test/DebugInfo/Inputs/split-dwarf-test
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: llvm/trunk/test/DebugInfo/Inputs/split-dwarf-test.cc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/Inputs/split-dwarf-test.cc?rev=217270&view=auto
==============================================================================
--- llvm/trunk/test/DebugInfo/Inputs/split-dwarf-test.cc (added)
+++ llvm/trunk/test/DebugInfo/Inputs/split-dwarf-test.cc Fri Sep 5 14:29:45 2014
@@ -0,0 +1,17 @@
+int foo(int a) {
+ return a + 1;
+}
+
+int main(int argc, char *argv[]) {
+ return foo(argc);
+}
+
+// Build instructions:
+// 1) clang++ -### -O2 -gsplit-dwarf.cc split-dwarf-test.cc -o split-dwarf-test
+// 2) Replace the value "-fdebug-compilation-dir" flag to "Output"
+// (this is the temp directory used by lit).
+// 3) Manually run clang-cc1, objcopy and ld invocations.
+// 4) Copy the binary and .dwo file to the Inputs directory. Make sure the
+// .dwo file will be available for symbolizer (use test RUN-lines to copy
+// the .dwo file to a directory
+// <execution_directory>/<directory_provided_in_fdebug_compilation_dir>.
Added: llvm/trunk/test/DebugInfo/Inputs/split-dwarf-test.dwo
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/Inputs/split-dwarf-test.dwo?rev=217270&view=auto
==============================================================================
Binary file - no diff available.
Propchange: llvm/trunk/test/DebugInfo/Inputs/split-dwarf-test.dwo
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Modified: llvm/trunk/test/DebugInfo/llvm-symbolizer.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/llvm-symbolizer.test?rev=217270&r1=217269&r2=217270&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/llvm-symbolizer.test (original)
+++ llvm/trunk/test/DebugInfo/llvm-symbolizer.test Fri Sep 5 14:29:45 2014
@@ -19,10 +19,15 @@ RUN: echo "%p/Inputs/macho-universal:x86
RUN: echo "%p/Inputs/llvm-symbolizer-dwo-test 0x400514" >> %t.input
RUN: echo "%p/Inputs/fission-ranges.elf-x86_64 0x720" >> %t.input
RUN: echo "%p/Inputs/arange-overlap.elf-x86_64 0x714" >> %t.input
+RUN: cp %p/Inputs/split-dwarf-test.dwo %T
+RUN: echo "%p/Inputs/split-dwarf-test 0x4004d0" >> %t.input
+RUN: echo "%p/Inputs/split-dwarf-test 0x4004c0" >> %t.input
RUN: llvm-symbolizer --functions=linkage --inlining --demangle=false \
RUN: --default-arch=i386 < %t.input | FileCheck %s
+REQUIRES: shell
+
CHECK: main
CHECK-NEXT: /tmp/dbginfo{{[/\\]}}dwarfdump-test.cc:16
@@ -98,6 +103,14 @@ CHECK-NEXT: {{.*}}fission-ranges.cc:6
CHECK: _ZN1S3bazEv
CHECK-NEXT: {{.*}}arange-overlap.cc:6
+CHECK: _Z3fooi
+CHECK-NEXT: {{.*}}split-dwarf-test.cc
+CHECK-NEXT: main
+CHECK-NEXT: {{.*}}split-dwarf-test.cc
+
+CHECK: _Z3fooi
+CHECK-NEXT: {{.*}}split-dwarf-test.cc
+
RUN: echo "unexisting-file 0x1234" > %t.input2
RUN: llvm-symbolizer < %t.input2
More information about the llvm-commits
mailing list