diff --git a/clang/lib/Parse/ParseStmtAsm.cpp b/clang/lib/Parse/ParseStmtAsm.cpp --- a/clang/lib/Parse/ParseStmtAsm.cpp +++ b/clang/lib/Parse/ParseStmtAsm.cpp @@ -577,20 +577,23 @@ TheTarget->createMCAsmInfo(*MRI, TT, MCOptions)); // Get the instruction descriptor. std::unique_ptr MII(TheTarget->createMCInstrInfo()); - std::unique_ptr MOFI(new llvm::MCObjectFileInfo()); std::unique_ptr STI( TheTarget->createMCSubtargetInfo(TT, TO.CPU, FeaturesStr)); // Target MCTargetDesc may not be linked in clang-based tools. + + llvm::SourceMgr TempSrcMgr; + llvm::MCContext Ctx(TheTriple, MAI.get(), MRI.get(), /*MOFI=*/nullptr, + STI.get(), &TempSrcMgr); + std::unique_ptr MOFI( + TheTarget->createMCObjectFileInfo(Ctx, /*PIC=*/false)); + Ctx.setObjectFileInfo(MOFI.get()); + if (!MAI || !MII || !MOFI || !STI) { Diag(AsmLoc, diag::err_msasm_unable_to_create_target) << "target MC unavailable"; return EmptyStmt(); } - llvm::SourceMgr TempSrcMgr; - llvm::MCContext Ctx(TheTriple, MAI.get(), MRI.get(), MOFI.get(), STI.get(), - &TempSrcMgr); - MOFI->initMCObjectFileInfo(Ctx, /*PIC=*/false); std::unique_ptr Buffer = llvm::MemoryBuffer::getMemBuffer(AsmString, ""); diff --git a/clang/tools/driver/cc1as_main.cpp b/clang/tools/driver/cc1as_main.cpp --- a/clang/tools/driver/cc1as_main.cpp +++ b/clang/tools/driver/cc1as_main.cpp @@ -383,10 +383,6 @@ if (!Opts.SplitDwarfOutput.empty()) DwoOS = getOutputStream(Opts.SplitDwarfOutput, Diags, IsBinary); - // FIXME: This is not pretty. MCContext has a ptr to MCObjectFileInfo and - // MCObjectFileInfo needs a MCContext reference in order to initialize itself. - std::unique_ptr MOFI(new MCObjectFileInfo()); - // Build up the feature string from the target feature list. std::string FS = llvm::join(Opts.Features, ","); @@ -394,7 +390,7 @@ TheTarget->createMCSubtargetInfo(Opts.Triple, Opts.CPU, FS)); assert(STI && "Unable to create subtarget info!"); - MCContext Ctx(Triple(Opts.Triple), MAI.get(), MRI.get(), MOFI.get(), + MCContext Ctx(Triple(Opts.Triple), MAI.get(), MRI.get(), /*MOFI=*/nullptr, STI.get(), &SrcMgr, &MCOptions); bool PIC = false; @@ -408,7 +404,12 @@ PIC = false; } - MOFI->initMCObjectFileInfo(Ctx, PIC); + // FIXME: This is not pretty. MCContext has a ptr to MCObjectFileInfo and + // MCObjectFileInfo needs a MCContext reference in order to initialize itself. + std::unique_ptr MOFI( + TheTarget->createMCObjectFileInfo(Ctx, PIC)); + Ctx.setObjectFileInfo(MOFI.get()); + if (Opts.SaveTemporaryLabels) Ctx.setAllowTemporaryLabels(false); if (Opts.GenDwarfForAssembly) diff --git a/llvm/include/llvm/MC/MCContext.h b/llvm/include/llvm/MC/MCContext.h --- a/llvm/include/llvm/MC/MCContext.h +++ b/llvm/include/llvm/MC/MCContext.h @@ -416,6 +416,8 @@ this->DiagHandler = DiagHandler; } + void setObjectFileInfo(const MCObjectFileInfo *Mofi) { MOFI = Mofi; } + const MCAsmInfo *getAsmInfo() const { return MAI; } const MCRegisterInfo *getRegisterInfo() const { return MRI; } diff --git a/llvm/include/llvm/MC/MCObjectFileInfo.h b/llvm/include/llvm/MC/MCObjectFileInfo.h --- a/llvm/include/llvm/MC/MCObjectFileInfo.h +++ b/llvm/include/llvm/MC/MCObjectFileInfo.h @@ -229,6 +229,7 @@ public: void initMCObjectFileInfo(MCContext &MCCtx, bool PIC, bool LargeCodeModel = false); + virtual ~MCObjectFileInfo(); MCContext &getContext() const { return *Ctx; } bool getSupportsWeakOmittedEHFrame() const { @@ -251,6 +252,7 @@ return CompactUnwindDwarfEHFrameOnly; } + virtual unsigned getTextSectionAlignment() const { return 4; } MCSection *getTextSection() const { return TextSection; } MCSection *getDataSection() const { return DataSection; } MCSection *getBSSSection() const { return BSSSection; } diff --git a/llvm/include/llvm/Support/TargetRegistry.h b/llvm/include/llvm/Support/TargetRegistry.h --- a/llvm/include/llvm/Support/TargetRegistry.h +++ b/llvm/include/llvm/Support/TargetRegistry.h @@ -23,6 +23,7 @@ #include "llvm/ADT/StringRef.h" #include "llvm/ADT/Triple.h" #include "llvm/ADT/iterator_range.h" +#include "llvm/MC/MCObjectFileInfo.h" #include "llvm/Support/CodeGen.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FormattedStream.h" @@ -130,6 +131,9 @@ using MCAsmInfoCtorFnTy = MCAsmInfo *(*)(const MCRegisterInfo &MRI, const Triple &TT, const MCTargetOptions &Options); + using MCObjectFileInfoCtorFnTy = MCObjectFileInfo *(*)(MCContext &Ctx, + bool PIC, + bool LargeCodeModel); using MCInstrInfoCtorFnTy = MCInstrInfo *(*)(); using MCInstrAnalysisCtorFnTy = MCInstrAnalysis *(*)(const MCInstrInfo *Info); using MCRegInfoCtorFnTy = MCRegisterInfo *(*)(const Triple &TT); @@ -227,6 +231,10 @@ /// registered. MCAsmInfoCtorFnTy MCAsmInfoCtorFn; + /// MCObjectFileInfoCtorFn - Constructor function for this target's + /// MCObjectFileInfo, if registered. + MCObjectFileInfoCtorFnTy MCObjectFileInfoCtorFn; + /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo, /// if registered. MCInstrInfoCtorFnTy MCInstrInfoCtorFn; @@ -350,6 +358,19 @@ return MCAsmInfoCtorFn(MRI, Triple(TheTriple), Options); } + /// createMCObjectFileInfo - Create a MCObjectFileInfo implementation for the + /// specified target triple. + /// + MCObjectFileInfo *createMCObjectFileInfo(MCContext &Ctx, bool PIC, + bool LargeCodeModel = false) const { + if (!MCObjectFileInfoCtorFn) { + MCObjectFileInfo *MOFI = new MCObjectFileInfo(); + MOFI->initMCObjectFileInfo(Ctx, PIC, LargeCodeModel); + return MOFI; + } + return MCObjectFileInfoCtorFn(Ctx, PIC, LargeCodeModel); + } + /// createMCInstrInfo - Create a MCInstrInfo implementation. /// MCInstrInfo *createMCInstrInfo() const { @@ -724,6 +745,20 @@ T.MCAsmInfoCtorFn = Fn; } + /// RegisterMCObjectFileInfo - Register a MCObjectFileInfo implementation for + /// the given target. + /// + /// Clients are responsible for ensuring that registration doesn't occur + /// while another thread is attempting to access the registry. Typically + /// this is done by initializing all targets at program startup. + /// + /// @param T - The target being registered. + /// @param Fn - A function to construct a MCObjectFileInfo for the target. + static void RegisterMCObjectFileInfo(Target &T, + Target::MCObjectFileInfoCtorFnTy Fn) { + T.MCObjectFileInfoCtorFn = Fn; + } + /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the /// given target. /// @@ -991,6 +1026,40 @@ } }; +/// RegisterMCObjectFileInfo - Helper template for registering a target object +/// file info implementation. This invokes the static "Create" method on the +/// class to actually do the construction. Usage: +/// +/// extern "C" void LLVMInitializeFooTarget() { +/// extern Target TheFooTarget; +/// RegisterMCObjectFileInfo X(TheFooTarget); +/// } +template struct RegisterMCObjectFileInfo { + RegisterMCObjectFileInfo(Target &T) { + TargetRegistry::RegisterMCObjectFileInfo(T, &Allocator); + } + +private: + static MCObjectFileInfo *Allocator(MCContext &Ctx, bool PIC, + bool LargeCodeModel = false) { + return new MCObjectFileInfoImpl(Ctx, PIC, LargeCodeModel); + } +}; + +/// RegisterMCObjectFileInfo - Helper template for registering a target object +/// file info implementation. This invokes the specified function to do the +/// construction. Usage: +/// +/// extern "C" void LLVMInitializeFooTarget() { +/// extern Target TheFooTarget; +/// RegisterMCObjectFileInfoFn X(TheFooTarget, TheFunction); +/// } +struct RegisterMCObjectFileInfoFn { + RegisterMCObjectFileInfoFn(Target &T, Target::MCObjectFileInfoCtorFnTy Fn) { + TargetRegistry::RegisterMCObjectFileInfo(T, Fn); + } +}; + /// RegisterMCInstrInfo - Helper template for registering a target instruction /// info implementation. This invokes the static "Create" method on the class /// to actually do the construction. Usage: diff --git a/llvm/lib/DWARFLinker/DWARFStreamer.cpp b/llvm/lib/DWARFLinker/DWARFStreamer.cpp --- a/llvm/lib/DWARFLinker/DWARFStreamer.cpp +++ b/llvm/lib/DWARFLinker/DWARFStreamer.cpp @@ -54,10 +54,10 @@ if (!MSTI) return error("no subtarget info for target " + TripleName, Context), false; - MOFI.reset(new MCObjectFileInfo); - MC.reset( - new MCContext(TheTriple, MAI.get(), MRI.get(), MOFI.get(), MSTI.get())); - MOFI->initMCObjectFileInfo(*MC, /*PIC=*/false); + MC.reset(new MCContext(TheTriple, MAI.get(), MRI.get(), /*MOFI=*/nullptr, + MSTI.get())); + MOFI.reset(TheTarget->createMCObjectFileInfo(*MC, /*PIC=*/false)); + MC->setObjectFileInfo(MOFI.get()); MAB = TheTarget->createMCAsmBackend(*MSTI, *MRI, MCOptions); if (!MAB) diff --git a/llvm/lib/MC/MCELFStreamer.cpp b/llvm/lib/MC/MCELFStreamer.cpp --- a/llvm/lib/MC/MCELFStreamer.cpp +++ b/llvm/lib/MC/MCELFStreamer.cpp @@ -90,7 +90,7 @@ void MCELFStreamer::InitSections(bool NoExecStack) { MCContext &Ctx = getContext(); SwitchSection(Ctx.getObjectFileInfo()->getTextSection()); - emitCodeAlignment(4); + emitCodeAlignment(Ctx.getObjectFileInfo()->getTextSectionAlignment()); if (NoExecStack) SwitchSection(Ctx.getAsmInfo()->getNonexecutableStackSection(Ctx)); diff --git a/llvm/lib/MC/MCObjectFileInfo.cpp b/llvm/lib/MC/MCObjectFileInfo.cpp --- a/llvm/lib/MC/MCObjectFileInfo.cpp +++ b/llvm/lib/MC/MCObjectFileInfo.cpp @@ -959,6 +959,8 @@ /* MultiSymbolsAllowed */ true, ".dwmac", XCOFF::SSUBTYP_DWMAC); } +MCObjectFileInfo::~MCObjectFileInfo() = default; + void MCObjectFileInfo::initMCObjectFileInfo(MCContext &MCCtx, bool PIC, bool LargeCodeModel) { PositionIndependent = PIC; diff --git a/llvm/lib/Object/ModuleSymbolTable.cpp b/llvm/lib/Object/ModuleSymbolTable.cpp --- a/llvm/lib/Object/ModuleSymbolTable.cpp +++ b/llvm/lib/Object/ModuleSymbolTable.cpp @@ -99,10 +99,11 @@ if (!MCII) return; - MCObjectFileInfo MOFI; - MCContext MCCtx(TT, MAI.get(), MRI.get(), &MOFI, STI.get()); - MOFI.initMCObjectFileInfo(MCCtx, /*PIC=*/false); - MOFI.setSDKVersion(M.getSDKVersion()); + MCContext MCCtx(TT, MAI.get(), MRI.get(), /*MOFI=*/nullptr, STI.get()); + std::unique_ptr MOFI( + T->createMCObjectFileInfo(MCCtx, /*PIC=*/false)); + MOFI->setSDKVersion(M.getSDKVersion()); + MCCtx.setObjectFileInfo(MOFI.get()); RecordStreamer Streamer(MCCtx, M); T->createNullTargetStreamer(Streamer); diff --git a/llvm/tools/llvm-dwp/llvm-dwp.cpp b/llvm/tools/llvm-dwp/llvm-dwp.cpp --- a/llvm/tools/llvm-dwp/llvm-dwp.cpp +++ b/llvm/tools/llvm-dwp/llvm-dwp.cpp @@ -880,9 +880,11 @@ if (!MSTI) return error("no subtarget info for target " + TripleName, Context); - MCObjectFileInfo MOFI; - MCContext MC(*ErrOrTriple, MAI.get(), MRI.get(), &MOFI, MSTI.get()); - MOFI.initMCObjectFileInfo(MC, /*PIC=*/false); + MCContext MC(*ErrOrTriple, MAI.get(), MRI.get(), /*MOFI=*/nullptr, + MSTI.get()); + std::unique_ptr MOFI( + TheTarget->createMCObjectFileInfo(MC, /*PIC=*/false)); + MC.setObjectFileInfo(MOFI.get()); MCTargetOptions Options; auto MAB = TheTarget->createMCAsmBackend(*MSTI, *MRI, Options); diff --git a/llvm/tools/llvm-exegesis/lib/SnippetFile.cpp b/llvm/tools/llvm-exegesis/lib/SnippetFile.cpp --- a/llvm/tools/llvm-exegesis/lib/SnippetFile.cpp +++ b/llvm/tools/llvm-exegesis/lib/SnippetFile.cpp @@ -130,13 +130,14 @@ BenchmarkCode Result; - MCObjectFileInfo ObjectFileInfo; const TargetMachine &TM = State.getTargetMachine(); MCContext Context(TM.getTargetTriple(), TM.getMCAsmInfo(), - TM.getMCRegisterInfo(), &ObjectFileInfo, + TM.getMCRegisterInfo(), /*MOFI=*/nullptr, TM.getMCSubtargetInfo()); + std::unique_ptr ObjectFileInfo( + TM.getTarget().createMCObjectFileInfo(Context, /*PIC=*/false)); + Context.setObjectFileInfo(ObjectFileInfo.get()); Context.initInlineSourceManager(); - ObjectFileInfo.initMCObjectFileInfo(Context, /*PIC=*/false); BenchmarkCodeStreamer Streamer(&Context, TM.getMCRegisterInfo(), &Result); std::string Error; diff --git a/llvm/tools/llvm-mc-assemble-fuzzer/llvm-mc-assemble-fuzzer.cpp b/llvm/tools/llvm-mc-assemble-fuzzer/llvm-mc-assemble-fuzzer.cpp --- a/llvm/tools/llvm-mc-assemble-fuzzer/llvm-mc-assemble-fuzzer.cpp +++ b/llvm/tools/llvm-mc-assemble-fuzzer/llvm-mc-assemble-fuzzer.cpp @@ -173,10 +173,11 @@ std::unique_ptr STI( TheTarget->createMCSubtargetInfo(TripleName, MCPU, FeaturesStr)); - MCObjectFileInfo MOFI; - MCContext Ctx(TheTriple, MAI.get(), MRI.get(), &MOFI, STI.get(), &SrcMgr); - static const bool UsePIC = false; - MOFI.initMCObjectFileInfo(Ctx, UsePIC); + MCContext Ctx(TheTriple, MAI.get(), MRI.get(), /*MOFI=*/nullptr, STI.get(), + &SrcMgr); + std::unique_ptr MOFI( + TheTarget->createMCObjectFileInfo(Ctx, /*PIC=*/false)); + Ctx.setObjectFileInfo(MOFI.get()); const unsigned OutputAsmVariant = 0; std::unique_ptr MCII(TheTarget->createMCInstrInfo()); diff --git a/llvm/tools/llvm-mc/llvm-mc.cpp b/llvm/tools/llvm-mc/llvm-mc.cpp --- a/llvm/tools/llvm-mc/llvm-mc.cpp +++ b/llvm/tools/llvm-mc/llvm-mc.cpp @@ -394,10 +394,11 @@ // FIXME: This is not pretty. MCContext has a ptr to MCObjectFileInfo and // MCObjectFileInfo needs a MCContext reference in order to initialize itself. - MCObjectFileInfo MOFI; - MCContext Ctx(TheTriple, MAI.get(), MRI.get(), &MOFI, STI.get(), &SrcMgr, - &MCOptions); - MOFI.initMCObjectFileInfo(Ctx, PIC, LargeCodeModel); + MCContext Ctx(TheTriple, MAI.get(), MRI.get(), /*MOFI=*/nullptr, STI.get(), + &SrcMgr, &MCOptions); + std::unique_ptr MOFI( + TheTarget->createMCObjectFileInfo(Ctx, PIC, LargeCodeModel)); + Ctx.setObjectFileInfo(MOFI.get()); if (SaveTempLabels) Ctx.setAllowTemporaryLabels(false); diff --git a/llvm/tools/llvm-mca/llvm-mca.cpp b/llvm/tools/llvm-mca/llvm-mca.cpp --- a/llvm/tools/llvm-mca/llvm-mca.cpp +++ b/llvm/tools/llvm-mca/llvm-mca.cpp @@ -371,15 +371,16 @@ TheTarget->createMCAsmInfo(*MRI, TripleName, MCOptions)); assert(MAI && "Unable to create target asm info!"); - MCObjectFileInfo MOFI; SourceMgr SrcMgr; // Tell SrcMgr about this buffer, which is what the parser will pick up. SrcMgr.AddNewSourceBuffer(std::move(*BufferPtr), SMLoc()); - MCContext Ctx(TheTriple, MAI.get(), MRI.get(), &MOFI, STI.get(), &SrcMgr); - - MOFI.initMCObjectFileInfo(Ctx, /*PIC=*/false); + MCContext Ctx(TheTriple, MAI.get(), MRI.get(), /*MOFI=*/nullptr, STI.get(), + &SrcMgr); + std::unique_ptr MOFI( + TheTarget->createMCObjectFileInfo(Ctx, /*PIC=*/false)); + Ctx.setObjectFileInfo(MOFI.get()); std::unique_ptr BOS; diff --git a/llvm/tools/llvm-ml/llvm-ml.cpp b/llvm/tools/llvm-ml/llvm-ml.cpp --- a/llvm/tools/llvm-ml/llvm-ml.cpp +++ b/llvm/tools/llvm-ml/llvm-ml.cpp @@ -281,10 +281,11 @@ // FIXME: This is not pretty. MCContext has a ptr to MCObjectFileInfo and // MCObjectFileInfo needs a MCContext reference in order to initialize itself. - MCObjectFileInfo MOFI; - MCContext Ctx(TheTriple, MAI.get(), MRI.get(), &MOFI, STI.get(), &SrcMgr); - MOFI.initMCObjectFileInfo(Ctx, /*PIC=*/false, - /*LargeCodeModel=*/true); + MCContext Ctx(TheTriple, MAI.get(), MRI.get(), /*MOFI=*/nullptr, STI.get(), + &SrcMgr); + std::unique_ptr MOFI(TheTarget->createMCObjectFileInfo( + Ctx, /*PIC=*/false, /*LargeCodeModel=*/true)); + Ctx.setObjectFileInfo(MOFI.get()); if (InputArgs.hasArg(OPT_save_temp_labels)) Ctx.setAllowTemporaryLabels(false); 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 @@ -1576,10 +1576,12 @@ if (!MII) reportError(Obj->getFileName(), "no instruction info for target " + TripleName); - MCObjectFileInfo MOFI; - MCContext Ctx(Triple(TripleName), AsmInfo.get(), MRI.get(), &MOFI, STI.get()); + MCContext Ctx(Triple(TripleName), AsmInfo.get(), MRI.get(), /*MOFI=*/nullptr, + STI.get()); // FIXME: for now initialize MCObjectFileInfo with default values - MOFI.initMCObjectFileInfo(Ctx, /*PIC=*/false); + std::unique_ptr MOFI( + TheTarget->createMCObjectFileInfo(Ctx, /*PIC=*/false)); + Ctx.setObjectFileInfo(MOFI.get()); std::unique_ptr DisAsm( TheTarget->createMCDisassembler(*STI, Ctx)); diff --git a/llvm/tools/llvm-profgen/ProfiledBinary.cpp b/llvm/tools/llvm-profgen/ProfiledBinary.cpp --- a/llvm/tools/llvm-profgen/ProfiledBinary.cpp +++ b/llvm/tools/llvm-profgen/ProfiledBinary.cpp @@ -332,9 +332,11 @@ if (!MII) exitWithError("no instruction info for target " + TripleName, FileName); - MCObjectFileInfo MOFI; - MCContext Ctx(Triple(TripleName), AsmInfo.get(), MRI.get(), &MOFI, STI.get()); - MOFI.initMCObjectFileInfo(Ctx, /*PIC=*/false); + MCContext Ctx(Triple(TripleName), AsmInfo.get(), MRI.get(), /*MOFI=*/nullptr, + STI.get()); + std::unique_ptr MOFI( + TheTarget->createMCObjectFileInfo(Ctx, /*PIC=*/false)); + Ctx.setObjectFileInfo(MOFI.get()); DisAsm.reset(TheTarget->createMCDisassembler(*STI, Ctx)); if (!DisAsm) exitWithError("no disassembler for target " + TripleName, FileName); diff --git a/llvm/unittests/MC/SystemZ/SystemZAsmLexerTest.cpp b/llvm/unittests/MC/SystemZ/SystemZAsmLexerTest.cpp --- a/llvm/unittests/MC/SystemZ/SystemZAsmLexerTest.cpp +++ b/llvm/unittests/MC/SystemZ/SystemZAsmLexerTest.cpp @@ -62,6 +62,7 @@ std::unique_ptr MRI; std::unique_ptr MUPMAI; std::unique_ptr MII; + std::unique_ptr MOFI; std::unique_ptr Str; std::unique_ptr Parser; std::unique_ptr Ctx; @@ -74,7 +75,6 @@ const Target *TheTarget; const MCTargetOptions MCOptions; - MCObjectFileInfo MOFI; SystemZAsmLexerTest() { // We will use the SystemZ triple, because of missing @@ -112,9 +112,11 @@ SrcMgr.AddNewSourceBuffer(std::move(Buffer), SMLoc()); EXPECT_EQ(Buffer, nullptr); - Ctx.reset(new MCContext(Triple, MUPMAI.get(), MRI.get(), &MOFI, STI.get(), - &SrcMgr, &MCOptions)); - MOFI.initMCObjectFileInfo(*Ctx, /*PIC=*/false, /*LargeCodeModel=*/false); + Ctx.reset(new MCContext(Triple, MUPMAI.get(), MRI.get(), /*MOFI=*/nullptr, + STI.get(), &SrcMgr, &MCOptions)); + MOFI.reset(TheTarget->createMCObjectFileInfo(*Ctx, /*PIC=*/false, + /*LargeCodeModel=*/false)); + Ctx->setObjectFileInfo(MOFI.get()); Str.reset(TheTarget->createNullStreamer(*Ctx)); diff --git a/mlir/lib/Dialect/GPU/Transforms/SerializeToHsaco.cpp b/mlir/lib/Dialect/GPU/Transforms/SerializeToHsaco.cpp --- a/mlir/lib/Dialect/GPU/Transforms/SerializeToHsaco.cpp +++ b/mlir/lib/Dialect/GPU/Transforms/SerializeToHsaco.cpp @@ -168,9 +168,11 @@ target->createMCAsmInfo(*mri, this->triple, mcOptions)); mai->setRelaxELFRelocations(true); - llvm::MCObjectFileInfo mofi; - llvm::MCContext ctx(triple, mai.get(), mri.get(), &mofi, &srcMgr, &mcOptions); - mofi.initMCObjectFileInfo(ctx, /*PIC=*/false, /*LargeCodeModel=*/false); + llvm::MCContext ctx(triple, mai.get(), mri.get(), /*MOFI=*/nullptr, &srcMgr, + &mcOptions); + std::unique_ptr mofi(target->createMCObjectFileInfo( + ctx, /*PIC=*/false, /*LargeCodeModel=*/false)); + ctx.setObjectFileInfo(mofi.get()); SmallString<128> cwd; if (!llvm::sys::fs::current_path(cwd))