@@ -162,28 +162,30 @@ BinaryContext::~BinaryContext() {
162
162
163
163
// / Create BinaryContext for a given architecture \p ArchName and
164
164
// / triple \p TripleName.
165
- Expected<std::unique_ptr<BinaryContext>>
166
- BinaryContext::createBinaryContext (const ObjectFile *File, bool IsPIC,
167
- std::unique_ptr<DWARFContext> DwCtx,
168
- JournalingStreams Logger) {
165
+ Expected<std::unique_ptr<BinaryContext>> BinaryContext::createBinaryContext (
166
+ Triple TheTriple, StringRef InputFileName, SubtargetFeatures *Features,
167
+ bool IsPIC, std::unique_ptr<DWARFContext> DwCtx, JournalingStreams Logger) {
169
168
StringRef ArchName = " " ;
170
169
std::string FeaturesStr = " " ;
171
- switch (File-> getArch ()) {
170
+ switch (TheTriple. getArch ()) {
172
171
case llvm::Triple::x86_64:
172
+ if (Features)
173
+ return createFatalBOLTError (
174
+ " x86_64 target does not use SubtargetFeatures" );
173
175
ArchName = " x86-64" ;
174
176
FeaturesStr = " +nopl" ;
175
177
break ;
176
178
case llvm::Triple::aarch64:
179
+ if (Features)
180
+ return createFatalBOLTError (
181
+ " AArch64 target does not use SubtargetFeatures" );
177
182
ArchName = " aarch64" ;
178
183
FeaturesStr = " +all" ;
179
184
break ;
180
185
case llvm::Triple::riscv64: {
181
186
ArchName = " riscv64" ;
182
- Expected<SubtargetFeatures> Features = File->getFeatures ();
183
-
184
- if (auto E = Features.takeError ())
185
- return std::move (E);
186
-
187
+ if (!Features)
188
+ return createFatalBOLTError (" RISCV target needs SubtargetFeatures" );
187
189
// We rely on relaxation for some transformations (e.g., promoting all calls
188
190
// to PseudoCALL and then making JITLink relax them). Since the relax
189
191
// feature is not stored in the object file, we manually enable it.
@@ -196,12 +198,11 @@ BinaryContext::createBinaryContext(const ObjectFile *File, bool IsPIC,
196
198
" BOLT-ERROR: Unrecognized machine in ELF file" );
197
199
}
198
200
199
- auto TheTriple = std::make_unique<Triple>(File->makeTriple ());
200
- const std::string TripleName = TheTriple->str ();
201
+ const std::string TripleName = TheTriple.str ();
201
202
202
203
std::string Error;
203
204
const Target *TheTarget =
204
- TargetRegistry::lookupTarget (std::string (ArchName), * TheTriple, Error);
205
+ TargetRegistry::lookupTarget (std::string (ArchName), TheTriple, Error);
205
206
if (!TheTarget)
206
207
return createStringError (make_error_code (std::errc::not_supported),
207
208
Twine (" BOLT-ERROR: " , Error));
@@ -240,13 +241,13 @@ BinaryContext::createBinaryContext(const ObjectFile *File, bool IsPIC,
240
241
Twine (" BOLT-ERROR: no instruction info for target " , TripleName));
241
242
242
243
std::unique_ptr<MCContext> Ctx (
243
- new MCContext (* TheTriple, AsmInfo.get (), MRI.get (), STI.get ()));
244
+ new MCContext (TheTriple, AsmInfo.get (), MRI.get (), STI.get ()));
244
245
std::unique_ptr<MCObjectFileInfo> MOFI (
245
246
TheTarget->createMCObjectFileInfo (*Ctx, IsPIC));
246
247
Ctx->setObjectFileInfo (MOFI.get ());
247
248
// We do not support X86 Large code model. Change this in the future.
248
249
bool Large = false ;
249
- if (TheTriple-> getArch () == llvm::Triple::aarch64)
250
+ if (TheTriple. getArch () == llvm::Triple::aarch64)
250
251
Large = true ;
251
252
unsigned LSDAEncoding =
252
253
Large ? dwarf::DW_EH_PE_absptr : dwarf::DW_EH_PE_udata4;
@@ -273,7 +274,7 @@ BinaryContext::createBinaryContext(const ObjectFile *File, bool IsPIC,
273
274
274
275
int AsmPrinterVariant = AsmInfo->getAssemblerDialect ();
275
276
std::unique_ptr<MCInstPrinter> InstructionPrinter (
276
- TheTarget->createMCInstPrinter (* TheTriple, AsmPrinterVariant, *AsmInfo,
277
+ TheTarget->createMCInstPrinter (TheTriple, AsmPrinterVariant, *AsmInfo,
277
278
*MII, *MRI));
278
279
if (!InstructionPrinter)
279
280
return createStringError (
@@ -285,8 +286,8 @@ BinaryContext::createBinaryContext(const ObjectFile *File, bool IsPIC,
285
286
TheTarget->createMCCodeEmitter (*MII, *Ctx));
286
287
287
288
auto BC = std::make_unique<BinaryContext>(
288
- std::move (Ctx), std::move (DwCtx), std::move (TheTriple), TheTarget ,
289
- std::string (TripleName), std::move (MCE), std::move (MOFI),
289
+ std::move (Ctx), std::move (DwCtx), std::make_unique<Triple> (TheTriple),
290
+ TheTarget, std::string (TripleName), std::move (MCE), std::move (MOFI),
290
291
std::move (AsmInfo), std::move (MII), std::move (STI),
291
292
std::move (InstructionPrinter), std::move (MIA), nullptr , std::move (MRI),
292
293
std::move (DisAsm), Logger);
@@ -296,7 +297,7 @@ BinaryContext::createBinaryContext(const ObjectFile *File, bool IsPIC,
296
297
BC->MAB = std::unique_ptr<MCAsmBackend>(
297
298
BC->TheTarget ->createMCAsmBackend (*BC->STI , *BC->MRI , MCTargetOptions ()));
298
299
299
- BC->setFilename (File-> getFileName () );
300
+ BC->setFilename (InputFileName );
300
301
301
302
BC->HasFixedLoadAddress = !IsPIC;
302
303
0 commit comments