Skip to content

Commit

Permalink
jit: check if dlfind failed when emitting a ccall (#50961)
Browse files Browse the repository at this point in the history
  • Loading branch information
gbaraldi authored Aug 21, 2023
1 parent 1182003 commit 430a74e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/jitlayers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1594,6 +1594,9 @@ struct JuliaOJIT::DLSymOptimizer {
auto libname = cast<ConstantDataArray>(GV->getInitializer())->getAsCString();
addr = lookup(libname.data(), fname.data());
} else {
// Can happen if we fail the compile time dlfind i.e when we try a symbol that doesn't exist in libc
if (dyn_cast<ConstantPointerNull>(libarg))
continue;
assert(cast<ConstantExpr>(libarg)->getOpcode() == Instruction::IntToPtr && "libarg should be either a global variable or a integer index!");
libarg = cast<ConstantExpr>(libarg)->getOperand(0);
auto libidx = cast<ConstantInt>(libarg)->getZExtValue();
Expand Down
5 changes: 5 additions & 0 deletions test/ccall.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1922,10 +1922,15 @@ function somefunction_not_found()
ccall((:somefunction, libfrobozz), Cvoid, ())
end

function somefunction_not_found_libc()
ccall(:test,Int,())
end

@testset "library not found" begin
if Sys.islinux()
@test_throws "could not load symbol \"somefunction\"" somefunction_not_found()
else
@test_throws "could not load library \"\"" somefunction_not_found()
end
@test_throws "could not load symbol \"test\"" somefunction_not_found_libc()
end

0 comments on commit 430a74e

Please sign in to comment.