@@ -162,28 +162,30 @@ BinaryContext::~BinaryContext() {
162162
163163// / Create BinaryContext for a given architecture \p ArchName and
164164// / 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) {
169168 StringRef ArchName = " " ;
170169 std::string FeaturesStr = " " ;
171- switch (File-> getArch ()) {
170+ switch (TheTriple. getArch ()) {
172171 case llvm::Triple::x86_64:
172+ if (Features)
173+ return createFatalBOLTError (
174+ " x86_64 target does not use SubtargetFeatures" );
173175 ArchName = " x86-64" ;
174176 FeaturesStr = " +nopl" ;
175177 break ;
176178 case llvm::Triple::aarch64:
179+ if (Features)
180+ return createFatalBOLTError (
181+ " AArch64 target does not use SubtargetFeatures" );
177182 ArchName = " aarch64" ;
178183 FeaturesStr = " +all" ;
179184 break ;
180185 case llvm::Triple::riscv64: {
181186 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" );
187189 // We rely on relaxation for some transformations (e.g., promoting all calls
188190 // to PseudoCALL and then making JITLink relax them). Since the relax
189191 // feature is not stored in the object file, we manually enable it.
@@ -196,12 +198,11 @@ BinaryContext::createBinaryContext(const ObjectFile *File, bool IsPIC,
196198 " BOLT-ERROR: Unrecognized machine in ELF file" );
197199 }
198200
199- auto TheTriple = std::make_unique<Triple>(File->makeTriple ());
200- const std::string TripleName = TheTriple->str ();
201+ const std::string TripleName = TheTriple.str ();
201202
202203 std::string Error;
203204 const Target *TheTarget =
204- TargetRegistry::lookupTarget (std::string (ArchName), * TheTriple, Error);
205+ TargetRegistry::lookupTarget (std::string (ArchName), TheTriple, Error);
205206 if (!TheTarget)
206207 return createStringError (make_error_code (std::errc::not_supported),
207208 Twine (" BOLT-ERROR: " , Error));
@@ -240,13 +241,13 @@ BinaryContext::createBinaryContext(const ObjectFile *File, bool IsPIC,
240241 Twine (" BOLT-ERROR: no instruction info for target " , TripleName));
241242
242243 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 ()));
244245 std::unique_ptr<MCObjectFileInfo> MOFI (
245246 TheTarget->createMCObjectFileInfo (*Ctx, IsPIC));
246247 Ctx->setObjectFileInfo (MOFI.get ());
247248 // We do not support X86 Large code model. Change this in the future.
248249 bool Large = false ;
249- if (TheTriple-> getArch () == llvm::Triple::aarch64)
250+ if (TheTriple. getArch () == llvm::Triple::aarch64)
250251 Large = true ;
251252 unsigned LSDAEncoding =
252253 Large ? dwarf::DW_EH_PE_absptr : dwarf::DW_EH_PE_udata4;
@@ -273,7 +274,7 @@ BinaryContext::createBinaryContext(const ObjectFile *File, bool IsPIC,
273274
274275 int AsmPrinterVariant = AsmInfo->getAssemblerDialect ();
275276 std::unique_ptr<MCInstPrinter> InstructionPrinter (
276- TheTarget->createMCInstPrinter (* TheTriple, AsmPrinterVariant, *AsmInfo,
277+ TheTarget->createMCInstPrinter (TheTriple, AsmPrinterVariant, *AsmInfo,
277278 *MII, *MRI));
278279 if (!InstructionPrinter)
279280 return createStringError (
@@ -285,8 +286,8 @@ BinaryContext::createBinaryContext(const ObjectFile *File, bool IsPIC,
285286 TheTarget->createMCCodeEmitter (*MII, *Ctx));
286287
287288 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),
290291 std::move (AsmInfo), std::move (MII), std::move (STI),
291292 std::move (InstructionPrinter), std::move (MIA), nullptr , std::move (MRI),
292293 std::move (DisAsm), Logger);
@@ -296,7 +297,7 @@ BinaryContext::createBinaryContext(const ObjectFile *File, bool IsPIC,
296297 BC->MAB = std::unique_ptr<MCAsmBackend>(
297298 BC->TheTarget ->createMCAsmBackend (*BC->STI , *BC->MRI , MCTargetOptions ()));
298299
299- BC->setFilename (File-> getFileName () );
300+ BC->setFilename (InputFileName );
300301
301302 BC->HasFixedLoadAddress = !IsPIC;
302303
0 commit comments