Skip to content

Commit 2181175

Browse files
gbaraldigiordano
andauthored
Fixup lld code even more and make sure gcc can use it (#350)
* Fixup lld code even more and make sure gcc can use it * Apply suggestions from code review Co-authored-by: Mosè Giordano <giordano@users.noreply.github.com> --------- Co-authored-by: Mosè Giordano <giordano@users.noreply.github.com>
1 parent fa22ac3 commit 2181175

File tree

3 files changed

+71
-8
lines changed

3 files changed

+71
-8
lines changed

src/BuildToolchains.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ function cmake_os(p::AbstractPlatform)
3131
end
3232
end
3333

34+
lld_str(p::AbstractPlatform) = Sys.isapple(p) ? "ld64.lld" : "ld.lld"
3435
function linker_string(p::AbstractPlatform, clang_use_lld)
3536
target = triplet(p)
3637
aatarget = aatriplet(p)
37-
lld_str = Sys.isapple(p) ? "ld64.lld" : "ld.lld"
38-
return clang_use_lld ? "/opt/bin/$(target)/$(lld_str)" : "/opt/bin/$(target)/$(aatarget)-ld"
38+
return clang_use_lld ? "/opt/bin/$(target)/$(lld_str(p))" : "/opt/bin/$(target)/$(aatarget)-ld"
3939
end
4040

4141
function toolchain_file(bt::CMake, p::AbstractPlatform, host_platform::AbstractPlatform; is_host::Bool=false, clang_use_lld::Bool=false)

src/Runner.jl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -787,10 +787,12 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
787787
"""
788788
wrapper(io, string("/opt/", aatriplet(p), "/bin/", string(aatriplet(p), "-dlltool")); allow_ccache=false, extra_cmds=extra_cmds, hash_args=true)
789789
end
790+
791+
lld_generic(io::IO, p::AbstractPlatform) =
792+
return wrapper(io, "/opt/$(host_target)/bin/lld"; env=Dict("LD_LIBRARY_PATH"=>ld_library_path(platform, host_platform; csl_paths=false)), allow_ccache=false,)
790793
function lld(io::IO, p::AbstractPlatform)
791-
lld_str = Sys.isapple(p) ? "ld64.lld" : "ld.lld"
792794
return wrapper(io,
793-
"/opt/$(host_target)/bin/$(lld_str)";
795+
"/opt/$(host_target)/bin/$(lld_str(p))";
794796
env=Dict("LD_LIBRARY_PATH"=>ld_library_path(platform, host_platform; csl_paths=false)), allow_ccache=false,
795797
)
796798
end
@@ -872,11 +874,11 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
872874
# ld wrappers for clang's `-fuse-ld=$(target)`
873875
if Sys.isapple(p)
874876
write_wrapper(ld, p, "ld64.$(t)")
875-
write_wrapper(lld,p,"ld64.lld")
876877
else
877878
write_wrapper(ld, p, "ld.$(t)")
878-
write_wrapper(lld, p, "ld.lld")
879879
end
880+
write_wrapper(lld,p,"$(t)-$(lld_str(p))")
881+
write_wrapper(lld_generic, p, "$(t)-lld")
880882
write_wrapper(nm, p, "$(t)-nm")
881883
write_wrapper(libtool, p, "$(t)-libtool")
882884
write_wrapper(objcopy, p, "$(t)-objcopy")
@@ -942,8 +944,7 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
942944
elseif Sys.iswindows(platform)
943945
append!(default_tools, ("dlltool", "windres", "winmc"))
944946
end
945-
946-
append!(default_tools, ("cc", "c++", "cpp", "f77", "gfortran", "gcc", "clang", "g++", "clang++"))
947+
append!(default_tools, ("cc", "c++", "cpp", "f77", "gfortran", "gcc", "clang", "g++", "clang++", "lld", lld_str(platform)))
947948
end
948949
if :rust in compilers
949950
append!(default_tools, ("rustc","rustup","cargo"))

test/runners.jl

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,68 @@ end
428428
@test contains(lines[end], r"^ +sdk 10\.14$")
429429
end
430430
end
431+
432+
@testset "Test lld usage" begin
433+
mktempdir() do dir
434+
ur = preferred_runner()(dir; platform=Platform("x86_64", "windows"), preferred_gcc_version=v"6")
435+
iobuff = IOBuffer()
436+
test_c = """
437+
#include <stdlib.h>
438+
int test(void) {
439+
return 0;
440+
}
441+
"""
442+
test_script = """
443+
set -e
444+
echo '$(test_c)' > test.c
445+
clang -Werror -shared test.c -o libtest.\${dlext}
446+
"""
447+
cmd = `/bin/bash -c "$(test_script)"`
448+
@test run(ur, cmd, iobuff)
449+
450+
test_script = """
451+
set -e
452+
echo '$(test_c)' > test.c
453+
clang -Werror -v -shared test.c -o libtest.\${dlext}
454+
"""
455+
iobuff = IOBuffer()
456+
cmd = `/bin/bash -c "$(test_script)"`
457+
@test run(ur, cmd, iobuff)
458+
seekstart(iobuff)
459+
@test occursin(r"ld.lld", readchomp(iobuff))
460+
end
461+
462+
mktempdir() do dir
463+
ur = preferred_runner()(dir; platform=Platform("x86_64", "linux", libc="musl"), preferred_gcc_version=v"9")
464+
iobuff = IOBuffer()
465+
test_c = """
466+
#include <stdlib.h>
467+
int test(void) {
468+
return 0;
469+
}
470+
"""
471+
test_script = """
472+
set -e
473+
echo '$(test_c)' > test.c
474+
gcc -Werror -shared test.c -fuse-ld=lld -o libtest.\${dlext}
475+
"""
476+
cmd = `/bin/bash -c "$(test_script)"`
477+
@test run(ur, cmd, iobuff)
478+
479+
test_script = """
480+
set -e
481+
echo '$(test_c)' > test.c
482+
gcc -Werror -v -shared test.c -fuse-ld=lld -o libtest.\${dlext}
483+
"""
484+
iobuff = IOBuffer()
485+
cmd = `/bin/bash -c "$(test_script)"`
486+
@test run(ur, cmd, iobuff)
487+
seekstart(iobuff)
488+
@test occursin(r"lld", readchomp(iobuff))
489+
end
490+
end
491+
492+
431493
end
432494

433495
@testset "Shards" begin

0 commit comments

Comments
 (0)