[PATCH] D73531: [llvm-objdump] avoid crash disassembling unknown instruction

Sjoerd Meijer via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 28 01:10:52 PST 2020


SjoerdMeijer created this revision.
SjoerdMeijer added reviewers: MaskRay, jhenderson, grimar, thegameg.
Herald added a subscriber: rupprecht.
Herald added a project: LLVM.

llvm-obj dump can crash when it can't disassemble an instruction:

  llvm-objdump: llvm/include/llvm/ADT/SmallVector.h:153: llvm::SmallVectorTemplateCommon::const_reference llvm::SmallVectorTemplateCommon<llvm::MCOperand, void>::operator[](llvm::SmallVectorTemplateCommon::size_type) const [T = llvm::MCOperand]: Assertion `idx < size()' failed.

This can happen when the source is compiled with:

  clang -march=..+ext1+ext2

and disassembly is attempted with:

  llvm-objdump -mattr=+ext1
    

I.e., it isn't given the same architecture extensions.  I have tried adding a test case, by taking our proprietary disassembler and generate the assembly code for the offending assembly sequence, let llvm-mc assemble that, and then llvm-objdump disassemble it again:

  llvm-mc -assemble  ... | llvm-objdump -disassemble ..

but I just can't reproduce it in this way; llvm-mc or llvm-objdump is perhaps behaving slightly differently, perhaps there's some state somewhere. I have visually inspected the code though: first of all, it no longer crashes, and also it looks okay (and the test suite passes).


https://reviews.llvm.org/D73531

Files:
  llvm/tools/llvm-objdump/llvm-objdump.cpp


Index: llvm/tools/llvm-objdump/llvm-objdump.cpp
===================================================================
--- llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -1431,6 +1431,12 @@
         outs() << CommentStream.str();
         Comments.clear();
 
+        if (!Disassembled) {
+          outs() << "\n";
+          Index += Size;
+          continue;
+        }
+
         // Try to resolve the target of a call, tail call, etc. to a specific
         // symbol.
         if (MIA && (MIA->isCall(Inst) || MIA->isUnconditionalBranch(Inst) ||


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D73531.240793.patch
Type: text/x-patch
Size: 592 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200128/ca55eb83/attachment.bin>


More information about the llvm-commits mailing list