Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "BinaryBuilderBase"
uuid = "7f725544-6523-48cd-82d1-3fa08ff4056e"
authors = ["Elliot Saba <[email protected]>"]
version = "1.39.1"
version = "1.40.0"

[deps]
Bzip2_jll = "6e34b625-4abd-537c-b88f-471c36dfa7a0"
Expand Down
12 changes: 12 additions & 0 deletions src/Runner.jl
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,14 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
end
end

function buildid_link_flags!(p::AbstractPlatform, flags::Vector{String})
# build-id is only supported in the ELF format, which is linux+FreeBSD
if Sys.islinux(p) || Sys.isfreebsd(p)
# Use a known algorithm to embed the build-id for reproducibility
push!(flags, "-Wl,--build-id=sha1")
end
end

function clang_compile_flags!(p::AbstractPlatform, flags::Vector{String} = String[])
if lock_microarchitecture
append!(flags, get_march_flags(arch(p), march(p), "clang"))
Expand Down Expand Up @@ -540,6 +548,9 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
append!(flags, min_macos_version_linker_flags())
end
end

buildid_link_flags!(p, flags)

return flags
end

Expand Down Expand Up @@ -630,6 +641,7 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
push!(flags, "-Wl,--no-insert-timestamp")
end
sanitize_link_flags!(p, flags)
buildid_link_flags!(p, flags)
return flags
end

Expand Down
36 changes: 36 additions & 0 deletions test/runners.jl
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,10 @@ end
if lowercase(get(ENV, "BINARYBUILDER_FULL_SHARD_TEST", "false")) == "true"
@info("Beginning full shard test... (this can take a while)")
platforms = supported_platforms()
elf_platforms = filter(p -> Sys.islinux(p) || Sys.isfreebsd(p), supported_platforms())
else
platforms = (default_host_platform,)
elf_platforms = (default_host_platform,)
end

# Checks that the wrappers provide the correct C++ string ABI
Expand All @@ -153,6 +155,40 @@ end
end
end

# Checks that the compiler/linker include a build-id
# This is only available on ELF-based platforms
@testset "Compilation - build-id note $(platform) - $(compiler)" for platform in elf_platforms, compiler in ("cc", "gcc", "clang", "c++", "g++", "clang++")
mktempdir() do dir
ur = preferred_runner()(dir; platform=platform)
iobuff = IOBuffer()
test_c = """
#include <stdlib.h>
int test(void) {
return 0;
}
"""
test_script = """
set -e
# Make sure setting `CCACHE` doesn't affect the compiler wrappers.
export CCACHE=pwned
export USE_CCACHE=false
echo '$(test_c)' > test.c
# Build object file
$(compiler) -Werror -c test.c -o test.o
# Build shared library
$(compiler) -Werror -shared test.c -o libtest.\${dlext}

# Print out the notes in the library
readelf -n libtest.\${dlext}
"""
cmd = `/bin/bash -c "$(test_script)"`
@test run(ur, cmd, iobuff)
seekstart(iobuff)
# Make sure the compiled library has the note section for the build-id
@test occursin(r".note.gnu.build-id", readchomp(iobuff))
end
end

# This tests only that compilers for all platforms can build and link simple C code
@testset "Compilation - $(platform) - $(compiler)" for platform in platforms, compiler in ("cc", "gcc", "clang")
mktempdir() do dir
Expand Down
Loading