Skip to content

Commit 43c389a

Browse files
committed
Check for conflicting @ccallable name before JIT registration
This turns the existing segfault into an error: ```julia julia> using Foo, Bar ERROR: @ccallable: symbol 'foo' conflicts with existing symbol Stacktrace: [1] _include_from_serialized(pkg::Base.PkgId, path::String, ocachepath::String, depmods::Vector{…}, ignore_native::Nothing; register::Bool) @ Base ./loading.jl:1241 [2] _include_from_serialized (repeats 2 times) @ ./loading.jl:1206 [inlined] [3] _require_search_from_serialized(pkg::Base.PkgId, sourcepath::String, build_id::UInt128, stalecheck::Bool; reasons::Dict{…}, DEPOT_PATH::Vector{…}) @ Base ./loading.jl:2018 [4] _require(pkg::Base.PkgId, env::String) @ Base ./loading.jl:2477 [5] __require_prelocked(uuidkey::Base.PkgId, env::String) @ Base ./loading.jl:2343 [6] #invoke_in_world#2 @ ./essentials.jl:1082 [inlined] [7] invoke_in_world @ ./essentials.jl:1079 [inlined] [8] _require_prelocked(uuidkey::Base.PkgId, env::String) @ Base ./loading.jl:2330 [9] macro expansion @ ./loading.jl:2269 [inlined] [10] macro expansion @ ./lock.jl:287 [inlined] [11] __require(into::Module, mod::Symbol) @ Base ./loading.jl:2226 [12] #invoke_in_world#2 @ ./essentials.jl:1082 [inlined] [13] invoke_in_world @ ./essentials.jl:1079 [inlined] [14] require(into::Module, mod::Symbol) @ Base ./loading.jl:2219 Some type information was truncated. Use `show(err)` to see complete types. ``` Ideally the loading code would know to anticipate this and display a better error to the user (w/o the useless stack-trace) Resolves #54878, although we may wish to make this a warning or provide an alternative `using` / `import` pathway that can allow `@ccallable` registration to fail.
1 parent a73ba3b commit 43c389a

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/codegen.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7619,12 +7619,15 @@ const char *jl_generate_ccallable(LLVMOrcThreadSafeModuleRef llvmmod, void *sysi
76197619
// restore a ccallable from the system image
76207620
void *addr;
76217621
int found = jl_dlsym(sysimg_handle, name, &addr, 0);
7622-
if (found)
7623-
add_named_global(name, addr);
7624-
else {
7625-
err = jl_get_exceptionf(jl_errorexception_type, "%s not found in sysimg", name);
7622+
if (!found) {
7623+
err = jl_get_exceptionf(jl_errorexception_type, "@ccallable: symbol '%s' not found in sysimg", name);
7624+
jl_throw(err);
7625+
}
7626+
if (jl_ExecutionEngine->getGlobalValueAddress(StringRef(name)) != 0) {
7627+
err = jl_get_exceptionf(jl_errorexception_type, "@ccallable: symbol '%s' conflicts with existing symbol", name);
76267628
jl_throw(err);
76277629
}
7630+
add_named_global(name, addr);
76287631
}
76297632
else {
76307633
jl_method_instance_t *lam = jl_get_specialization1((jl_tupletype_t*)sigt, world, &min_valid, &max_valid, 0);

0 commit comments

Comments
 (0)