Index: test/MC/X86/invalid_opcode.s =================================================================== --- test/MC/X86/invalid_opcode.s +++ test/MC/X86/invalid_opcode.s @@ -0,0 +1,4 @@ +# RUN: llvm-mc -triple=x86_64 -filetype=obj %s -o - | llvm-objdump -d - | FileCheck %s + +# CHECK: 0: ff ff +.word 0xffff \ No newline at end of file Index: tools/llvm-objdump/llvm-objdump.cpp =================================================================== --- tools/llvm-objdump/llvm-objdump.cpp +++ tools/llvm-objdump/llvm-objdump.cpp @@ -314,12 +314,15 @@ ArrayRef Bytes, uint64_t Address, raw_ostream &OS, StringRef Annot, MCSubtargetInfo const &STI) { - outs() << format("%8" PRIx64 ":", Address); + OS << format("%8" PRIx64 ":", Address); if (!NoShowRawInsn) { - outs() << "\t"; - dumpBytes(Bytes, outs()); + OS << "\t"; + dumpBytes(Bytes, OS); } - IP.printInst(MI, outs(), "", STI); + if (MI) + IP.printInst(MI, OS, "", STI); + else + OS << " "; } }; PrettyPrinter PrettyPrinterInst; @@ -340,6 +343,11 @@ ArrayRef Bytes, uint64_t Address, raw_ostream &OS, StringRef Annot, MCSubtargetInfo const &STI) override { + if (!MI) { + printLead(Bytes, Address, OS); + OS << " "; + return; + } std::string Buffer; { raw_string_ostream TempStream(Buffer); @@ -1088,72 +1096,69 @@ if (Index >= End) break; - if (DisAsm->getInstruction(Inst, Size, Bytes.slice(Index), - SectionAddr + Index, DebugOut, - CommentStream)) { - PIP.printInst(*IP, &Inst, - Bytes.slice(Index, Size), - SectionAddr + Index, outs(), "", *STI); - outs() << CommentStream.str(); - Comments.clear(); + bool Disassembled = DisAsm->getInstruction(Inst, Size, Bytes.slice(Index), + SectionAddr + Index, DebugOut, + CommentStream); + if (Size == 0) + Size = 1; + PIP.printInst(*IP, Disassembled ? &Inst : nullptr, + Bytes.slice(Index, Size), + SectionAddr + Index, outs(), "", *STI); + outs() << CommentStream.str(); + Comments.clear(); - // Try to resolve the target of a call, tail call, etc. to a specific - // symbol. - if (MIA && (MIA->isCall(Inst) || MIA->isUnconditionalBranch(Inst) || - MIA->isConditionalBranch(Inst))) { - uint64_t Target; - if (MIA->evaluateBranch(Inst, SectionAddr + Index, Size, Target)) { - // In a relocatable object, the target's section must reside in - // the same section as the call instruction or it is accessed - // through a relocation. - // - // In a non-relocatable object, the target may be in any section. - // - // N.B. We don't walk the relocations in the relocatable case yet. - auto *TargetSectionSymbols = &Symbols; - if (!Obj->isRelocatableObject()) { - auto SectionAddress = std::upper_bound( - SectionAddresses.begin(), SectionAddresses.end(), Target, - [](uint64_t LHS, - const std::pair &RHS) { - return LHS < RHS.first; - }); - if (SectionAddress != SectionAddresses.begin()) { - --SectionAddress; - TargetSectionSymbols = &AllSymbols[SectionAddress->second]; - } else { - TargetSectionSymbols = nullptr; - } + // Try to resolve the target of a call, tail call, etc. to a specific + // symbol. + if (MIA && (MIA->isCall(Inst) || MIA->isUnconditionalBranch(Inst) || + MIA->isConditionalBranch(Inst))) { + uint64_t Target; + if (MIA->evaluateBranch(Inst, SectionAddr + Index, Size, Target)) { + // In a relocatable object, the target's section must reside in + // the same section as the call instruction or it is accessed + // through a relocation. + // + // In a non-relocatable object, the target may be in any section. + // + // N.B. We don't walk the relocations in the relocatable case yet. + auto *TargetSectionSymbols = &Symbols; + if (!Obj->isRelocatableObject()) { + auto SectionAddress = std::upper_bound( + SectionAddresses.begin(), SectionAddresses.end(), Target, + [](uint64_t LHS, + const std::pair &RHS) { + return LHS < RHS.first; + }); + if (SectionAddress != SectionAddresses.begin()) { + --SectionAddress; + TargetSectionSymbols = &AllSymbols[SectionAddress->second]; + } else { + TargetSectionSymbols = nullptr; } + } - // Find the first symbol in the section whose offset is less than - // or equal to the target. - if (TargetSectionSymbols) { - auto TargetSym = std::upper_bound( - TargetSectionSymbols->begin(), TargetSectionSymbols->end(), - Target, [](uint64_t LHS, - const std::pair &RHS) { - return LHS < RHS.first; - }); - if (TargetSym != TargetSectionSymbols->begin()) { - --TargetSym; - uint64_t TargetAddress = std::get<0>(*TargetSym); - StringRef TargetName = std::get<1>(*TargetSym); - outs() << " <" << TargetName; - uint64_t Disp = Target - TargetAddress; - if (Disp) - outs() << '+' << utohexstr(Disp); - outs() << '>'; - } + // Find the first symbol in the section whose offset is less than + // or equal to the target. + if (TargetSectionSymbols) { + auto TargetSym = std::upper_bound( + TargetSectionSymbols->begin(), TargetSectionSymbols->end(), + Target, [](uint64_t LHS, + const std::pair &RHS) { + return LHS < RHS.first; + }); + if (TargetSym != TargetSectionSymbols->begin()) { + --TargetSym; + uint64_t TargetAddress = std::get<0>(*TargetSym); + StringRef TargetName = std::get<1>(*TargetSym); + outs() << " <" << TargetName; + uint64_t Disp = Target - TargetAddress; + if (Disp) + outs() << '+' << utohexstr(Disp); + outs() << '>'; } } } - outs() << "\n"; - } else { - errs() << ToolName << ": warning: invalid instruction encoding\n"; - if (Size == 0) - Size = 1; // skip illegible bytes } + outs() << "\n"; // Print relocation for instruction. while (rel_cur != rel_end) {