@@ -11,38 +11,40 @@ GlobalVariable *jl_emit_RTLD_DEFAULT_var(Module *M)
11
11
// Find or create the GVs for the library and symbol lookup.
12
12
// Return `runtime_lib` (whether the library name is a string)
13
13
// The `lib` and `sym` GV returned may not be in the current module.
14
- static bool runtime_sym_gvs (jl_codegen_params_t &emission_context, LLVMContext &ctxt , const char *f_lib, const char *f_name,
14
+ static bool runtime_sym_gvs (jl_codectx_t &ctx , const char *f_lib, const char *f_name,
15
15
GlobalVariable *&lib, GlobalVariable *&sym)
16
16
{
17
- Module *M = emission_context.shared_module (ctxt);
17
+ auto &TSM = ctx.emission_context .shared_module (*jl_Module);
18
+ // Safe b/c emission context holds context lock
19
+ auto M = TSM.getModuleUnlocked ();
18
20
bool runtime_lib = false ;
19
21
GlobalVariable *libptrgv;
20
22
jl_codegen_params_t ::SymMapGV *symMap;
21
23
#ifdef _OS_WINDOWS_
22
24
if ((intptr_t )f_lib == (intptr_t )JL_EXE_LIBNAME) {
23
25
libptrgv = prepare_global_in (M, jlexe_var);
24
- symMap = &emission_context.symMapExe ;
26
+ symMap = &ctx. emission_context .symMapExe ;
25
27
}
26
28
else if ((intptr_t )f_lib == (intptr_t )JL_LIBJULIA_INTERNAL_DL_LIBNAME) {
27
29
libptrgv = prepare_global_in (M, jldlli_var);
28
- symMap = &emission_context.symMapDlli ;
30
+ symMap = &ctx. emission_context .symMapDlli ;
29
31
}
30
32
else if ((intptr_t )f_lib == (intptr_t )JL_LIBJULIA_DL_LIBNAME) {
31
33
libptrgv = prepare_global_in (M, jldll_var);
32
- symMap = &emission_context.symMapDll ;
34
+ symMap = &ctx. emission_context .symMapDll ;
33
35
}
34
36
else
35
37
#endif
36
38
if (f_lib == NULL ) {
37
39
libptrgv = jl_emit_RTLD_DEFAULT_var (M);
38
- symMap = &emission_context.symMapDefault ;
40
+ symMap = &ctx. emission_context .symMapDefault ;
39
41
}
40
42
else {
41
43
std::string name = " ccalllib_" ;
42
44
name += llvm::sys::path::filename (f_lib);
43
45
name += std::to_string (globalUniqueGeneratedNames++);
44
46
runtime_lib = true ;
45
- auto &libgv = emission_context.libMapGV [f_lib];
47
+ auto &libgv = ctx. emission_context .libMapGV [f_lib];
46
48
if (libgv.first == NULL ) {
47
49
libptrgv = new GlobalVariable (*M, getInt8PtrTy (M->getContext ()), false ,
48
50
GlobalVariable::ExternalLinkage,
@@ -175,7 +177,7 @@ static Value *runtime_sym_lookup(
175
177
Constant::getNullValue (T_pvoidfunc), gvname);
176
178
}
177
179
else {
178
- runtime_lib = runtime_sym_gvs (ctx. emission_context , ctx. builder . getContext () , f_lib, f_name, libptrgv, llvmgv);
180
+ runtime_lib = runtime_sym_gvs (ctx, f_lib, f_name, libptrgv, llvmgv);
179
181
libptrgv = prepare_global_in (jl_Module, libptrgv);
180
182
}
181
183
llvmgv = prepare_global_in (jl_Module, llvmgv);
@@ -185,13 +187,14 @@ static Value *runtime_sym_lookup(
185
187
// Emit a "PLT" entry that will be lazily initialized
186
188
// when being called the first time.
187
189
static GlobalVariable *emit_plt_thunk (
188
- jl_codegen_params_t &emission_context ,
190
+ jl_codectx_t &ctx ,
189
191
FunctionType *functype, const AttributeList &attrs,
190
192
CallingConv::ID cc, const char *f_lib, const char *f_name,
191
193
GlobalVariable *libptrgv, GlobalVariable *llvmgv,
192
194
bool runtime_lib)
193
195
{
194
- Module *M = emission_context.shared_module (functype->getContext ());
196
+ auto &TSM = ctx.emission_context .shared_module (*jl_Module);
197
+ Module *M = TSM.getModuleUnlocked ();
195
198
PointerType *funcptype = PointerType::get (functype, 0 );
196
199
libptrgv = prepare_global_in (M, libptrgv);
197
200
llvmgv = prepare_global_in (M, llvmgv);
@@ -211,7 +214,7 @@ static GlobalVariable *emit_plt_thunk(
211
214
fname);
212
215
BasicBlock *b0 = BasicBlock::Create (M->getContext (), " top" , plt);
213
216
IRBuilder<> irbuilder (b0);
214
- Value *ptr = runtime_sym_lookup (emission_context, irbuilder, NULL , funcptype, f_lib, NULL , f_name, plt, libptrgv,
217
+ Value *ptr = runtime_sym_lookup (ctx. emission_context , irbuilder, NULL , funcptype, f_lib, NULL , f_name, plt, libptrgv,
215
218
llvmgv, runtime_lib);
216
219
StoreInst *store = irbuilder.CreateAlignedStore (irbuilder.CreateBitCast (ptr, T_pvoidfunc), got, Align (sizeof (void *)));
217
220
store->setAtomic (AtomicOrdering::Release);
@@ -266,14 +269,14 @@ static Value *emit_plt(
266
269
assert (!functype->isVarArg ());
267
270
GlobalVariable *libptrgv;
268
271
GlobalVariable *llvmgv;
269
- bool runtime_lib = runtime_sym_gvs (ctx. emission_context , ctx. builder . getContext () , f_lib, f_name, libptrgv, llvmgv);
272
+ bool runtime_lib = runtime_sym_gvs (ctx, f_lib, f_name, libptrgv, llvmgv);
270
273
PointerType *funcptype = PointerType::get (functype, 0 );
271
274
272
275
auto &pltMap = ctx.emission_context .allPltMap [attrs];
273
276
auto key = std::make_tuple (llvmgv, functype, cc);
274
277
GlobalVariable *&sharedgot = pltMap[key];
275
278
if (!sharedgot) {
276
- sharedgot = emit_plt_thunk (ctx. emission_context ,
279
+ sharedgot = emit_plt_thunk (ctx,
277
280
functype, attrs, cc, f_lib, f_name, libptrgv, llvmgv, runtime_lib);
278
281
}
279
282
GlobalVariable *got = prepare_global_in (jl_Module, sharedgot);
@@ -921,7 +924,7 @@ static jl_cgval_t emit_llvmcall(jl_codectx_t &ctx, jl_value_t **args, size_t nar
921
924
// save the module to be linked later.
922
925
// we cannot do this right now, because linking mutates the destination module,
923
926
// which might invalidate LLVM values cached in cgval_t's (specifically constant arrays)
924
- ctx.llvmcall_modules .push_back (std::move (Mod));
927
+ ctx.llvmcall_modules .push_back (orc::ThreadSafeModule ( std::move (Mod), ctx. emission_context . tsctx ));
925
928
926
929
JL_GC_POP ();
927
930
0 commit comments