diff options
Diffstat (limited to 'llvm')
-rw-r--r-- | llvm/test/tools/llvm-objdump/ARM/macho-arm-and-thumb.test | 6 | ||||
-rw-r--r-- | llvm/test/tools/llvm-objdump/ARM/macho-v7m.test | 6 | ||||
-rw-r--r-- | llvm/tools/llvm-objdump/MachODump.cpp | 24 |
3 files changed, 27 insertions, 9 deletions
diff --git a/llvm/test/tools/llvm-objdump/ARM/macho-arm-and-thumb.test b/llvm/test/tools/llvm-objdump/ARM/macho-arm-and-thumb.test index f741f6cb27a..fab64f549ef 100644 --- a/llvm/test/tools/llvm-objdump/ARM/macho-arm-and-thumb.test +++ b/llvm/test/tools/llvm-objdump/ARM/macho-arm-and-thumb.test @@ -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 diff --git a/llvm/test/tools/llvm-objdump/ARM/macho-v7m.test b/llvm/test/tools/llvm-objdump/ARM/macho-v7m.test index 938aa4f7d60..3ba11220561 100644 --- a/llvm/test/tools/llvm-objdump/ARM/macho-v7m.test +++ b/llvm/test/tools/llvm-objdump/ARM/macho-v7m.test @@ -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 diff --git a/llvm/tools/llvm-objdump/MachODump.cpp b/llvm/tools/llvm-objdump/MachODump.cpp index 7f256cb58fe..71260ee8452 100644 --- a/llvm/tools/llvm-objdump/MachODump.cpp +++ b/llvm/tools/llvm-objdump/MachODump.cpp @@ -6034,7 +6034,7 @@ static void DisassembleMachO(StringRef Filename, MachOObjectFile *MachOOF, 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 Filename, MachOObjectFile *MachOOF, 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 Filename, MachOObjectFile *MachOOF, 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 Filename, MachOObjectFile *MachOOF, } 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 Filename, MachOObjectFile *MachOOF, 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 |