@@ -836,92 +836,6 @@ PrettyPrinter &selectPrettyPrinter(Triple const &Triple) {
836
836
return AArch64PrettyPrinterInst;
837
837
}
838
838
}
839
-
840
- class DisassemblerTarget {
841
- public:
842
- const Target *TheTarget;
843
- std::unique_ptr<const MCSubtargetInfo> SubtargetInfo;
844
- std::shared_ptr<MCContext> Context;
845
- std::unique_ptr<MCDisassembler> DisAsm;
846
- std::shared_ptr<const MCInstrAnalysis> InstrAnalysis;
847
- std::shared_ptr<MCInstPrinter> InstPrinter;
848
- PrettyPrinter *PrettyPrinter;
849
-
850
- DisassemblerTarget (const Target *TheTarget, ObjectFile &Obj,
851
- StringRef TripleName, StringRef MCPU,
852
- SubtargetFeatures &Features);
853
- DisassemblerTarget (DisassemblerTarget &Other, SubtargetFeatures &Features);
854
-
855
- private:
856
- MCTargetOptions Options;
857
- std::shared_ptr<const MCRegisterInfo> RegisterInfo;
858
- std::shared_ptr<const MCAsmInfo> AsmInfo;
859
- std::shared_ptr<const MCInstrInfo> InstrInfo;
860
- std::shared_ptr<MCObjectFileInfo> ObjectFileInfo;
861
- };
862
-
863
- DisassemblerTarget::DisassemblerTarget (const Target *TheTarget, ObjectFile &Obj,
864
- StringRef TripleName, StringRef MCPU,
865
- SubtargetFeatures &Features)
866
- : TheTarget(TheTarget),
867
- PrettyPrinter (&selectPrettyPrinter (Triple(TripleName))),
868
- RegisterInfo(TheTarget->createMCRegInfo (TripleName)) {
869
- if (!RegisterInfo)
870
- reportError (Obj.getFileName (), " no register info for target " + TripleName);
871
-
872
- // Set up disassembler.
873
- AsmInfo.reset (TheTarget->createMCAsmInfo (*RegisterInfo, TripleName, Options));
874
- if (!AsmInfo)
875
- reportError (Obj.getFileName (), " no assembly info for target " + TripleName);
876
-
877
- SubtargetInfo.reset (
878
- TheTarget->createMCSubtargetInfo (TripleName, MCPU, Features.getString ()));
879
- if (!SubtargetInfo)
880
- reportError (Obj.getFileName (),
881
- " no subtarget info for target " + TripleName);
882
- InstrInfo.reset (TheTarget->createMCInstrInfo ());
883
- if (!InstrInfo)
884
- reportError (Obj.getFileName (),
885
- " no instruction info for target " + TripleName);
886
- Context =
887
- std::make_shared<MCContext>(Triple (TripleName), AsmInfo.get (),
888
- RegisterInfo.get (), SubtargetInfo.get ());
889
-
890
- // FIXME: for now initialize MCObjectFileInfo with default values
891
- ObjectFileInfo.reset (
892
- TheTarget->createMCObjectFileInfo (*Context, /* PIC=*/ false ));
893
- Context->setObjectFileInfo (ObjectFileInfo.get ());
894
-
895
- DisAsm.reset (TheTarget->createMCDisassembler (*SubtargetInfo, *Context));
896
- if (!DisAsm)
897
- reportError (Obj.getFileName (), " no disassembler for target " + TripleName);
898
-
899
- InstrAnalysis.reset (TheTarget->createMCInstrAnalysis (InstrInfo.get ()));
900
-
901
- int AsmPrinterVariant = AsmInfo->getAssemblerDialect ();
902
- InstPrinter.reset (TheTarget->createMCInstPrinter (Triple (TripleName),
903
- AsmPrinterVariant, *AsmInfo,
904
- *InstrInfo, *RegisterInfo));
905
- if (!InstPrinter)
906
- reportError (Obj.getFileName (),
907
- " no instruction printer for target " + TripleName);
908
- InstPrinter->setPrintImmHex (PrintImmHex);
909
- InstPrinter->setPrintBranchImmAsAddress (true );
910
- InstPrinter->setSymbolizeOperands (SymbolizeOperands);
911
- InstPrinter->setMCInstrAnalysis (InstrAnalysis.get ());
912
- }
913
-
914
- DisassemblerTarget::DisassemblerTarget (DisassemblerTarget &Other,
915
- SubtargetFeatures &Features)
916
- : TheTarget(Other.TheTarget),
917
- SubtargetInfo(TheTarget->createMCSubtargetInfo (TripleName, MCPU,
918
- Features.getString())),
919
- Context(Other.Context),
920
- DisAsm(TheTarget->createMCDisassembler (*SubtargetInfo, *Context)),
921
- InstrAnalysis(Other.InstrAnalysis), InstPrinter(Other.InstPrinter),
922
- PrettyPrinter(Other.PrettyPrinter), RegisterInfo(Other.RegisterInfo),
923
- AsmInfo(Other.AsmInfo), InstrInfo(Other.InstrInfo),
924
- ObjectFileInfo(Other.ObjectFileInfo) {}
925
839
} // namespace
926
840
927
841
static uint8_t getElfSymbolType (const ObjectFile &Obj, const SymbolRef &Sym) {
@@ -1412,14 +1326,15 @@ fetchBinaryByBuildID(const ObjectFile &Obj) {
1412
1326
return std::move (*DebugBinary);
1413
1327
}
1414
1328
1415
- static void
1416
- disassembleObject (const Target *TheTarget, ObjectFile &Obj,
1417
- const ObjectFile &DbgObj, MCContext &Ctx,
1418
- MCDisassembler *PrimaryDisAsm,
1419
- std::optional<DisassemblerTarget> &SecondaryTarget,
1420
- const MCInstrAnalysis *MIA, MCInstPrinter *IP,
1421
- const MCSubtargetInfo *PrimarySTI, PrettyPrinter &PIP,
1422
- SourcePrinter &SP, bool InlineRelocs) {
1329
+ static void disassembleObject (const Target *TheTarget, ObjectFile &Obj,
1330
+ const ObjectFile &DbgObj, MCContext &Ctx,
1331
+ MCDisassembler *PrimaryDisAsm,
1332
+ MCDisassembler *SecondaryDisAsm,
1333
+ const MCInstrAnalysis *MIA, MCInstPrinter *IP,
1334
+ const MCSubtargetInfo *PrimarySTI,
1335
+ const MCSubtargetInfo *SecondarySTI,
1336
+ PrettyPrinter &PIP, SourcePrinter &SP,
1337
+ bool InlineRelocs) {
1423
1338
const MCSubtargetInfo *STI = PrimarySTI;
1424
1339
MCDisassembler *DisAsm = PrimaryDisAsm;
1425
1340
bool PrimaryIsThumb = false ;
@@ -1875,17 +1790,13 @@ disassembleObject(const Target *TheTarget, ObjectFile &Obj,
1875
1790
if (!MappingSymbols.empty ()) {
1876
1791
char Kind = getMappingSymbolKind (MappingSymbols, Index);
1877
1792
DumpARMELFData = Kind == ' d' ;
1878
- if (SecondaryTarget ) {
1793
+ if (SecondarySTI ) {
1879
1794
if (Kind == ' a' ) {
1880
- STI = PrimaryIsThumb ? SecondaryTarget->SubtargetInfo .get ()
1881
- : PrimarySTI;
1882
- DisAsm = PrimaryIsThumb ? SecondaryTarget->DisAsm .get ()
1883
- : PrimaryDisAsm;
1795
+ STI = PrimaryIsThumb ? SecondarySTI : PrimarySTI;
1796
+ DisAsm = PrimaryIsThumb ? SecondaryDisAsm : PrimaryDisAsm;
1884
1797
} else if (Kind == ' t' ) {
1885
- STI = PrimaryIsThumb ? PrimarySTI
1886
- : SecondaryTarget->SubtargetInfo .get ();
1887
- DisAsm = PrimaryIsThumb ? PrimaryDisAsm
1888
- : SecondaryTarget->DisAsm .get ();
1798
+ STI = PrimaryIsThumb ? PrimarySTI : SecondarySTI;
1799
+ DisAsm = PrimaryIsThumb ? PrimaryDisAsm : SecondaryDisAsm;
1889
1800
}
1890
1801
}
1891
1802
}
@@ -2153,6 +2064,20 @@ static void disassembleObject(ObjectFile *Obj, bool InlineRelocs) {
2153
2064
Features.AddFeature (" +all" );
2154
2065
}
2155
2066
2067
+ std::unique_ptr<const MCRegisterInfo> MRI (
2068
+ TheTarget->createMCRegInfo (TripleName));
2069
+ if (!MRI)
2070
+ reportError (Obj->getFileName (),
2071
+ " no register info for target " + TripleName);
2072
+
2073
+ // Set up disassembler.
2074
+ MCTargetOptions MCOptions;
2075
+ std::unique_ptr<const MCAsmInfo> AsmInfo (
2076
+ TheTarget->createMCAsmInfo (*MRI, TripleName, MCOptions));
2077
+ if (!AsmInfo)
2078
+ reportError (Obj->getFileName (),
2079
+ " no assembly info for target " + TripleName);
2080
+
2156
2081
if (MCPU.empty ())
2157
2082
MCPU = Obj->tryGetCPUName ().value_or (" " ).str ();
2158
2083
@@ -2179,24 +2104,58 @@ static void disassembleObject(ObjectFile *Obj, bool InlineRelocs) {
2179
2104
}
2180
2105
}
2181
2106
2182
- DisassemblerTarget PrimaryTarget (TheTarget, *Obj, TripleName, MCPU, Features);
2107
+ std::unique_ptr<const MCSubtargetInfo> STI (
2108
+ TheTarget->createMCSubtargetInfo (TripleName, MCPU, Features.getString ()));
2109
+ if (!STI)
2110
+ reportError (Obj->getFileName (),
2111
+ " no subtarget info for target " + TripleName);
2112
+ std::unique_ptr<const MCInstrInfo> MII (TheTarget->createMCInstrInfo ());
2113
+ if (!MII)
2114
+ reportError (Obj->getFileName (),
2115
+ " no instruction info for target " + TripleName);
2116
+ MCContext Ctx (Triple (TripleName), AsmInfo.get (), MRI.get (), STI.get ());
2117
+ // FIXME: for now initialize MCObjectFileInfo with default values
2118
+ std::unique_ptr<MCObjectFileInfo> MOFI (
2119
+ TheTarget->createMCObjectFileInfo (Ctx, /* PIC=*/ false ));
2120
+ Ctx.setObjectFileInfo (MOFI.get ());
2121
+
2122
+ std::unique_ptr<MCDisassembler> DisAsm (
2123
+ TheTarget->createMCDisassembler (*STI, Ctx));
2124
+ if (!DisAsm)
2125
+ reportError (Obj->getFileName (), " no disassembler for target " + TripleName);
2183
2126
2184
2127
// If we have an ARM object file, we need a second disassembler, because
2185
2128
// ARM CPUs have two different instruction sets: ARM mode, and Thumb mode.
2186
2129
// We use mapping symbols to switch between the two assemblers, where
2187
2130
// appropriate.
2188
- std::optional<DisassemblerTarget> SecondaryTarget ;
2189
-
2190
- if (isArmElf (*Obj)) {
2191
- if (!PrimaryTarget. SubtargetInfo ->checkFeatures (" +mclass " )) {
2192
- if (PrimaryTarget. SubtargetInfo -> checkFeatures ( " + thumb-mode" ))
2193
- Features. AddFeature ( " -thumb-mode " );
2194
- else
2195
- Features. AddFeature ( " +thumb-mode " );
2196
- SecondaryTarget. emplace (PrimaryTarget, Features);
2197
- }
2131
+ std::unique_ptr<MCDisassembler> SecondaryDisAsm ;
2132
+ std::unique_ptr< const MCSubtargetInfo> SecondarySTI;
2133
+ if (isArmElf (*Obj) && !STI-> checkFeatures ( " +mclass " ) ) {
2134
+ if (STI ->checkFeatures (" +thumb-mode " ))
2135
+ Features. AddFeature ( " - thumb-mode" );
2136
+ else
2137
+ Features. AddFeature ( " +thumb-mode " );
2138
+ SecondarySTI. reset (TheTarget-> createMCSubtargetInfo (TripleName, MCPU,
2139
+ Features. getString ()) );
2140
+ SecondaryDisAsm. reset (TheTarget-> createMCDisassembler (*SecondarySTI, Ctx));
2198
2141
}
2199
2142
2143
+ std::unique_ptr<const MCInstrAnalysis> MIA (
2144
+ TheTarget->createMCInstrAnalysis (MII.get ()));
2145
+
2146
+ int AsmPrinterVariant = AsmInfo->getAssemblerDialect ();
2147
+ std::unique_ptr<MCInstPrinter> IP (TheTarget->createMCInstPrinter (
2148
+ Triple (TripleName), AsmPrinterVariant, *AsmInfo, *MII, *MRI));
2149
+ if (!IP)
2150
+ reportError (Obj->getFileName (),
2151
+ " no instruction printer for target " + TripleName);
2152
+ IP->setPrintImmHex (PrintImmHex);
2153
+ IP->setPrintBranchImmAsAddress (true );
2154
+ IP->setSymbolizeOperands (SymbolizeOperands);
2155
+ IP->setMCInstrAnalysis (MIA.get ());
2156
+
2157
+ PrettyPrinter &PIP = selectPrettyPrinter (Triple (TripleName));
2158
+
2200
2159
const ObjectFile *DbgObj = Obj;
2201
2160
if (!FetchedBinary.getBinary () && !Obj->hasDebugInfo ()) {
2202
2161
if (std::optional<OwningBinary<Binary>> DebugBinaryOpt =
@@ -2225,16 +2184,13 @@ static void disassembleObject(ObjectFile *Obj, bool InlineRelocs) {
2225
2184
SourcePrinter SP (DbgObj, TheTarget->getName ());
2226
2185
2227
2186
for (StringRef Opt : DisassemblerOptions)
2228
- if (!PrimaryTarget. InstPrinter ->applyTargetSpecificCLOption (Opt))
2187
+ if (!IP ->applyTargetSpecificCLOption (Opt))
2229
2188
reportError (Obj->getFileName (),
2230
2189
" Unrecognized disassembler option: " + Opt);
2231
2190
2232
- disassembleObject (TheTarget, *Obj, *DbgObj, *PrimaryTarget.Context .get (),
2233
- PrimaryTarget.DisAsm .get (), SecondaryTarget,
2234
- PrimaryTarget.InstrAnalysis .get (),
2235
- PrimaryTarget.InstPrinter .get (),
2236
- PrimaryTarget.SubtargetInfo .get (),
2237
- *PrimaryTarget.PrettyPrinter , SP, InlineRelocs);
2191
+ disassembleObject (TheTarget, *Obj, *DbgObj, Ctx, DisAsm.get (),
2192
+ SecondaryDisAsm.get (), MIA.get (), IP.get (), STI.get (),
2193
+ SecondarySTI.get (), PIP, SP, InlineRelocs);
2238
2194
}
2239
2195
2240
2196
void Dumper::printRelocations () {
0 commit comments