diff --git a/src/aotcompile.cpp b/src/aotcompile.cpp index c11357d276482..652982c6c7523 100644 --- a/src/aotcompile.cpp +++ b/src/aotcompile.cpp @@ -816,9 +816,12 @@ void *jl_emit_native_impl(jl_array_t *codeinfos, LLVMOrcThreadSafeModuleRef llvm continue; // skip any duplicates that accidentally made there way in here (or make this an error?) if (jl_ir_inlining_cost((jl_value_t*)src) < UINT16_MAX) params.safepoint_on_entry = false; // ensure we don't block ExpandAtomicModifyPass from inlining this code if applicable - orc::ThreadSafeModule result_m = jl_create_ts_module(name_from_method_instance(jl_get_ci_mi(codeinst)), - params.tsctx, clone.getModuleUnlocked()->getDataLayout(), - Triple(clone.getModuleUnlocked()->getTargetTriple())); + orc::ThreadSafeModule result_m = + jl_create_ts_module(name_from_method_instance(jl_get_ci_mi(codeinst)), + params.tsctx, + clone.getModuleUnlocked()->getDataLayout(), + Triple(clone.getModuleUnlocked()->getTargetTriple()), + clone.getModuleUnlocked()); jl_llvm_functions_t decls; if (!(params.params->force_emit_all) && jl_atomic_load_relaxed(&codeinst->invoke) == jl_fptr_const_return_addr) decls.functionObject = "jl_fptr_const_return"; diff --git a/src/codegen.cpp b/src/codegen.cpp index c6932bde61d2e..a595fbc1fdcc6 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -2684,17 +2684,12 @@ static jl_cgval_t convert_julia_type(jl_codectx_t &ctx, const jl_cgval_t &v, jl_ return jl_cgval_t(v, typ, new_tindex); } -std::unique_ptr jl_create_llvm_module(StringRef name, LLVMContext &context, const DataLayout &DL, const Triple &triple) JL_NOTSAFEPOINT +std::unique_ptr jl_create_llvm_module(StringRef name, LLVMContext &context, + const DataLayout &DL, const Triple &triple, + Module *source) JL_NOTSAFEPOINT { ++ModulesCreated; auto m = std::make_unique(name, context); - // According to clang darwin above 10.10 supports dwarfv4 - if (!m->getModuleFlag("Dwarf Version")) { - m->addModuleFlag(llvm::Module::Warning, "Dwarf Version", 4); - } - if (!m->getModuleFlag("Debug Info Version")) - m->addModuleFlag(llvm::Module::Warning, "Debug Info Version", - llvm::DEBUG_METADATA_VERSION); m->setDataLayout(DL); m->setTargetTriple(triple.str()); @@ -2705,9 +2700,29 @@ std::unique_ptr jl_create_llvm_module(StringRef name, LLVMContext &conte m->setOverrideStackAlignment(16); } + if (source) { + // Copy module flags from source module + SmallVector Flags; + source->getModuleFlagsMetadata(Flags); + for (const auto &Flag : Flags) { + m->addModuleFlag(Flag.Behavior, Flag.Key->getString(), Flag.Val); + } + // Copy other module-level properties + m->setStackProtectorGuard(source->getStackProtectorGuard()); + m->setOverrideStackAlignment(source->getOverrideStackAlignment()); + } + else { + // No source: set default Julia flags + // According to clang darwin above 10.10 supports dwarfv4 + m->addModuleFlag(llvm::Module::Warning, "Dwarf Version", 4); + m->addModuleFlag(llvm::Module::Warning, "Debug Info Version", + llvm::DEBUG_METADATA_VERSION); + #if defined(JL_DEBUG_BUILD) - m->setStackProtectorGuard("global"); + m->setStackProtectorGuard("global"); #endif + } + return m; } diff --git a/src/jitlayers.h b/src/jitlayers.h index 331d9accc8fb8..f77b21ce39d21 100644 --- a/src/jitlayers.h +++ b/src/jitlayers.h @@ -667,10 +667,16 @@ class JuliaOJIT { OptSelLayerT OptSelLayer; }; extern JuliaOJIT *jl_ExecutionEngine; -std::unique_ptr jl_create_llvm_module(StringRef name, LLVMContext &ctx, const DataLayout &DL, const Triple &triple) JL_NOTSAFEPOINT; -inline orc::ThreadSafeModule jl_create_ts_module(StringRef name, orc::ThreadSafeContext ctx, const DataLayout &DL, const Triple &triple) JL_NOTSAFEPOINT { +std::unique_ptr jl_create_llvm_module(StringRef name, LLVMContext &ctx, + const DataLayout &DL, const Triple &triple, + Module *source = nullptr) JL_NOTSAFEPOINT; +inline orc::ThreadSafeModule jl_create_ts_module(StringRef name, orc::ThreadSafeContext ctx, + const DataLayout &DL, const Triple &triple, + Module *source = nullptr) JL_NOTSAFEPOINT +{ auto lock = ctx.getLock(); - return orc::ThreadSafeModule(jl_create_llvm_module(name, *ctx.getContext(), DL, triple), ctx); + return orc::ThreadSafeModule( + jl_create_llvm_module(name, *ctx.getContext(), DL, triple, source), ctx); } Module &jl_codegen_params_t::shared_module() JL_NOTSAFEPOINT {