Skip to content

Commit 71a1058

Browse files
committed
Restrict windows build-id generation to GCC 5+
1 parent a338b3d commit 71a1058

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

src/Runner.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,8 +439,11 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
439439
function buildid_link_flags!(p::AbstractPlatform, flags::Vector{String})
440440
# build-id is not supported on macOS compilers
441441
if !Sys.isapple(p)
442-
# Use a known algorithm to embed the build-id for reproducibility
443-
push!(flags, "-Wl,--build-id=sha1")
442+
# 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")
444+
# Use a known algorithm to embed the build-id for reproducibility
445+
push!(flags, "-Wl,--build-id=sha1")
446+
end
444447
end
445448
end
446449

test/runners.jl

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,11 @@ end
131131
@info("Beginning full shard test... (this can take a while)")
132132
platforms = supported_platforms()
133133
elf_platforms = filter(p -> Sys.islinux(p) || Sys.isfreebsd(p), supported_platforms())
134+
win_platforms = filter(p -> Sys.iswindows(p), supported_platforms())
134135
else
135136
platforms = (default_host_platform,)
136137
elf_platforms = (default_host_platform,)
138+
win_platforms = (Platform("x86_64", "windows"),)
137139
end
138140

139141
# Checks that the wrappers provide the correct C++ string ABI
@@ -157,7 +159,7 @@ end
157159

158160
# Checks that the compiler/linker include a build-id
159161
# This is only available on ELF-based platforms
160-
@testset "Compilation - build-id note $(platform) - $(compiler)" for platform in elf_platforms, compiler in ("cc", "gcc", "clang", "c++", "g++", "clang++")
162+
@testset "Compilation - Linux build-id note $(platform) - $(compiler)" for platform in elf_platforms, compiler in ("cc", "gcc", "clang", "c++", "g++", "clang++")
161163
mktempdir() do dir
162164
ur = preferred_runner()(dir; platform=platform)
163165
iobuff = IOBuffer()
@@ -187,6 +189,40 @@ end
187189
end
188190
end
189191

192+
# Checks that Windows can include a build-id
193+
@testset "Compilation - Windows build-id note $(platform) - $(compiler)" for platform in win_platforms, compiler in ("cc", "gcc", "clang", "c++", "g++", "clang++")
194+
mktempdir() do dir
195+
# Windows build-id support requires binutils 2.25, which is part of our GCC 5
196+
ur = preferred_runner()(dir; platform=platform, preferred_gcc_version=v"5")
197+
iobuff = IOBuffer()
198+
test_c = """
199+
#include <stdlib.h>
200+
int test(void) {
201+
return 0;
202+
}
203+
"""
204+
test_script = """
205+
set -e
206+
# We need readpe to get the information from the library
207+
apk add pev
208+
# Make sure setting `CCACHE` doesn't affect the compiler wrappers.
209+
export CCACHE=pwned
210+
export USE_CCACHE=false
211+
echo '$(test_c)' > test.c
212+
# Build shared library
213+
$(compiler) -shared test.c -o libtest.\${dlext}
214+
215+
# Print out the notes in the library
216+
readpe libtest.\${dlext}
217+
"""
218+
cmd = `/bin/bash -c "$(test_script)"`
219+
@test run(ur, cmd, iobuff)
220+
seekstart(iobuff)
221+
# Make sure the compiled library has the section for the build-id
222+
@test occursin(".buildid", readchomp(iobuff))
223+
end
224+
end
225+
190226
# This tests only that compilers for all platforms can build and link simple C code
191227
@testset "Compilation - $(platform) - $(compiler)" for platform in platforms, compiler in ("cc", "gcc", "clang")
192228
mktempdir() do dir

0 commit comments

Comments
 (0)