[llvm] r267250 - llvm-objdump: deal with invalid ARM encodings slightly better.

Tim Northover via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 22 16:23:31 PDT 2016


Author: tnorthover
Date: Fri Apr 22 18:23:31 2016
New Revision: 267250

URL: http://llvm.org/viewvc/llvm-project?rev=267250&view=rev
Log:
llvm-objdump: deal with invalid ARM encodings slightly better.

Before we printed a warning to stderr and left the actual output stream in a
mess. This tries to print a .long or .short representation of what we saw (as
if there was a data-in-code directive).

This isn't guaranteed to restore synchronization in Thumb-mode (if the invalid
instruction was supposed to be 32-bits, we may be off-by-16 for the rest of the
function). But there's no certain way to deal with that, and it's invalid code
anyway (if the data really wasn't an instruction, the user can add proper
.data_in_code directives if they care)

Modified:
    llvm/trunk/test/tools/llvm-objdump/ARM/macho-arm-and-thumb.test
    llvm/trunk/test/tools/llvm-objdump/ARM/macho-v7m.test
    llvm/trunk/tools/llvm-objdump/MachODump.cpp

Modified: llvm/trunk/test/tools/llvm-objdump/ARM/macho-arm-and-thumb.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objdump/ARM/macho-arm-and-thumb.test?rev=267250&r1=267249&r2=267250&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-objdump/ARM/macho-arm-and-thumb.test (original)
+++ llvm/trunk/test/tools/llvm-objdump/ARM/macho-arm-and-thumb.test Fri Apr 22 18:23:31 2016
@@ -10,7 +10,11 @@ nop
 .arm
 _a:
 nop
+.long 0xf8765432
+nop
 
 @ CHECK: 00 bf nop
 @ CHECK-NEXT: 00 bf nop
-@ CHECK: 00 f0 20 e3 nop
+@ CHECK:      00 f0 20 e3 nop
+@ CHECK-NEXT: .long 0xf8765432
+@ CHECK-NEXT: nop

Modified: llvm/trunk/test/tools/llvm-objdump/ARM/macho-v7m.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objdump/ARM/macho-v7m.test?rev=267250&r1=267249&r2=267250&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-objdump/ARM/macho-v7m.test (original)
+++ llvm/trunk/test/tools/llvm-objdump/ARM/macho-v7m.test Fri Apr 22 18:23:31 2016
@@ -6,5 +6,9 @@
 _t:
         @ A nice Cortex-M only instruction to make sure the default CPU is sound.
         msr msp, r0
+        .short 0xf000
+        b _t
 
-@ CHECK: msr msp, r0
\ No newline at end of file
+@ CHECK: msr msp, r0
+@ CHECK: .short 0xf000
+@ CHECK: b _t

Modified: llvm/trunk/tools/llvm-objdump/MachODump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/MachODump.cpp?rev=267250&r1=267249&r2=267250&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/MachODump.cpp (original)
+++ llvm/trunk/tools/llvm-objdump/MachODump.cpp Fri Apr 22 18:23:31 2016
@@ -6034,7 +6034,7 @@ static void DisassembleMachO(StringRef F
     return;
   }
 
-  // Set up thumb disassembler.
+  // Set up separate thumb disassembler if needed.
   std::unique_ptr<const MCRegisterInfo> ThumbMRI;
   std::unique_ptr<const MCAsmInfo> ThumbAsmInfo;
   std::unique_ptr<const MCSubtargetInfo> ThumbSTI;
@@ -6275,8 +6275,11 @@ static void DisassembleMachO(StringRef F
       symbolTableWorked = true;
 
       DataRefImpl Symb = Symbols[SymIdx].getRawDataRefImpl();
-      bool isThumb =
-          (MachOOF->getSymbolFlags(Symb) & SymbolRef::SF_Thumb) && ThumbTarget;
+      bool IsThumb = MachOOF->getSymbolFlags(Symb) & SymbolRef::SF_Thumb;
+
+      // We only need the dedicated Thumb target if there's a real choice
+      // (i.e. we're not targeting M-class) and the function is Thumb.
+      bool UseThumbTarget = IsThumb && ThumbTarget;
 
       outs() << SymName << ":\n";
       DILineInfo lastLine;
@@ -6320,7 +6323,7 @@ static void DisassembleMachO(StringRef F
         raw_svector_ostream Annotations(AnnotationsBytes);
 
         bool gotInst;
-        if (isThumb)
+        if (UseThumbTarget)
           gotInst = ThumbDisAsm->getInstruction(Inst, Size, Bytes.slice(Index),
                                                 PC, DebugOut, Annotations);
         else
@@ -6332,7 +6335,7 @@ static void DisassembleMachO(StringRef F
           }
           formatted_raw_ostream FormattedOS(outs());
           StringRef AnnotationsStr = Annotations.str();
-          if (isThumb)
+          if (UseThumbTarget)
             ThumbIP->printInst(&Inst, FormattedOS, AnnotationsStr, *ThumbSTI);
           else
             IP->printInst(&Inst, FormattedOS, AnnotationsStr, *STI);
@@ -6354,14 +6357,21 @@ static void DisassembleMachO(StringRef F
             outs() << format("\t.byte 0x%02x #bad opcode\n",
                              *(Bytes.data() + Index) & 0xff);
             Size = 1; // skip exactly one illegible byte and move on.
-          } else if (Arch == Triple::aarch64) {
+          } else if (Arch == Triple::aarch64 ||
+                     (Arch == Triple::arm && !IsThumb)) {
             uint32_t opcode = (*(Bytes.data() + Index) & 0xff) |
                               (*(Bytes.data() + Index + 1) & 0xff) << 8 |
                               (*(Bytes.data() + Index + 2) & 0xff) << 16 |
                               (*(Bytes.data() + Index + 3) & 0xff) << 24;
             outs() << format("\t.long\t0x%08x\n", opcode);
             Size = 4;
-          } else {
+          } else if (Arch == Triple::arm) {
+            assert(IsThumb && "ARM mode should have been dealt with above");
+            uint32_t opcode = (*(Bytes.data() + Index) & 0xff) |
+                              (*(Bytes.data() + Index + 1) & 0xff) << 8;
+            outs() << format("\t.short\t0x%04x\n", opcode);
+            Size = 2;
+          } else{
             errs() << "llvm-objdump: warning: invalid instruction encoding\n";
             if (Size == 0)
               Size = 1; // skip illegible bytes




More information about the llvm-commits mailing list