[PATCH] D51365: [llvm-objdump] Keep the memory buffer from the dSYM alive when using -g -dsym

Francis Visoiu Mistrih via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 28 10:02:14 PDT 2018


thegameg created this revision.
thegameg added reviewers: JDevlieghere, kastiglione, aprantl, bkramer.

When using `-g` and `-dsym`, llvm-objdump opens the dSYM file and keeps the MachOObjectFile alive, while the memory buffer that the MachOObjectFile was based on gets destroyed.

This segfaults with a pretty large file. I am open to suggestions on how to test this even if it doesn't really segfault, since it seems that there are no `-g` nor `-dsym` tests for llvm-objdump.


https://reviews.llvm.org/D51365

Files:
  tools/llvm-objdump/MachODump.cpp


Index: tools/llvm-objdump/MachODump.cpp
===================================================================
--- tools/llvm-objdump/MachODump.cpp
+++ tools/llvm-objdump/MachODump.cpp
@@ -6947,6 +6947,7 @@
 
   std::unique_ptr<DIContext> diContext;
   ObjectFile *DbgObj = MachOOF;
+  std::unique_ptr<MemoryBuffer> DSYMBuf;
   // Try to find debug info and set up the DIContext for it.
   if (UseDbg) {
     // A separate DSym file path was specified, parse it as a macho file,
@@ -6964,6 +6965,8 @@
       if (DbgObjCheck.takeError())
         report_error(MachOOF->getFileName(), DbgObjCheck.takeError());
       DbgObj = DbgObjCheck.get().release();
+      // We need to keep the file alive, because we're replacing DbgObj with it.
+      DSYMBuf = std::move(BufOrErr.get());
     }
 
     // Setup the DIContext


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51365.162892.patch
Type: text/x-patch
Size: 814 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180828/30b39986/attachment.bin>


More information about the llvm-commits mailing list