Skip to content

Commit a7df949

Browse files
committed
Don't emit module metadata for non-toplevel modules.
Instead, rely on the linker automatically inheriting the metadata from the parent module. This avoids warnings and aborts with external users such as GPUCompiler.jl.
1 parent 157b8bc commit a7df949

File tree

3 files changed

+29
-16
lines changed

3 files changed

+29
-16
lines changed

src/aotcompile.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -813,9 +813,10 @@ void *jl_emit_native_impl(jl_array_t *codeinfos, LLVMOrcThreadSafeModuleRef llvm
813813
continue; // skip any duplicates that accidentally made there way in here (or make this an error?)
814814
if (jl_ir_inlining_cost((jl_value_t*)src) < UINT16_MAX)
815815
params.safepoint_on_entry = false; // ensure we don't block ExpandAtomicModifyPass from inlining this code if applicable
816-
orc::ThreadSafeModule result_m = jl_create_ts_module(name_from_method_instance(jl_get_ci_mi(codeinst)),
817-
params.tsctx, clone.getModuleUnlocked()->getDataLayout(),
818-
Triple(clone.getModuleUnlocked()->getTargetTriple()));
816+
orc::ThreadSafeModule result_m = jl_create_ts_module(
817+
name_from_method_instance(jl_get_ci_mi(codeinst)), params.tsctx,
818+
clone.getModuleUnlocked()->getDataLayout(),
819+
Triple(clone.getModuleUnlocked()->getTargetTriple()), false);
819820
jl_llvm_functions_t decls;
820821
if (!(params.params->force_emit_all) && jl_atomic_load_relaxed(&codeinst->invoke) == jl_fptr_const_return_addr)
821822
decls.functionObject = "jl_fptr_const_return";

src/codegen.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2682,17 +2682,12 @@ static jl_cgval_t convert_julia_type(jl_codectx_t &ctx, const jl_cgval_t &v, jl_
26822682
return jl_cgval_t(v, typ, new_tindex);
26832683
}
26842684

2685-
std::unique_ptr<Module> jl_create_llvm_module(StringRef name, LLVMContext &context, const DataLayout &DL, const Triple &triple) JL_NOTSAFEPOINT
2685+
std::unique_ptr<Module> jl_create_llvm_module(StringRef name, LLVMContext &context,
2686+
const DataLayout &DL, const Triple &triple,
2687+
bool toplevel) JL_NOTSAFEPOINT
26862688
{
26872689
++ModulesCreated;
26882690
auto m = std::make_unique<Module>(name, context);
2689-
// According to clang darwin above 10.10 supports dwarfv4
2690-
if (!m->getModuleFlag("Dwarf Version")) {
2691-
m->addModuleFlag(llvm::Module::Warning, "Dwarf Version", 4);
2692-
}
2693-
if (!m->getModuleFlag("Debug Info Version"))
2694-
m->addModuleFlag(llvm::Module::Warning, "Debug Info Version",
2695-
llvm::DEBUG_METADATA_VERSION);
26962691
m->setDataLayout(DL);
26972692
m->setTargetTriple(triple.str());
26982693

@@ -2703,9 +2698,19 @@ std::unique_ptr<Module> jl_create_llvm_module(StringRef name, LLVMContext &conte
27032698
m->setOverrideStackAlignment(16);
27042699
}
27052700

2701+
// when this is a toplevel module, add additional flags.
2702+
// otherwise, these are inherited from the parent module when linking.
2703+
if (toplevel) {
2704+
// According to clang darwin above 10.10 supports dwarfv4
2705+
m->addModuleFlag(llvm::Module::Warning, "Dwarf Version", 4);
2706+
m->addModuleFlag(llvm::Module::Warning, "Debug Info Version",
2707+
llvm::DEBUG_METADATA_VERSION);
2708+
27062709
#if defined(JL_DEBUG_BUILD)
2707-
m->setStackProtectorGuard("global");
2710+
m->setStackProtectorGuard("global");
27082711
#endif
2712+
}
2713+
27092714
return m;
27102715
}
27112716

src/jitlayers.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -671,15 +671,22 @@ class JuliaOJIT {
671671
OptSelLayerT OptSelLayer;
672672
};
673673
extern JuliaOJIT *jl_ExecutionEngine;
674-
std::unique_ptr<Module> jl_create_llvm_module(StringRef name, LLVMContext &ctx, const DataLayout &DL, const Triple &triple) JL_NOTSAFEPOINT;
675-
inline orc::ThreadSafeModule jl_create_ts_module(StringRef name, orc::ThreadSafeContext ctx, const DataLayout &DL, const Triple &triple) JL_NOTSAFEPOINT {
674+
std::unique_ptr<Module> jl_create_llvm_module(StringRef name, LLVMContext &ctx,
675+
const DataLayout &DL, const Triple &triple,
676+
bool toplevel) JL_NOTSAFEPOINT;
677+
inline orc::ThreadSafeModule jl_create_ts_module(StringRef name, orc::ThreadSafeContext ctx,
678+
const DataLayout &DL, const Triple &triple,
679+
bool toplevel = true) JL_NOTSAFEPOINT
680+
{
676681
auto lock = ctx.getLock();
677-
return orc::ThreadSafeModule(jl_create_llvm_module(name, *ctx.getContext(), DL, triple), ctx);
682+
return orc::ThreadSafeModule(
683+
jl_create_llvm_module(name, *ctx.getContext(), DL, triple, toplevel), ctx);
678684
}
679685

680686
Module &jl_codegen_params_t::shared_module() JL_NOTSAFEPOINT {
681687
if (!_shared_module) {
682-
_shared_module = jl_create_llvm_module("globals", getContext(), DL, TargetTriple);
688+
_shared_module =
689+
jl_create_llvm_module("globals", getContext(), DL, TargetTriple, true);
683690
}
684691
return *_shared_module;
685692
}

0 commit comments

Comments
 (0)