Index: llvm/tools/llvm-objdump/llvm-objdump.cpp =================================================================== --- llvm/tools/llvm-objdump/llvm-objdump.cpp +++ llvm/tools/llvm-objdump/llvm-objdump.cpp @@ -1413,18 +1413,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) @@ -1535,7 +1531,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); @@ -1593,9 +1589,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'); } } @@ -1607,8 +1605,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->TheTarget, TripleName, DT->DisAsm.get(), + SectionAddr, Bytes, Symbols, SynthesizedLabelNames); } StringRef SegmentName = getSegmentName(MachO, Section); @@ -1801,9 +1799,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 @@ -1828,7 +1826,7 @@ // distance to the next symbol, and sometimes it will be just a // prologue and we should start disassembling instructions from where // it left off. - outs() << Ctx.getAsmInfo()->getCommentString() + outs() << DT->Context->getAsmInfo()->getCommentString() << " error in decoding " << SymNamesHere[SHI] << " : decoding failed region as bytes.\n"; for (uint64_t I = 0; I < Size; ++I) { @@ -1861,7 +1859,9 @@ std::unordered_map AllLabels; std::unordered_map> BBAddrMapLabels; if (SymbolizeOperands) { - collectLocalBranchTargets(Bytes, MIA, DisAsm, IP, PrimarySTI, + collectLocalBranchTargets(Bytes, DT->InstrAnalysis.get(), + DT->DisAsm.get(), DT->InstPrinter.get(), + PrimaryTarget.SubtargetInfo.get(), SectionAddr, Index, End, AllLabels); collectBBAddrMapLabels(AddrToBBAddrMap, SectionAddr, Index, End, BBAddrMapLabels); @@ -1876,23 +1876,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. @@ -1916,8 +1910,8 @@ doesXCOFFTracebackTableBegin(Bytes.slice(Index, 4))) { dumpTracebackTable(Bytes.slice(Index), SectionAddr + Index + VMAAdjustment, FOS, - SectionAddr + End + VMAAdjustment, *STI, - cast(&Obj)); + SectionAddr + End + VMAAdjustment, + *DT->SubtargetInfo, cast(&Obj)); Index = End; continue; } @@ -1938,39 +1932,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->Printer->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. @@ -2072,9 +2068,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 @@ -2229,12 +2225,8 @@ reportError(Obj->getFileName(), "Unrecognized disassembler option: " + Opt); - disassembleObject(TheTarget, *Obj, *DbgObj, *PrimaryTarget.Context.get(), - PrimaryTarget.DisAsm.get(), SecondaryTarget, - PrimaryTarget.InstrAnalysis.get(), - PrimaryTarget.InstPrinter.get(), - PrimaryTarget.SubtargetInfo.get(), - *PrimaryTarget.Printer, SP, InlineRelocs); + disassembleObject(*Obj, *DbgObj, PrimaryTarget, SecondaryTarget, SP, + InlineRelocs); } void Dumper::printRelocations() {