Skip to content

Don't emit module metadata for non-toplevel modules. #58508

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/aotcompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -813,9 +813,10 @@ 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()), false);
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";
Expand Down
23 changes: 14 additions & 9 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2682,17 +2682,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<Module> jl_create_llvm_module(StringRef name, LLVMContext &context, const DataLayout &DL, const Triple &triple) JL_NOTSAFEPOINT
std::unique_ptr<Module> jl_create_llvm_module(StringRef name, LLVMContext &context,
const DataLayout &DL, const Triple &triple,
bool toplevel) JL_NOTSAFEPOINT
{
++ModulesCreated;
auto m = std::make_unique<Module>(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());

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

// when this is a toplevel module, add additional flags.
// otherwise, these are inherited from the parent module when linking.
if (toplevel) {
// 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;
}

Expand Down
15 changes: 11 additions & 4 deletions src/jitlayers.h
Original file line number Diff line number Diff line change
Expand Up @@ -671,15 +671,22 @@ class JuliaOJIT {
OptSelLayerT OptSelLayer;
};
extern JuliaOJIT *jl_ExecutionEngine;
std::unique_ptr<Module> 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<Module> jl_create_llvm_module(StringRef name, LLVMContext &ctx,
const DataLayout &DL, const Triple &triple,
bool toplevel) JL_NOTSAFEPOINT;
inline orc::ThreadSafeModule jl_create_ts_module(StringRef name, orc::ThreadSafeContext ctx,
const DataLayout &DL, const Triple &triple,
bool toplevel = true) 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, toplevel), ctx);
}

Module &jl_codegen_params_t::shared_module() JL_NOTSAFEPOINT {
if (!_shared_module) {
_shared_module = jl_create_llvm_module("globals", getContext(), DL, TargetTriple);
_shared_module =
jl_create_llvm_module("globals", getContext(), DL, TargetTriple, true);
}
return *_shared_module;
}
Expand Down