Skip to content

Commit ed7ddb9

Browse files
committed
Add creation of the build-id to the linker flags
1 parent 99594c5 commit ed7ddb9

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "BinaryBuilderBase"
22
uuid = "7f725544-6523-48cd-82d1-3fa08ff4056e"
33
authors = ["Elliot Saba <[email protected]>"]
4-
version = "1.39.1"
4+
version = "1.40.0"
55

66
[deps]
77
Bzip2_jll = "6e34b625-4abd-537c-b88f-471c36dfa7a0"

src/Runner.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,14 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
436436
end
437437
end
438438

439+
function buildid_link_flags!(p::AbstractPlatform, flags::Vector{String})
440+
# build-id is only supported in the ELF format, which is linux+FreeBSD
441+
if Sys.islinux(p) || Sys.isfreebsd(p)
442+
# Use a known algorithm to embed the build-id for reproducibility
443+
push!(flags, "-Wl,--build-id=sha1")
444+
end
445+
end
446+
439447
function clang_compile_flags!(p::AbstractPlatform, flags::Vector{String} = String[])
440448
if lock_microarchitecture
441449
append!(flags, get_march_flags(arch(p), march(p), "clang"))
@@ -540,6 +548,9 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
540548
append!(flags, min_macos_version_linker_flags())
541549
end
542550
end
551+
552+
buildid_link_flags!(p, flags)
553+
543554
return flags
544555
end
545556

@@ -630,6 +641,7 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
630641
push!(flags, "-Wl,--no-insert-timestamp")
631642
end
632643
sanitize_link_flags!(p, flags)
644+
buildid_link_flags!(p, flags)
633645
return flags
634646
end
635647

test/runners.jl

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,10 @@ end
130130
if lowercase(get(ENV, "BINARYBUILDER_FULL_SHARD_TEST", "false")) == "true"
131131
@info("Beginning full shard test... (this can take a while)")
132132
platforms = supported_platforms()
133+
elf_platforms = filter(p -> Sys.islinux(p) || Sys.isfreebsd(p), supported_platforms())
133134
else
134135
platforms = (default_host_platform,)
136+
elf_platforms = (default_host_platform,)
135137
end
136138

137139
# Checks that the wrappers provide the correct C++ string ABI
@@ -153,6 +155,40 @@ end
153155
end
154156
end
155157

158+
# Checks that the compiler/linker include a build-id
159+
# 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++")
161+
mktempdir() do dir
162+
ur = preferred_runner()(dir; platform=platform)
163+
iobuff = IOBuffer()
164+
test_c = """
165+
#include <stdlib.h>
166+
int test(void) {
167+
return 0;
168+
}
169+
"""
170+
test_script = """
171+
set -e
172+
# Make sure setting `CCACHE` doesn't affect the compiler wrappers.
173+
export CCACHE=pwned
174+
export USE_CCACHE=false
175+
echo '$(test_c)' > test.c
176+
# Build object file
177+
$(compiler) -Werror -c test.c -o test.o
178+
# Build shared library
179+
$(compiler) -Werror -shared test.c -o libtest.\${dlext}
180+
181+
# Print out the notes in the library
182+
readelf -n libtest.\${dlext}
183+
"""
184+
cmd = `/bin/bash -c "$(test_script)"`
185+
@test run(ur, cmd, iobuff)
186+
seekstart(iobuff)
187+
# Make sure the compiled library has the note section for the build-id
188+
@test occursin(r".note.gnu.build-id", readchomp(iobuff))
189+
end
190+
end
191+
156192
# This tests only that compilers for all platforms can build and link simple C code
157193
@testset "Compilation - $(platform) - $(compiler)" for platform in platforms, compiler in ("cc", "gcc", "clang")
158194
mktempdir() do dir

0 commit comments

Comments
 (0)