Skip to content

Commit 4d0f35d

Browse files
committed
Don't depend on CompilerSupportLibraries_jll from OpenBLAS_jll
This is important because CSL_jll loads in many other libraries that we may or may not care that much about, such as `libstdc++` and `libgomp`. We load `libstdc++` eagerly on Linux, so that will already be loaded in all cases that we care about, however on macOS we don't generally want that loaded, and this suppresses that. `libgomp` is needed by BB-provided software that uses OpenMP during compilation, however it can conflict with software compiled by the Intel compilers, such as `MKL`. It's best to allow MKL to load its OpenMP libraries first, so delaying loading `libgomp` until someone actually calls `using CompilerSupportLibraries_jll` is the right thing to do. In the future, we want to rework JLLs such that libraries aren't eagerly loaded at JLL `__init__()` time, but rather they should be JIT loaded upon first usage of the library handle itself. This would allow BB to emit much more fine-grained dependency structures, so that the distribution of a set of libraries can happen together, but the loading of said libraries would be independent.
1 parent c55000a commit 4d0f35d

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

stdlib/OpenBLAS_jll/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ uuid = "4536629a-c528-5b80-bd46-f80d51c5b363"
33
version = "0.3.23+0"
44

55
[deps]
6+
# See note in `src/OpenBLAS_jll.jl` about this dependency.
67
CompilerSupportLibraries_jll = "e66e0078-7015-5450-92f7-15fbd957f2ae"
78
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
89
Artifacts = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"

stdlib/OpenBLAS_jll/src/OpenBLAS_jll.jl

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,17 @@
22

33
## dummy stub for https://github.com/JuliaBinaryWrappers/OpenBLAS_jll.jl
44
baremodule OpenBLAS_jll
5-
using Base, Libdl, CompilerSupportLibraries_jll, Base.BinaryPlatforms
5+
using Base, Libdl, Base.BinaryPlatforms
6+
7+
# We are explicitly NOT loading this at runtime, as it contains `libgomp`
8+
# which conflicts with `libiomp5`, breaking things like MKL. In the future,
9+
# we hope to transition to a JLL interface that provides a more granular
10+
# interface than eagerly dlopen'ing all libraries provided in the JLL
11+
# which will eliminate issues like this, where we avoid loading a JLL
12+
# because we don't want to load a library that we don't even use yet.
13+
# using CompilerSupportLibraries_jll
14+
# Because of this however, we have to manually load the libraries we
15+
# _do_ care about, namely libgfortran
616
Base.Experimental.@compiler_options compile=min optimize=0 infer=false
717

818
const PATH_list = String[]
@@ -25,10 +35,13 @@ end
2535

2636
if Sys.iswindows()
2737
const libopenblas = "libopenblas$(libsuffix).dll"
38+
const _libgfortran = string("libgfortran-", libgfortran_version(HostPlatform()).major, ".dll")
2839
elseif Sys.isapple()
2940
const libopenblas = "@rpath/libopenblas$(libsuffix).dylib"
41+
const _libgfortran = string("@rpath/", "libgfortran.", libgfortran_version(HostPlatform()).major, ".dylib")
3042
else
3143
const libopenblas = "libopenblas$(libsuffix).so"
44+
const _libgfortran = string("libgfortran.so.", libgfortran_version(HostPlatform()).major)
3245
end
3346

3447
function __init__()
@@ -50,6 +63,10 @@ function __init__()
5063
ENV["OPENBLAS_DEFAULT_NUM_THREADS"] = "1"
5164
end
5265

66+
# As mentioned above, we are sneaking this in here so that we don't have to
67+
# depend on CSL_jll and load _all_ of its libraries.
68+
dlopen(_libgfortran)
69+
5370
global libopenblas_handle = dlopen(libopenblas)
5471
global libopenblas_path = dlpath(libopenblas_handle)
5572
global artifact_dir = dirname(Sys.BINDIR)

0 commit comments

Comments
 (0)