mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-23 11:13:28 +01:00
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) llvm-svn: 267250
This commit is contained in:
parent
5cc375dd3c
commit
2b39bb5c9b
@ -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
|
||||
|
@ -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
|
||||
@ CHECK: msr msp, r0
|
||||
@ CHECK: .short 0xf000
|
||||
@ CHECK: b _t
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user