Skip to content

ccall(:foo) doesn't pick up LD_PRELOAD overrides #53747

Open
@green-nsk

Description

@green-nsk

we're using a custom network stack library that loads via LD_PRELOAD mechanism and overrides certain function calls (socket(), recv(), setsockopt() and others). For some reason starting julia-1.10 ccall(:socket) doesn't pick up LD_PRELOAD version of the call anymore.

We found a workaround to call ccall((:socket, "")) works with our LD_PRELOAD network stack. We'd like to understand what's changed and how the two ccall() versions are different and how we can make sure we don't hit that in the future versions.

Repro:

$ cat socket.c
__attribute__((visibility("default")))
int
socket(int domain, int type, int protocol) {
    return 42;
}

$ gcc -shared -o socket.so -fPIC socket.c
$ LD_PRELOAD=./socket.so julia-1.9.3 -e 'println(ccall(:socket, Cint, (Cint, Cint, Cint), 0, 0, 0))'
42
$ LD_PRELOAD=./socket.so julia-1.10.2 -e 'println(ccall(:socket, Cint, (Cint, Cint, Cint), 0, 0, 0))'
-1
$ LD_PRELOAD=./socket.so julia-1.10.2 -e 'println(ccall((:socket, ""), Cint, (Cint, Cint, Cint), 0, 0, 0))'
42
$ LD_PRELOAD=./socket.so julia-1.10.2 -e '
    using Libdl
    socket_ptr = dlopen("") do h ; dlsym(h, :socket) end
    println(ccall(socket_ptr, Cint, (Cint, Cint, Cint), 0, 0, 0))'
42

Julia downloaded from https://julialang-s3.julialang.org/bin/linux/x64/1.10/julia-1.10.2-linux-x86_64.tar.gz

julia> versioninfo()
Julia Version 1.10.2
Commit bd47eca2c8a (2024-03-01 10:14 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 32 × AMD Ryzen 9 5950X 16-Core Processor
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, znver3)
Threads: 1 default, 0 interactive, 1 GC (on 32 virtual cores)
Environment:
  JULIA_PKG_DEVDIR = /home/sfokin/code/

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions