From 430a74e2b9bdc65dca4170c32045cd33005ea0cc Mon Sep 17 00:00:00 2001 From: Gabriel Baraldi Date: Mon, 21 Aug 2023 13:07:35 -0300 Subject: [PATCH] jit: check if dlfind failed when emitting a ccall (#50961) Fixes https://github.com/JuliaLang/julia/pull/50899#issuecomment-1682628441 --- src/jitlayers.cpp | 3 +++ test/ccall.jl | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/src/jitlayers.cpp b/src/jitlayers.cpp index fc30072b2f89a..1d51a0983d982 100644 --- a/src/jitlayers.cpp +++ b/src/jitlayers.cpp @@ -1594,6 +1594,9 @@ struct JuliaOJIT::DLSymOptimizer { auto libname = cast(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(libarg)) + continue; assert(cast(libarg)->getOpcode() == Instruction::IntToPtr && "libarg should be either a global variable or a integer index!"); libarg = cast(libarg)->getOperand(0); auto libidx = cast(libarg)->getZExtValue(); diff --git a/test/ccall.jl b/test/ccall.jl index d55ba03799039..6e8269a36225d 100644 --- a/test/ccall.jl +++ b/test/ccall.jl @@ -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