Skip to content

Commit

Permalink
use global symbols on Unix to support LD_PRELOAD interception (#451)
Browse files Browse the repository at this point in the history
* use global symbols on Unix to support LD_PRELOAD interception

* dlopen in deps

* move dlopen to src

* Update implementations.jl
  • Loading branch information
simonbyrne authored Jan 26, 2021
1 parent 1ebbbd9 commit 74f31f2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions deps/build.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ if binary == "system"
const mpiexec_cmd = Cmd(mpiexec isa String ? [mpiexec] : mpiexec)

_doc_external(fname) = ""

include(joinpath("..","src","implementations.jl"))

@info "Using implementation" libmpi mpiexec_cmd MPI_LIBRARY_VERSION_STRING
Expand Down
12 changes: 12 additions & 0 deletions src/implementations.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
const use_stdcall = startswith(basename(libmpi), "msmpi")

# This is required in addition to __init__() so that we can call library at precompilation time.
if Sys.isunix()
Libdl.dlopen(libmpi, Libdl.RTLD_LAZY | Libdl.RTLD_GLOBAL)
end

macro mpicall(expr)
@assert expr isa Expr && expr.head == :call && expr.args[1] == :ccall

# On unix systems we call the global symbols to allow for LD_PRELOAD interception
# It can be emulated in Windows (via Libdl.dllist), but this is not fast.
if Sys.isunix() && expr.args[2].head == :tuple
expr.args[2] = expr.args[2].args[1]
end

# Microsoft MPI uses stdcall calling convention
# this only affects 32-bit Windows
# unfortunately we need to use ccall to call Get_library_version
Expand Down

0 comments on commit 74f31f2

Please sign in to comment.