diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp --- a/llvm/tools/llvm-objdump/llvm-objdump.cpp +++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp @@ -1393,18 +1393,14 @@ } static void -disassembleObject(const Target *TheTarget, ObjectFile &Obj, - const ObjectFile &DbgObj, MCContext &Ctx, - MCDisassembler *PrimaryDisAsm, +disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj, + DisassemblerTarget &PrimaryTarget, std::optional &SecondaryTarget, - const MCInstrAnalysis *MIA, MCInstPrinter *IP, - const MCSubtargetInfo *PrimarySTI, PrettyPrinter &PIP, SourcePrinter &SP, bool InlineRelocs) { - const MCSubtargetInfo *STI = PrimarySTI; - MCDisassembler *DisAsm = PrimaryDisAsm; + DisassemblerTarget *DT = &PrimaryTarget; bool PrimaryIsThumb = false; if (isArmElf(Obj)) - PrimaryIsThumb = STI->checkFeatures("+thumb-mode"); + PrimaryIsThumb = PrimaryTarget.SubtargetInfo->checkFeatures("+thumb-mode"); std::map> RelocMap; if (InlineRelocs) @@ -1515,7 +1511,7 @@ llvm::stable_sort(AbsoluteSymbols); std::unique_ptr DICtx; - LiveVariablePrinter LVP(*Ctx.getRegisterInfo(), *STI); + LiveVariablePrinter LVP(*DT->Context->getRegisterInfo(), *DT->SubtargetInfo); if (DbgVariables != DVDisabled) { DICtx = DWARFContext::create(DbgObj); @@ -1573,9 +1569,11 @@ if (Name.startswith("$x")) MappingSymbols.emplace_back(Address - SectionAddr, 'x'); if (Name.startswith("$a")) - MappingSymbols.emplace_back(Address - SectionAddr, 'a'); + MappingSymbols.emplace_back(Address - SectionAddr, + PrimaryIsThumb ? 's' : 'p'); if (Name.startswith("$t")) - MappingSymbols.emplace_back(Address - SectionAddr, 't'); + MappingSymbols.emplace_back(Address - SectionAddr, + PrimaryIsThumb ? 'p' : 's'); } } @@ -1587,8 +1585,8 @@ std::vector> SynthesizedLabelNames; if (Obj.isELF() && Obj.getArch() == Triple::amdgcn) { // AMDGPU disassembler uses symbolizer for printing labels - addSymbolizer(Ctx, TheTarget, TripleName, DisAsm, SectionAddr, Bytes, - Symbols, SynthesizedLabelNames); + addSymbolizer(*DT->Context, DT->Target, TripleName, DT->DisAsm.get(), + SectionAddr, Bytes, Symbols, SynthesizedLabelNames); } StringRef SegmentName = getSegmentName(MachO, Section); @@ -1781,9 +1779,9 @@ for (size_t SHI = 0; SHI < SymbolsHere.size(); ++SHI) { SymbolInfoTy Symbol = SymbolsHere[SHI]; - auto Status = - DisAsm->onSymbolStart(Symbol, Size, Bytes.slice(Start, End - Start), - SectionAddr + Start, CommentStream); + auto Status = DT->DisAsm->onSymbolStart( + Symbol, Size, Bytes.slice(Start, End - Start), SectionAddr + Start, + CommentStream); if (!Status) { // If onSymbolStart returns std::nullopt, that means it didn't trigger @@ -1835,7 +1833,9 @@ std::unordered_map AllLabels; std::unordered_map> BBAddrMapLabels; if (SymbolizeOperands) { - collectLocalBranchTargets(Bytes, MIA, DisAsm, IP, PrimarySTI, + collectLocalBranchTargets(Bytes, DT->InstrAnalysis, DT->DisAsm.get(), + DT->InstPrinter, + PrimaryTarget.SubtargetInfo.get(), SectionAddr, Index, End, AllLabels); collectBBAddrMapLabels(AddrToBBAddrMap, SectionAddr, Index, End, BBAddrMapLabels); @@ -1850,23 +1850,17 @@ char Kind = getMappingSymbolKind(MappingSymbols, Index); DumpARMELFData = Kind == 'd'; if (SecondaryTarget) { - if (Kind == 'a') { - STI = PrimaryIsThumb ? SecondaryTarget->SubtargetInfo.get() - : PrimarySTI; - DisAsm = PrimaryIsThumb ? SecondaryTarget->DisAsm.get() - : PrimaryDisAsm; - } else if (Kind == 't') { - STI = PrimaryIsThumb ? PrimarySTI - : SecondaryTarget->SubtargetInfo.get(); - DisAsm = PrimaryIsThumb ? PrimaryDisAsm - : SecondaryTarget->DisAsm.get(); + if (Kind == 'p') { + DT = &PrimaryTarget; + } else if (Kind == 's') { + DT = &*SecondaryTarget; } } } if (DumpARMELFData) { Size = dumpARMELFData(SectionAddr, Index, End, Obj, Bytes, - MappingSymbols, *STI, FOS); + MappingSymbols, *DT->SubtargetInfo, FOS); } else { // When -z or --disassemble-zeroes are given we always dissasemble // them. Otherwise we might want to skip zero bytes we see. @@ -1902,39 +1896,41 @@ MCInst Inst; ArrayRef ThisBytes = Bytes.slice(Index); uint64_t ThisAddr = SectionAddr + Index; - bool Disassembled = DisAsm->getInstruction(Inst, Size, ThisBytes, - ThisAddr, CommentStream); + bool Disassembled = DT->DisAsm->getInstruction( + Inst, Size, ThisBytes, ThisAddr, CommentStream); if (Size == 0) Size = std::min( ThisBytes.size(), - DisAsm->suggestBytesToSkip(ThisBytes, ThisAddr)); + DT->DisAsm->suggestBytesToSkip(ThisBytes, ThisAddr)); LVP.update({Index, Section.getIndex()}, {Index + Size, Section.getIndex()}, Index + Size != End); - IP->setCommentStream(CommentStream); + DT->InstPrinter->setCommentStream(CommentStream); - PIP.printInst( - *IP, Disassembled ? &Inst : nullptr, Bytes.slice(Index, Size), + DT->PrettyPrinter->printInst( + *DT->InstPrinter, Disassembled ? &Inst : nullptr, + Bytes.slice(Index, Size), {SectionAddr + Index + VMAAdjustment, Section.getIndex()}, FOS, - "", *STI, &SP, Obj.getFileName(), &Rels, LVP); + "", *DT->SubtargetInfo, &SP, Obj.getFileName(), &Rels, LVP); - IP->setCommentStream(llvm::nulls()); + DT->InstPrinter->setCommentStream(llvm::nulls()); // If disassembly has failed, avoid analysing invalid/incomplete // instruction information. Otherwise, try to resolve the target // address (jump target or memory operand address) and print it on the // right of the instruction. - if (Disassembled && MIA) { + if (Disassembled && DT->InstrAnalysis) { // Branch targets are printed just after the instructions. llvm::raw_ostream *TargetOS = &FOS; uint64_t Target; - bool PrintTarget = - MIA->evaluateBranch(Inst, SectionAddr + Index, Size, Target); + bool PrintTarget = DT->InstrAnalysis->evaluateBranch( + Inst, SectionAddr + Index, Size, Target); if (!PrintTarget) if (std::optional MaybeTarget = - MIA->evaluateMemoryOperandAddress( - Inst, STI, SectionAddr + Index, Size)) { + DT->InstrAnalysis->evaluateMemoryOperandAddress( + Inst, DT->SubtargetInfo.get(), SectionAddr + Index, + Size)) { Target = *MaybeTarget; PrintTarget = true; // Do not print real address when symbolizing. @@ -2037,9 +2033,9 @@ } } - assert(Ctx.getAsmInfo()); - emitPostInstructionInfo(FOS, *Ctx.getAsmInfo(), *STI, - CommentStream.str(), LVP); + assert(DT->Context->getAsmInfo()); + emitPostInstructionInfo(FOS, *DT->Context->getAsmInfo(), + *DT->SubtargetInfo, CommentStream.str(), LVP); Comments.clear(); // Hexagon does this in pretty printer @@ -2194,11 +2190,8 @@ reportError(Obj->getFileName(), "Unrecognized disassembler option: " + Opt); - disassembleObject(TheTarget, *Obj, *DbgObj, *PrimaryTarget.Context, - PrimaryTarget.DisAsm.get(), SecondaryTarget, - PrimaryTarget.InstrAnalysis, PrimaryTarget.InstPrinter, - PrimaryTarget.SubtargetInfo.get(), - *PrimaryTarget.PrettyPrinter, SP, InlineRelocs); + disassembleObject(*Obj, *DbgObj, PrimaryTarget, SecondaryTarget, SP, + InlineRelocs); } void objdump::printRelocations(const ObjectFile *Obj) {