Skip to content

RFC: add a warning against having multiple copies of a shared library loaded #7490

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions base/c.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,16 @@ const RTLD_FIRST = 0x00000040

dlsym(hnd, s::Union(Symbol,String)) = ccall(:jl_dlsym, Ptr{Void}, (Ptr{Void}, Ptr{Uint8}), hnd, s)
dlsym_e(hnd, s::Union(Symbol,String)) = ccall(:jl_dlsym_e, Ptr{Void}, (Ptr{Void}, Ptr{Uint8}), hnd, s)
dlopen(s::String, flags::Integer) = ccall(:jl_load_dynamic_library, Ptr{Void}, (Ptr{Uint8},Uint32), s, flags)
dlopen_e(s::String, flags::Integer) = ccall(:jl_load_dynamic_library_e, Ptr{Void}, (Ptr{Uint8},Uint32), s, flags)
function dlopen(s::String, flags::Integer)
lib = ccall(:jl_load_dynamic_library, Ptr{Void}, (Ptr{Uint8},Uint32), s, flags)
Sys.check_dllist()
lib
end
function dlopen_e(s::String, flags::Integer)
lib = ccall(:jl_load_dynamic_library_e, Ptr{Void}, (Ptr{Uint8},Uint32), s, flags)
Sys.check_dllist()
lib
end
dlopen(s::String) = dlopen(s, RTLD_LAZY | RTLD_DEEPBIND)
dlopen_e(s::String) = dlopen_e(s, RTLD_LAZY | RTLD_DEEPBIND)
dlclose(p::Ptr) = if p!=C_NULL; ccall(:uv_dlclose,Void,(Ptr{Void},),p); end
Expand Down
9 changes: 4 additions & 5 deletions base/sysimg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,11 @@ include("client.jl")
include("printf.jl")
importall .Printf

# misc useful functions & macros
# misc useful functions & macros and system information
include("util.jl")
include("sysinfo.jl")
import .Sys.CPU_CORES


# sparse matrices and linear algebra
include("sparse.jl")
Expand All @@ -243,10 +246,6 @@ include("fftw.jl")
include("dsp.jl")
importall .DSP

# system information
include("sysinfo.jl")
import .Sys.CPU_CORES

# mathematical constants
include("constants.jl")

Expand Down
23 changes: 23 additions & 0 deletions base/sysinfo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,14 @@ total_memory() = ccall(:uv_get_total_memory, Uint64, ())

if OS_NAME === :Darwin
const dlext = "dylib"
const dlpattern = r"^([^.]+).*\.dylib$"
elseif OS_NAME === :Windows
const dlext = "dll"
const dlpattern = r"^(.+)\.dll$"
else
#assume OS_NAME === :Linux, or similar
const dlext = "so"
const dlpattern = r"^(.+?)\.so(?:\..*)?$"
end

# This is deprecated! use dlext instead!
Expand Down Expand Up @@ -217,4 +220,24 @@ function dlpath( libname::String )
return path
end

function check_dllist()
fullpaths = dllist()
dlls = [begin
x = basename(x)
m = match(dlpattern, x)
if m !== nothing
x = m.captures[1]
end
x
end for x in fullpaths]
(isdefined(Base, :STDERR) && isopen(Base.STDERR)) || return dlls
for (i,dl) in enumerate(dlls)
for j in i+1:length(dlls)
if dl == dlls[j]
warn("detected possible duplicate library loaded: $dl. this may lead to unexpected behavior.\n $(fullpaths[i])\n $(fullpaths[j])", once=true)
end
end
end
end

end