Skip to content

Commit 430a74e

Browse files
authored
jit: check if dlfind failed when emitting a ccall (#50961)
Fixes #50899 (comment)
1 parent 1182003 commit 430a74e

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/jitlayers.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1594,6 +1594,9 @@ struct JuliaOJIT::DLSymOptimizer {
15941594
auto libname = cast<ConstantDataArray>(GV->getInitializer())->getAsCString();
15951595
addr = lookup(libname.data(), fname.data());
15961596
} else {
1597+
// Can happen if we fail the compile time dlfind i.e when we try a symbol that doesn't exist in libc
1598+
if (dyn_cast<ConstantPointerNull>(libarg))
1599+
continue;
15971600
assert(cast<ConstantExpr>(libarg)->getOpcode() == Instruction::IntToPtr && "libarg should be either a global variable or a integer index!");
15981601
libarg = cast<ConstantExpr>(libarg)->getOperand(0);
15991602
auto libidx = cast<ConstantInt>(libarg)->getZExtValue();

test/ccall.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1922,10 +1922,15 @@ function somefunction_not_found()
19221922
ccall((:somefunction, libfrobozz), Cvoid, ())
19231923
end
19241924

1925+
function somefunction_not_found_libc()
1926+
ccall(:test,Int,())
1927+
end
1928+
19251929
@testset "library not found" begin
19261930
if Sys.islinux()
19271931
@test_throws "could not load symbol \"somefunction\"" somefunction_not_found()
19281932
else
19291933
@test_throws "could not load library \"\"" somefunction_not_found()
19301934
end
1935+
@test_throws "could not load symbol \"test\"" somefunction_not_found_libc()
19311936
end

0 commit comments

Comments
 (0)