Skip to content

Commit

Permalink
Fixup lld code even more and make sure gcc can use it (#350)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
gbaraldi and giordano authored Nov 10, 2023
1 parent fa22ac3 commit 2181175
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/BuildToolchains.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ function cmake_os(p::AbstractPlatform)
end
end

lld_str(p::AbstractPlatform) = Sys.isapple(p) ? "ld64.lld" : "ld.lld"
function linker_string(p::AbstractPlatform, clang_use_lld)
target = triplet(p)
aatarget = aatriplet(p)
lld_str = Sys.isapple(p) ? "ld64.lld" : "ld.lld"
return clang_use_lld ? "/opt/bin/$(target)/$(lld_str)" : "/opt/bin/$(target)/$(aatarget)-ld"
return clang_use_lld ? "/opt/bin/$(target)/$(lld_str(p))" : "/opt/bin/$(target)/$(aatarget)-ld"
end

function toolchain_file(bt::CMake, p::AbstractPlatform, host_platform::AbstractPlatform; is_host::Bool=false, clang_use_lld::Bool=false)
Expand Down
13 changes: 7 additions & 6 deletions src/Runner.jl
Original file line number Diff line number Diff line change
Expand Up @@ -787,10 +787,12 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
"""
wrapper(io, string("/opt/", aatriplet(p), "/bin/", string(aatriplet(p), "-dlltool")); allow_ccache=false, extra_cmds=extra_cmds, hash_args=true)
end

lld_generic(io::IO, p::AbstractPlatform) =
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,)
function lld(io::IO, p::AbstractPlatform)
lld_str = Sys.isapple(p) ? "ld64.lld" : "ld.lld"
return wrapper(io,
"/opt/$(host_target)/bin/$(lld_str)";
"/opt/$(host_target)/bin/$(lld_str(p))";
env=Dict("LD_LIBRARY_PATH"=>ld_library_path(platform, host_platform; csl_paths=false)), allow_ccache=false,
)
end
Expand Down Expand Up @@ -872,11 +874,11 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
# ld wrappers for clang's `-fuse-ld=$(target)`
if Sys.isapple(p)
write_wrapper(ld, p, "ld64.$(t)")
write_wrapper(lld,p,"ld64.lld")
else
write_wrapper(ld, p, "ld.$(t)")
write_wrapper(lld, p, "ld.lld")
end
write_wrapper(lld,p,"$(t)-$(lld_str(p))")
write_wrapper(lld_generic, p, "$(t)-lld")
write_wrapper(nm, p, "$(t)-nm")
write_wrapper(libtool, p, "$(t)-libtool")
write_wrapper(objcopy, p, "$(t)-objcopy")
Expand Down Expand Up @@ -942,8 +944,7 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
elseif Sys.iswindows(platform)
append!(default_tools, ("dlltool", "windres", "winmc"))
end

append!(default_tools, ("cc", "c++", "cpp", "f77", "gfortran", "gcc", "clang", "g++", "clang++"))
append!(default_tools, ("cc", "c++", "cpp", "f77", "gfortran", "gcc", "clang", "g++", "clang++", "lld", lld_str(platform)))
end
if :rust in compilers
append!(default_tools, ("rustc","rustup","cargo"))
Expand Down
62 changes: 62 additions & 0 deletions test/runners.jl
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,68 @@ end
@test contains(lines[end], r"^ +sdk 10\.14$")
end
end

@testset "Test lld usage" begin
mktempdir() do dir
ur = preferred_runner()(dir; platform=Platform("x86_64", "windows"), preferred_gcc_version=v"6")
iobuff = IOBuffer()
test_c = """
#include <stdlib.h>
int test(void) {
return 0;
}
"""
test_script = """
set -e
echo '$(test_c)' > test.c
clang -Werror -shared test.c -o libtest.\${dlext}
"""
cmd = `/bin/bash -c "$(test_script)"`
@test run(ur, cmd, iobuff)

test_script = """
set -e
echo '$(test_c)' > test.c
clang -Werror -v -shared test.c -o libtest.\${dlext}
"""
iobuff = IOBuffer()
cmd = `/bin/bash -c "$(test_script)"`
@test run(ur, cmd, iobuff)
seekstart(iobuff)
@test occursin(r"ld.lld", readchomp(iobuff))
end

mktempdir() do dir
ur = preferred_runner()(dir; platform=Platform("x86_64", "linux", libc="musl"), preferred_gcc_version=v"9")
iobuff = IOBuffer()
test_c = """
#include <stdlib.h>
int test(void) {
return 0;
}
"""
test_script = """
set -e
echo '$(test_c)' > test.c
gcc -Werror -shared test.c -fuse-ld=lld -o libtest.\${dlext}
"""
cmd = `/bin/bash -c "$(test_script)"`
@test run(ur, cmd, iobuff)

test_script = """
set -e
echo '$(test_c)' > test.c
gcc -Werror -v -shared test.c -fuse-ld=lld -o libtest.\${dlext}
"""
iobuff = IOBuffer()
cmd = `/bin/bash -c "$(test_script)"`
@test run(ur, cmd, iobuff)
seekstart(iobuff)
@test occursin(r"lld", readchomp(iobuff))
end
end


end

@testset "Shards" begin
Expand Down

0 comments on commit 2181175

Please sign in to comment.