Skip to content

On Musl systems, can't ccall into a library with the soname #36458

Closed

Description

How to reproduce: in a Musl system (I used using BinaryBuilderBase; BinaryBuilderBase.runshell(Linux(:x86_64, libc = :musl);verbose=true)) start Julia and do

julia> using Pkg, Libdl

julia> Pkg.add("Cuba_jll")
   Updating registry at `~/.julia/registries/General`
  Resolving package versions...
No Changes to `~/.julia/environments/v1.5/Project.toml`
No Changes to `~/.julia/environments/v1.5/Manifest.toml`

julia> using Cuba_jll

julia> filter(lib -> occursin("libcuba", lib), dllist())
1-element Array{String,1}:
 "/root/.julia/artifacts/cb5872bf2d53927c3a13ed537915a8d63de707a7/lib/libcuba.so"

julia> libcuba
"libcuba.so"

julia> ccall((:cubacores, libcuba), Ptr{Cvoid}, (Cint, Cint), 0, 1000)
ERROR: could not load library "libcuba.so"
Error loading shared library libcuba.so: No such file or directory
Stacktrace:
 [1] top-level scope at ./REPL[6]:1

julia> const lib = Cuba_jll.libcuba_path
"/root/.julia/artifacts/cb5872bf2d53927c3a13ed537915a8d63de707a7/lib/libcuba.so"

julia> ccall((:cubacores, lib), Ptr{Cvoid}, (Cint, Cint), 0, 1000)
Ptr{Nothing} @0x00007fb842c77920

The function can be ccalled if the library is given with the full path, but not if only the basename is passed, even if the library is already loaded, as shown by its presence in dllist. JLL packages use the basename of the library because they can't set a const with the full path, for relocatability.

strace shows that libcuba.so is searched everywhere, but not where Julia should know where it is:

open("/usr/local/lib64/libcuba.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/local/lib/libcuba.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/local/lib/libcuba.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/lib/libcuba.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/lib64/libcuba.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/lib/libcuba.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/opt/x86_64-linux-musl/x86_64-linux-musl/lib64/libcuba.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/opt/x86_64-linux-musl/x86_64-linux-musl/lib/libcuba.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/opt/x86_64-linux-gnu/x86_64-linux-gnu/lib64/libcuba.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/opt/x86_64-linux-gnu/x86_64-linux-gnu/lib/libcuba.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/opt/x86_64-linux-musl/x86_64-linux-musl/lib64/libcuba.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/opt/x86_64-linux-musl/x86_64-linux-musl/lib/libcuba.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/workspace/destdir/lib64/libcuba.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/workspace/destdir/lib/libcuba.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/workspace/bin/../lib/libcuba.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/workspace/bin/../lib/julia/libcuba.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/lib/libcuba.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/local/lib/libcuba.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/lib/libcuba.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/local/lib64/libcuba.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/local/lib/libcuba.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/local/lib/libcuba.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/lib/libcuba.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/lib64/libcuba.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/lib/libcuba.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/opt/x86_64-linux-musl/x86_64-linux-musl/lib64/libcuba.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/opt/x86_64-linux-musl/x86_64-linux-musl/lib/libcuba.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/opt/x86_64-linux-gnu/x86_64-linux-gnu/lib64/libcuba.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/opt/x86_64-linux-gnu/x86_64-linux-gnu/lib/libcuba.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/opt/x86_64-linux-musl/x86_64-linux-musl/lib64/libcuba.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/opt/x86_64-linux-musl/x86_64-linux-musl/lib/libcuba.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/workspace/destdir/lib64/libcuba.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/workspace/destdir/lib/libcuba.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/workspace/bin/../lib/libcuba.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/workspace/bin/../lib/julia/libcuba.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/lib/libcuba.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/local/lib/libcuba.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/lib/libcuba.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)

First reported in JuliaStats/Rmath.jl#70.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

compiler:muslSupport for musl linked binaries on linux instead of glibcneeds decisionA decision on this change is needed

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions