Skip to content

Commit 02574e3

Browse files
authored
Introduce LLD_jll as stdlib (#46455)
* Introduce LLD_jll to stdlib * Add symlinks to lld to libexecdir * Allow to compile LLD from source (during LLVM compilation) + remove symlinks * Fix directory of libraries for Windows
1 parent 7273c48 commit 02574e3

File tree

9 files changed

+167
-5
lines changed

9 files changed

+167
-5
lines changed

Make.inc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ USE_SYSTEM_PATCHELF:=0
6666
USE_SYSTEM_LIBWHICH:=0
6767
USE_SYSTEM_ZLIB:=0
6868
USE_SYSTEM_P7ZIP:=0
69+
USE_SYSTEM_LLD:=0
6970

7071
# Link to the LLVM shared library
7172
USE_LLVM_SHLIB := 1
@@ -347,6 +348,7 @@ BUILD_LLVM_CLANG := 0
347348
# see http://lldb.llvm.org/build.html for dependencies
348349
BUILD_LLDB := 0
349350
BUILD_LIBCXX := 0
351+
BUILD_LLD := 1
350352

351353
# Options to enable Polly and its code-generation options
352354
USE_POLLY := 0
@@ -1151,7 +1153,7 @@ LIBGFORTRAN_VERSION := $(subst libgfortran,,$(filter libgfortran%,$(subst -,$(SP
11511153
# Note: we explicitly _do not_ define `CSL` here, since it requires some more
11521154
# advanced techniques to decide whether it should be installed from a BB source
11531155
# or not. See `deps/csl.mk` for more detail.
1154-
BB_PROJECTS := BLASTRAMPOLINE OPENBLAS LLVM LIBSUITESPARSE OPENLIBM GMP MBEDTLS LIBSSH2 NGHTTP2 MPFR CURL LIBGIT2 PCRE LIBUV LIBUNWIND DSFMT OBJCONV ZLIB P7ZIP
1156+
BB_PROJECTS := BLASTRAMPOLINE OPENBLAS LLVM LIBSUITESPARSE OPENLIBM GMP MBEDTLS LIBSSH2 NGHTTP2 MPFR CURL LIBGIT2 PCRE LIBUV LIBUNWIND DSFMT OBJCONV ZLIB P7ZIP LLD
11551157
define SET_BB_DEFAULT
11561158
# First, check to see if BB is disabled on a global setting
11571159
ifeq ($$(USE_BINARYBUILDER),0)

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,9 @@ endif
306306
# Install `7z` into libexec/
307307
$(INSTALL_M) $(build_bindir)/7z$(EXE) $(DESTDIR)$(libexecdir)/
308308

309+
# Install `lld` into libexec/
310+
$(INSTALL_M) $(build_depsbindir)/lld$(EXE) $(DESTDIR)$(libexecdir)/
311+
309312
# Copy public headers
310313
cp -R -L $(build_includedir)/julia/* $(DESTDIR)$(includedir)/julia
311314
# Copy system image

base/Makefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,18 @@ $(build_bindir)/7z$(EXE):
195195
rm -f "$@" && \
196196
ln -svf "$(7Z_PATH)" "$@"
197197

198+
symlink_lld: $(build_bindir)/lld$(EXE)
199+
200+
ifneq ($(USE_SYSTEM_LLD),0)
201+
SYMLINK_SYSTEM_LIBRARIES += symlink_lld
202+
LLD_PATH := $(shell which lld$(EXE))
203+
endif
204+
205+
$(build_bindir)/lld$(EXE):
206+
[ -e "$(LLD_PATH)" ] && \
207+
rm -f "$@" && \
208+
ln -svf "$(LLD_PATH)" "$@"
209+
198210
# the following excludes: libuv.a, libutf8proc.a
199211

200212
ifneq ($(USE_SYSTEM_LIBM),0)

deps/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ ifeq ($(USE_SYSTEM_LLVM), 0)
8888
DEP_LIBS += llvm
8989
endif
9090

91+
ifeq ($(USE_SYSTEM_LLD), 0)
92+
DEP_LIBS += lld
93+
endif
94+
9195
ifeq ($(USE_SYSTEM_PCRE), 0)
9296
DEP_LIBS += pcre
9397
endif
@@ -168,7 +172,7 @@ endif
168172
DEP_LIBS_STAGED_ALL := llvm llvm-tools clang llvmunwind unwind libuv pcre \
169173
openlibm dsfmt blastrampoline openblas lapack gmp mpfr patchelf utf8proc \
170174
objconv mbedtls libssh2 nghttp2 curl libgit2 libwhich zlib p7zip csl \
171-
libsuitesparse
175+
libsuitesparse lld
172176
DEP_LIBS_ALL := $(DEP_LIBS_STAGED_ALL)
173177

174178
ifneq ($(USE_BINARYBUILDER_OPENBLAS),0)

deps/llvm.mk

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ endif
5656
ifeq ($(BUILD_LIBCXX), 1)
5757
LLVM_ENABLE_RUNTIMES := $(LLVM_ENABLE_RUNTIMES);libcxx;libcxxabi
5858
endif
59+
ifeq ($(BUILD_LLD), 1)
60+
LLVM_ENABLE_PROJECTS := $(LLVM_ENABLE_PROJECTS);lld
61+
endif
5962

6063

6164
LLVM_LIB_FILE := libLLVMCodeGen.a
@@ -309,6 +312,6 @@ $(eval $(call bb-install,clang,CLANG,false,true))
309312
$(eval $(call bb-install,lld,LLD,false,true))
310313
$(eval $(call bb-install,llvm-tools,LLVM_TOOLS,false,true))
311314

312-
install-lld install-clang install-llvm-tools: install-llvm
313-
314315
endif # USE_BINARYBUILDER_LLVM
316+
317+
install-lld install-clang install-llvm-tools: install-llvm

stdlib/LLD_jll/Project.toml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name = "LLD_jll"
2+
uuid = "d55e3150-da41-5e91-b323-ecfd1eec6109"
3+
version = "14.0.5+3"
4+
5+
[deps]
6+
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
7+
Zlib_jll = "83775a58-1f1d-513f-b197-d71354ab007a"
8+
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
9+
TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
10+
libLLVM_jll = "8f36deef-c2a5-5394-99ed-8e07531fb29a"
11+
Artifacts = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
12+
13+
[compat]
14+
julia = "1.9"
15+
libLLVM_jll = "14.0.5"
16+
17+
[extras]
18+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
19+
20+
[targets]
21+
test = ["Test"]

stdlib/LLD_jll/src/LLD_jll.jl

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
2+
# This file is a part of Julia. License is MIT: https://julialang.org/license
3+
4+
## dummy stub for https://github.com/JuliaBinaryWrappers/LLD_jll.jl
5+
6+
baremodule LLD_jll
7+
using Base, Libdl
8+
Base.Experimental.@compiler_options compile=min optimize=0 infer=false
9+
10+
const PATH_list = String[]
11+
const LIBPATH_list = String[]
12+
13+
export lld
14+
15+
# These get calculated in __init__()
16+
const PATH = Ref("")
17+
const LIBPATH = Ref("")
18+
artifact_dir = ""
19+
lld_path = ""
20+
if Sys.iswindows()
21+
const lld_exe = "lld.exe"
22+
else
23+
const lld_exe = "lld"
24+
end
25+
26+
if Sys.iswindows()
27+
const LIBPATH_env = "PATH"
28+
const LIBPATH_default = ""
29+
const pathsep = ';'
30+
elseif Sys.isapple()
31+
const LIBPATH_env = "DYLD_FALLBACK_LIBRARY_PATH"
32+
const LIBPATH_default = "~/lib:/usr/local/lib:/lib:/usr/lib"
33+
const pathsep = ':'
34+
else
35+
const LIBPATH_env = "LD_LIBRARY_PATH"
36+
const LIBPATH_default = ""
37+
const pathsep = ':'
38+
end
39+
40+
function adjust_ENV!(env::Dict, PATH::String, LIBPATH::String, adjust_PATH::Bool, adjust_LIBPATH::Bool)
41+
if adjust_LIBPATH
42+
LIBPATH_base = get(env, LIBPATH_env, expanduser(LIBPATH_default))
43+
if !isempty(LIBPATH_base)
44+
env[LIBPATH_env] = string(LIBPATH, pathsep, LIBPATH_base)
45+
else
46+
env[LIBPATH_env] = LIBPATH
47+
end
48+
end
49+
if adjust_PATH && (LIBPATH_env != "PATH" || !adjust_LIBPATH)
50+
if adjust_PATH
51+
if !isempty(get(env, "PATH", ""))
52+
env["PATH"] = string(PATH, pathsep, env["PATH"])
53+
else
54+
env["PATH"] = PATH
55+
end
56+
end
57+
end
58+
return env
59+
end
60+
61+
function lld(f::Function; adjust_PATH::Bool = true, adjust_LIBPATH::Bool = true)
62+
env = adjust_ENV!(copy(ENV), PATH[], LIBPATH[], adjust_PATH, adjust_LIBPATH)
63+
withenv(env...) do
64+
return f(lld_path)
65+
end
66+
end
67+
function lld(; adjust_PATH::Bool = true, adjust_LIBPATH::Bool = true)
68+
env = adjust_ENV!(copy(ENV), PATH[], LIBPATH[], adjust_PATH, adjust_LIBPATH)
69+
return Cmd(Cmd([lld_path]); env)
70+
end
71+
72+
function init_lld_path()
73+
# Prefer our own bundled lld, but if we don't have one, pick it up off of the PATH
74+
# If this is an in-tree build, `lld` will live in `tools`. Otherwise, it'll be in `libexec`
75+
for bundled_lld_path in (joinpath(Sys.BINDIR, Base.LIBEXECDIR, lld_exe),
76+
joinpath(Sys.BINDIR, "..", "tools", lld_exe),
77+
joinpath(Sys.BINDIR, lld_exe))
78+
if isfile(bundled_lld_path)
79+
global lld_path = abspath(bundled_lld_path)
80+
return
81+
end
82+
end
83+
global lld_path = something(Sys.which(lld_exe), lld_exe)
84+
end
85+
86+
function __init__()
87+
global artifact_dir = dirname(Sys.BINDIR)
88+
init_lld_path()
89+
PATH[] = dirname(lld_path)
90+
push!(PATH_list, PATH[])
91+
if Sys.iswindows()
92+
# On windows, the dynamic libraries (.dll) are in Sys.BINDIR ("usr\\bin")
93+
append!(LIBPATH_list, [joinpath(Sys.BINDIR, Base.LIBDIR, "julia"), Sys.BINDIR])
94+
else
95+
append!(LIBPATH_list, [joinpath(Sys.BINDIR, Base.LIBDIR, "julia"), joinpath(Sys.BINDIR, Base.LIBDIR)])
96+
end
97+
LIBPATH[] = join(LIBPATH_list, pathsep)
98+
end
99+
100+
# JLLWrappers API compatibility shims. Note that not all of these will really make sense.
101+
# For instance, `find_artifact_dir()` won't actually be the artifact directory, because
102+
# there isn't one. It instead returns the overall Julia prefix.
103+
is_available() = true
104+
find_artifact_dir() = artifact_dir
105+
dev_jll() = error("stdlib JLLs cannot be dev'ed")
106+
best_wrapper = nothing
107+
108+
end # module libLLD_jll

stdlib/LLD_jll/test/runtests.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# This file is a part of Julia. License is MIT: https://julialang.org/license
2+
3+
using Test, Libdl, LLD_jll
4+
5+
@testset "LLD_jll" begin
6+
@test isfile(LLD_jll.lld_path)
7+
flavor = Sys.isapple() ? "darwin" : (Sys.iswindows() ? "link" : "gnu")
8+
@test success(`$(LLD_jll.lld()) -flavor $flavor --version`)
9+
end

stdlib/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ $(build_datarootdir)/julia/stdlib/$(VERSDIR):
2020

2121
JLLS = DSFMT GMP CURL LIBGIT2 LLVM LIBSSH2 LIBUV MBEDTLS MPFR NGHTTP2 \
2222
BLASTRAMPOLINE OPENBLAS OPENLIBM P7ZIP PCRE LIBSUITESPARSE ZLIB \
23-
LLVMUNWIND CSL UNWIND
23+
LLVMUNWIND CSL UNWIND LLD
2424

2525
# Initialize this with JLLs that aren't in "deps/$(LibName).version"
2626
JLL_NAMES := MozillaCACerts_jll

0 commit comments

Comments
 (0)