Fix a bug in llvm-objdump when disassembling using the wrong default CPU

in the second slice of a Mach-O universal file.

The code in llvm-objdump in in DisassembleMachO() was getting the default
CPU then incorrectly setting into the global variable used for the -mcpu option
if that was not set.  This caused a second call to DisassembleMachO() to use
the wrong default CPU when disassembling the next slice in a Mach-O universal
file.  And would result in bad disassembly and an error message about an
recognized processor for the target:

% llvm-objdump -d -m -arch all  fat.macho-armv7s-arm64 
fat.macho-armv7s-arm64 (architecture armv7s):
(__TEXT,__text) section
armv7:
       0:	60 47 	bx	r12
fat.macho-armv7s-arm64 (architecture arm64):
'cortex-a7' is not a recognized processor for this target (ignoring processor)
'cortex-a7' is not a recognized processor for this target (ignoring processor)
(__TEXT,__text) section
___multc3:
       0:		.long	0x1e620810

rdar://34439149

llvm-svn: 313921
This commit is contained in:
Kevin Enderby 2017-09-21 21:45:02 +00:00
parent d51d38f6f9
commit f310e62b77
3 changed files with 13 additions and 3 deletions

View File

@ -0,0 +1,6 @@
RUN: llvm-objdump -d -m -no-show-raw-insn -arch all %p/Inputs/fat.macho-armv7s-arm64 | FileCheck %s
CHECK: (architecture armv7s):
CHECK: bx r12
CHECK: (architecture arm64):
CHECK: fmul d16, d0, d2

View File

@ -6439,8 +6439,11 @@ static void DisassembleMachO(StringRef Filename, MachOObjectFile *MachOOF,
// GetTarget prints out stuff.
return;
}
std::string MachOMCPU;
if (MCPU.empty() && McpuDefault)
MCPU = McpuDefault;
MachOMCPU = McpuDefault;
else
MachOMCPU = MCPU;
std::unique_ptr<const MCInstrInfo> InstrInfo(TheTarget->createMCInstrInfo());
std::unique_ptr<const MCInstrInfo> ThumbInstrInfo;
@ -6462,7 +6465,7 @@ static void DisassembleMachO(StringRef Filename, MachOObjectFile *MachOOF,
std::unique_ptr<const MCAsmInfo> AsmInfo(
TheTarget->createMCAsmInfo(*MRI, TripleName));
std::unique_ptr<const MCSubtargetInfo> STI(
TheTarget->createMCSubtargetInfo(TripleName, MCPU, FeaturesStr));
TheTarget->createMCSubtargetInfo(TripleName, MachOMCPU, FeaturesStr));
MCContext Ctx(AsmInfo.get(), MRI.get(), nullptr);
std::unique_ptr<MCDisassembler> DisAsm(
TheTarget->createMCDisassembler(*STI, Ctx));
@ -6512,7 +6515,8 @@ static void DisassembleMachO(StringRef Filename, MachOObjectFile *MachOOF,
ThumbAsmInfo.reset(
ThumbTarget->createMCAsmInfo(*ThumbMRI, ThumbTripleName));
ThumbSTI.reset(
ThumbTarget->createMCSubtargetInfo(ThumbTripleName, MCPU, FeaturesStr));
ThumbTarget->createMCSubtargetInfo(ThumbTripleName, MachOMCPU,
FeaturesStr));
ThumbCtx.reset(new MCContext(ThumbAsmInfo.get(), ThumbMRI.get(), nullptr));
ThumbDisAsm.reset(ThumbTarget->createMCDisassembler(*ThumbSTI, *ThumbCtx));
MCContext *PtrThumbCtx = ThumbCtx.get();