157
157
allow_unsafe_flags::Bool = false,
158
158
lock_microarchitecture::Bool = true,
159
159
gcc_version::Union{Nothing,VersionNumber}=nothing,
160
- clang_version::Union{Nothing,VersionNumber}=nothing)
160
+ clang_version::Union{Nothing,VersionNumber}=nothing,
161
+ clang_use_lld::Bool = false,
162
+ )
161
163
162
164
We generate a set of compiler wrapper scripts within our build environment to force all
163
165
build systems to honor the necessary sets of compiler flags to build for our systems.
@@ -174,7 +176,8 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
174
176
lock_microarchitecture:: Bool = true ,
175
177
bootstrap:: Bool = ! isempty (bootstrap_list),
176
178
gcc_version:: Union{Nothing,VersionNumber} = nothing ,
177
- clang_version:: Union{Nothing,VersionNumber} = nothing
179
+ clang_version:: Union{Nothing,VersionNumber} = nothing ,
180
+ clang_use_lld:: Bool = false ,
178
181
)
179
182
# Wipe that directory out, in case it already had compiler wrappers
180
183
rm (bin_path; recursive= true , force= true )
@@ -187,7 +190,7 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
187
190
188
191
target = aatriplet (platform)
189
192
host_target = aatriplet (host_platform)
190
- clang_use_lld = ( ! isnothing (gcc_version) && ! isnothing (clang_version) && clang_version >= v " 16 " && gcc_version >= v " 5 " )
193
+
191
194
192
195
function wrapper (io:: IO ,
193
196
prog:: String ;
@@ -344,7 +347,7 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
344
347
])
345
348
end
346
349
end
347
- if Sys. islinux (p) && ! isnothing (gcc_version) ! isnothing (clang_version) && (clang_version >= v " 16" )
350
+ if Sys. islinux (p) && ! isnothing (gcc_version) && ! isnothing (clang_version) && (clang_version >= v " 16" )
348
351
append! (flags, [" --gcc-install-dir=/opt/$(aatriplet (p)) /lib/gcc/$(aatriplet (p)) /$(gcc_version) " ])
349
352
end
350
353
if Sys. iswindows (p)
@@ -469,10 +472,12 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
469
472
end
470
473
# we want to use a particular linker with clang. But we want to avoid warnings about unused
471
474
# flags when just compiling, so we put it into "linker-only flags".
472
- if ! clang_use_lld
475
+ if ! clang_use_lld # Clang with 16 or above is setup to use lld by default
473
476
push! (flags, " -fuse-ld=$(aatriplet (p)) " )
474
477
end
475
-
478
+ if Sys. isfreebsd (p) && clang_use_lld
479
+ push! (flags, " -L/opt/$(aatriplet (p)) /$(aatriplet (p)) /sys-root/usr/local/lib" )
480
+ end
476
481
sanitize_link_flags! (p, flags)
477
482
478
483
# On macos, we need to pass `-headerpad_max_install_names` so that we have lots of space
@@ -782,7 +787,13 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
782
787
"""
783
788
wrapper (io, string (" /opt/" , aatriplet (p), " /bin/" , string (aatriplet (p), " -dlltool" )); allow_ccache= false , extra_cmds= extra_cmds, hash_args= true )
784
789
end
785
-
790
+ function lld (io:: IO , p:: AbstractPlatform )
791
+ lld_str = Sys. isapple (p) ? " ld64.lld" : " ld.lld"
792
+ return wrapper (io,
793
+ " /opt/$(host_target) /bin/$(lld_str) " ;
794
+ env= Dict (" LD_LIBRARY_PATH" => ld_library_path (platform, host_platform; csl_paths= false )), allow_ccache= false ,
795
+ )
796
+ end
786
797
# Write out a bunch of common tools
787
798
for tool in (:cpp , :ld , :nm , :libtool , :objcopy , :objdump , :otool ,
788
799
:strip , :install_name_tool , :dlltool , :windres , :winmc , :lipo )
@@ -861,8 +872,10 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
861
872
# ld wrappers for clang's `-fuse-ld=$(target)`
862
873
if Sys. isapple (p)
863
874
write_wrapper (ld, p, " ld64.$(t) " )
875
+ write_wrapper (lld,p," ld64.lld" )
864
876
else
865
877
write_wrapper (ld, p, " ld.$(t) " )
878
+ write_wrapper (lld, p, " ld.lld" )
866
879
end
867
880
write_wrapper (nm, p, " $(t) -nm" )
868
881
write_wrapper (libtool, p, " $(t) -libtool" )
@@ -1330,17 +1343,18 @@ function runner_setup!(workspaces, mappings, workspace_root, verbose, kwargs, pl
1330
1343
1331
1344
clang = filter (s -> s. name == " LLVMBootstrap" , shards)
1332
1345
clang_version = length (clang) == 1 ? only (clang). version : nothing
1346
+ clang_use_lld = (! isnothing (gcc_version) && ! isnothing (clang_version) && clang_version >= v " 16" && gcc_version >= v " 6" )
1333
1347
# Construct environment variables we'll use from here on out
1334
1348
platform:: Platform = get_concrete_platform (platform; compilers... , extract_kwargs (kwargs, (:preferred_gcc_version ,:preferred_llvm_version ))... )
1335
1349
envs:: Dict{String,String} = merge (platform_envs (platform, src_name; rust_version, verbose, compilers... ), extra_env)
1336
1350
1337
1351
# JIT out some compiler wrappers, add it to our mounts
1338
- generate_compiler_wrappers! (platform; bin_path= compiler_wrapper_path, gcc_version, clang_version, compilers... , extract_kwargs (kwargs, (:allow_unsafe_flags ,:lock_microarchitecture ))... )
1352
+ generate_compiler_wrappers! (platform; bin_path= compiler_wrapper_path, gcc_version, clang_version, clang_use_lld, compilers... , extract_kwargs (kwargs, (:allow_unsafe_flags ,:lock_microarchitecture ))... )
1339
1353
push! (workspaces, compiler_wrapper_path => " /opt/bin" )
1340
1354
1341
1355
if isempty (bootstrap_list)
1342
1356
# Generate CMake and Meson files, only if we are not bootstrapping
1343
- generate_toolchain_files! (platform, envs, toolchains_path)
1357
+ generate_toolchain_files! (platform, envs, toolchains_path; clang_use_lld = clang_use_lld )
1344
1358
push! (workspaces, toolchains_path => " /opt/toolchains" )
1345
1359
1346
1360
# Generate directory where to write Cargo config files
0 commit comments