Skip to content

Commit 74f31f2

Browse files
authored
use global symbols on Unix to support LD_PRELOAD interception (#451)
* use global symbols on Unix to support LD_PRELOAD interception * dlopen in deps * move dlopen to src * Update implementations.jl
1 parent 1ebbbd9 commit 74f31f2

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

deps/build.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ if binary == "system"
7979
const mpiexec_cmd = Cmd(mpiexec isa String ? [mpiexec] : mpiexec)
8080

8181
_doc_external(fname) = ""
82+
8283
include(joinpath("..","src","implementations.jl"))
8384

8485
@info "Using implementation" libmpi mpiexec_cmd MPI_LIBRARY_VERSION_STRING

src/implementations.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
const use_stdcall = startswith(basename(libmpi), "msmpi")
22

3+
# This is required in addition to __init__() so that we can call library at precompilation time.
4+
if Sys.isunix()
5+
Libdl.dlopen(libmpi, Libdl.RTLD_LAZY | Libdl.RTLD_GLOBAL)
6+
end
7+
38
macro mpicall(expr)
49
@assert expr isa Expr && expr.head == :call && expr.args[1] == :ccall
10+
11+
# On unix systems we call the global symbols to allow for LD_PRELOAD interception
12+
# It can be emulated in Windows (via Libdl.dllist), but this is not fast.
13+
if Sys.isunix() && expr.args[2].head == :tuple
14+
expr.args[2] = expr.args[2].args[1]
15+
end
16+
517
# Microsoft MPI uses stdcall calling convention
618
# this only affects 32-bit Windows
719
# unfortunately we need to use ccall to call Get_library_version

0 commit comments

Comments
 (0)