Skip to content

Commit 8d1eca1

Browse files
gbaraldigiordano
andauthored
Default clang to use lld on specific conditions (#340)
* Default clang to use lld on specific conditions * Add test to check clang linker flags on non freebsd * Update src/Runner.jl Co-authored-by: Mosè Giordano <[email protected]> --------- Co-authored-by: Mosè Giordano <[email protected]>
1 parent b52b7a1 commit 8d1eca1

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

src/Runner.jl

+7-3
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
187187

188188
target = aatriplet(platform)
189189
host_target = aatriplet(host_platform)
190+
clang_use_lld = (!isnothing(gcc_version) && !isnothing(clang_version) && clang_version >= v"16" && gcc_version >= v"5")
190191

191192
function wrapper(io::IO,
192193
prog::String;
@@ -343,7 +344,7 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
343344
])
344345
end
345346
end
346-
if Sys.islinux(p) && !isnothing(gcc_version) && (clang_version >= v"16")
347+
if Sys.islinux(p) && !isnothing(gcc_version) !isnothing(clang_version) && (clang_version >= v"16")
347348
append!(flags, ["--gcc-install-dir=/opt/$(aatriplet(p))/lib/gcc/$(aatriplet(p))/$(gcc_version)"])
348349
end
349350
if Sys.iswindows(p)
@@ -409,6 +410,7 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
409410
append!(flags, get_march_flags(arch(p), march(p), "clang"))
410411
end
411412
if Sys.isapple(p)
413+
macos_version_flags = clang_use_lld ? (min_macos_version_flags()[1],) : min_macos_version_flags()
412414
append!(flags, String[
413415
# On MacOS, we need to override the typical C++ include search paths, because it always includes
414416
# the toolchain C++ headers first. Valentin tracked this down to:
@@ -421,7 +423,7 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
421423
# `clang` as a linker (and we have no real way to detect that in the wrapper), which will
422424
# cause `clang` to complain about compiler flags being passed in.
423425
"-Wno-unused-command-line-argument",
424-
min_macos_version_flags()...,
426+
macos_version_flags...,
425427
])
426428
end
427429
sanitize_compile_flags!(p, flags)
@@ -467,7 +469,9 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
467469
end
468470
# we want to use a particular linker with clang. But we want to avoid warnings about unused
469471
# flags when just compiling, so we put it into "linker-only flags".
470-
push!(flags, "-fuse-ld=$(aatriplet(p))")
472+
if !clang_use_lld
473+
push!(flags, "-fuse-ld=$(aatriplet(p))")
474+
end
471475

472476
sanitize_link_flags!(p, flags)
473477

test/rootfs.jl

+8-1
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,17 @@ end
223223
clang = read(joinpath(platform_bin_dir, "clang"), String)
224224
# Check link flags
225225
@test occursin("-L/opt/$(triplet(platform))/$(triplet(platform))/lib", clang)
226-
@test occursin("fuse-ld=$(triplet(platform))", clang)
227226
# Other compilers
228227
@test occursin("GOOS=\"freebsd\"", read(joinpath(platform_bin_dir, "go"), String))
229228
@test occursin("--target=x86_64-unknown-freebsd", read(joinpath(platform_bin_dir, "rustc"), String))
230229
end
230+
platform = Platform("x86_64", "linux"; libc="glibc", cxxstring_abi="cxx11")
231+
mktempdir() do bin_path
232+
platform_bin_dir = joinpath(bin_path, triplet(platform))
233+
generate_compiler_wrappers!(platform; bin_path = bin_path, compilers = [:c], gcc_version=v"5")
234+
clang = read(joinpath(platform_bin_dir, "clang"), String)
235+
# Check link flags
236+
@test occursin("-L/opt/$(aatriplet(platform))/lib/gcc/opt/$(aatriplet(platform))/lib/gcc", clang)
237+
end
231238
end
232239
end

test/runners.jl

+5
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ end
126126
# This tests only that compilers for all platforms can build and link simple C code
127127
@testset "Compilation - $(platform) - $(compiler)" for platform in platforms, compiler in ("cc", "gcc", "clang")
128128
mktempdir() do dir
129+
# if compiler == "clang"
130+
# ur = preferred_runner()(dir; platform=platform, preferred_gcc_version=v"5") #TODO: Fix CI disk size issues to allow this
131+
# else
132+
# ur = preferred_runner()(dir; platform=platform)
133+
# end
129134
ur = preferred_runner()(dir; platform=platform)
130135
iobuff = IOBuffer()
131136
test_c = """

0 commit comments

Comments
 (0)