Skip to content

Commit bb1d736

Browse files
authored
[Runner] Fix build id with lld on windows (#443)
As discovered in JuliaPackaging/Yggdrasil#12004, `--build-id=sha1` doesn't seem to be supported with lld on windows. Also, to make reproducible set `-Wl,--no-insert-timestamp` when using clang (we already do this for gcc).
1 parent c72d925 commit bb1d736

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/Runner.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,9 +440,13 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
440440
# build-id is not supported on macOS compilers
441441
if !Sys.isapple(p)
442442
# Windows build-id requires binutils 2.25+, which we only have for GCC 5+
443-
if !Sys.iswindows(p) || (Sys.iswindows(p) && gcc_version v"5")
443+
if !Sys.iswindows(p) || (Sys.iswindows(p) && gcc_version v"5" && !clang_use_lld)
444444
# Use a known algorithm to embed the build-id for reproducibility
445445
push!(flags, "-Wl,--build-id=sha1")
446+
elseif Sys.iswindows(p) && clang_use_lld
447+
# This is reproducible as we set `-Wl,--no-insert-timestamp` elsewhere
448+
# See https://github.com/llvm/llvm-project/issues/74238#issuecomment-1839640836
449+
push!(flags, "-Wl,--build-id")
446450
end
447451
end
448452
end
@@ -550,6 +554,10 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
550554
# The `-sdk_version` flag is not implemented in lld yet.
551555
append!(flags, min_macos_version_linker_flags())
552556
end
557+
elseif Sys.iswindows(p) && gcc_version v"5"
558+
# Do not embed timestamps, for reproducibility:
559+
# https://github.com/JuliaPackaging/BinaryBuilder.jl/issues/1232
560+
push!(flags, "-Wl,--no-insert-timestamp")
553561
end
554562

555563
buildid_link_flags!(p, flags)

test/runners.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,9 @@ end
160160

161161
# Checks that the compiler/linker include a build-id
162162
# This is only available on ELF-based platforms
163-
@testset "Compilation - Linux build-id note $(platform) - $(compiler)" for platform in elf_platforms, compiler in ("cc", "gcc", "clang", "c++", "g++", "clang++")
163+
@testset "Compilation - Linux build-id note $(platform) - $(compiler) - clang_use_lld=$(clang_use_lld)" for platform in elf_platforms, compiler in ("cc", "gcc", "clang", "c++", "g++", "clang++"), clang_use_lld in (true, false)
164164
mktempdir() do dir
165-
ur = preferred_runner()(dir; platform=platform)
165+
ur = preferred_runner()(dir; platform=platform, clang_use_lld=clang_use_lld)
166166
iobuff = IOBuffer()
167167
test_c = """
168168
#include <stdlib.h>
@@ -196,10 +196,10 @@ end
196196
end
197197

198198
# Checks that Windows can include a build-id
199-
@testset "Compilation - Windows build-id note $(platform) - $(compiler)" for platform in win_platforms, compiler in ("cc", "gcc", "clang", "c++", "g++", "clang++")
199+
@testset "Compilation - Windows build-id note $(platform) - $(compiler) - clang_use_lld=$(clang_use_lld)" for platform in win_platforms, compiler in ("cc", "gcc", "clang", "c++", "g++", "clang++"), clang_use_lld in (true, false)
200200
mktempdir() do dir
201201
# Windows build-id support requires binutils 2.25, which is part of our GCC 5
202-
ur = preferred_runner()(dir; platform=platform, preferred_gcc_version=v"5")
202+
ur = preferred_runner()(dir; platform=platform, preferred_gcc_version=v"5", clang_use_lld=clang_use_lld)
203203
iobuff = IOBuffer()
204204
test_c = """
205205
#include <stdlib.h>

0 commit comments

Comments
 (0)