Skip to content

Commit

Permalink
[Auditor] Do not skip GCC libraries when updating linkage (#1240)
Browse files Browse the repository at this point in the history
* [Auditor] Do not skip GCC libraries when updating linkage

* Fix expected SHAs of reproducible builds in tests

* Adapt other auditor tests
  • Loading branch information
giordano authored Oct 29, 2022
1 parent 23847ac commit 6d0e293
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 48 deletions.
29 changes: 1 addition & 28 deletions src/auditor/dynamic_linkage.jl
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,9 @@ function should_ignore_lib(lib, ::ELFHandle, platform::AbstractPlatform)
"libstdc++.so.6",
"libc++.so.1",
"libcxxrt.so.1",
# GCC libraries
# libc libraries
"libdl.so.2",
"librt.so.1",
"libgcc_s.1.so",
"libgcc_s.so.1",
"libm.so.5",
"libm.so.6",
"libthr.so.3",
Expand Down Expand Up @@ -313,31 +311,6 @@ end
# Determine whether a library is a "default" library or not, if it is we need
# to map it to `@rpath/$libname` on OSX or `\$ORIGIN/$libname` on Linux/FreeBSD
is_default_lib(lib, oh) = false
function is_default_lib(lib, ::MachOHandle)
default_libs = [
"libgcc_s.1.dylib",
"libgfortran.3.dylib",
"libgfortran.4.dylib",
"libgfortran.5.dylib",
"libquadmath.0.dylib",
"libgomp.1.dylib",
"libstdc++.6.dylib",
]
return lowercase(basename(lib)) in default_libs
end
function is_default_lib(lib, ::ELFHandle)
default_libs = [
"libgcc_s.so.1",
"libgfortran.so.3",
"libgfortran.so.4",
"libgfortran.so.5",
"libquadmath.so.0",
"libgomp.so.1",
"libstdc++.so.6",
"libc++.so.1",
]
return lowercase(basename(lib)) in default_libs
end

function valid_library_path(f::AbstractString, p::AbstractPlatform)
if Sys.iswindows(p)
Expand Down
64 changes: 59 additions & 5 deletions test/auditing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ end
make install
install_license /usr/share/licenses/libuv/LICENSE
"""
build_output_meta = do_build(build_path, script, platform, gcc_version)
build_output_meta = @test_logs (:info, "Building for $(triplet(platform))") (:warn, r"Linked library libgcc_s.so.1") match_mode=:any do_build(build_path, script, platform, gcc_version)
# Extract our platform's build
@test haskey(build_output_meta, platform)
tarball_path, tarball_hash = build_output_meta[platform][1:2]
Expand Down Expand Up @@ -470,7 +470,7 @@ end

mktempdir() do build_path
hello_world = ExecutableProduct("hello_world_fortran", :hello_world_fortran)
build_output_meta = @test_logs (:warn, r"CompilerSupportLibraries_jll") match_mode=:any begin
build_output_meta = @test_logs (:warn, r"CompilerSupportLibraries_jll") (:warn, r"Linked library libgfortran.so.5") (:warn, r"Linked library libquadmath.so.0") (:warn, r"Linked library libgcc_s.so.1") match_mode=:any begin
autobuild(
build_path,
"hello_fortran",
Expand All @@ -488,7 +488,9 @@ end
[platform],
#
Product[hello_world],
# No dependencies
# Note: we purposefully don't require CompilerSupportLibraries, even if we
# should, but the `@test_logs` above makes sure the audit warns us about
# this problem.
Dependency[];
)
end
Expand Down Expand Up @@ -518,14 +520,20 @@ end
@test_logs (:warn, r"links to libgfortran!") match_mode=:any begin
@test !Auditor.audit(Prefix(testdir); platform=BinaryBuilderBase.abi_agnostic(platform), autofix=false)
# Make sure audit is otherwise happy with the executable
@test Auditor.audit(Prefix(testdir); platform=platform, autofix=false)
# Note by Mosè: this test was introduced before
# https://github.com/JuliaPackaging/BinaryBuilder.jl/pull/1240 and relied on the
# fact audit was ok with not depending on CSL for packages needing GCC
# libraries, but that was a fallacious expectation. At the moment I don't know
# how to meaningfully use this test, leaving here as broken until we come up
# with better ideas (just remove the test?).
@test Auditor.audit(Prefix(testdir); platform=platform, autofix=false) broken=true
end

# Let's pretend that we're building for a different libgfortran version:
# audit should warn us.
libgfortran_versions = (3, 4, 5)
other_libgfortran_version = libgfortran_versions[findfirst(v -> v != our_libgfortran_version.major, libgfortran_versions)]
@test_logs (:warn, Regex("but we are supposedly building for libgfortran$(other_libgfortran_version)")) readmeta(hello_world_path) do oh
@test_logs (:warn, Regex("but we are supposedly building for libgfortran$(other_libgfortran_version)")) (:warn, r"Linked library libgfortran.so.5") (:warn, r"Linked library libquadmath.so.0") (:warn, r"Linked library libgcc_s.so.1") readmeta(hello_world_path) do oh
p = deepcopy(platform)
p["libgfortran_version"] = "$(other_libgfortran_version).0.0"
@test !Auditor.audit(Prefix(testdir); platform=p, autofix=false)
Expand Down Expand Up @@ -624,6 +632,52 @@ end
@test length(libfoo_rpaths) == 1 broken=Sys.isapple(platform)
end
end

@testset "GCC libraries" begin
platform = Platform("x86_64", "linux"; libc="glibc", libgfortran_version=v"5")
mktempdir() do build_path
build_output_meta = nothing
@test_logs (:info, "Building for $(triplet(platform))") match_mode=:any begin
build_output_meta = autobuild(
build_path,
"rpaths",
v"2.0.0",
# No sources
FileSource[],
# Build two libraries, `libbar` in `${libdir}/qux/` and `libfoo` in
# `${libdir}`, with the latter linking to the former.
raw"""
# Build fortran hello world
make -j${nproc} -sC /usr/share/testsuite/fortran/hello_world install
# Install fake license just to silence the warning
install_license /usr/share/licenses/libuv/LICENSE
""",
[platform],
# Ensure our library products are built
[ExecutableProduct("hello_world_fortran", :hello_world_fortran)],
# Dependencies: add CSL
[Dependency("CompilerSupportLibraries_jll")];
autofix=true,
)
end
# Extract our platform's build
@test haskey(build_output_meta, platform)
tarball_path, tarball_hash = build_output_meta[platform][1:2]
# Ensure the build products were created
@test isfile(tarball_path)
# Ensure reproducibility of build
@test build_output_meta[platform][3] == Base.SHA1("06ddfbeb9914a534ed3f21795b5da5b536d33c16")

# Unpack it somewhere else
@test verify(tarball_path, tarball_hash)
testdir = joinpath(build_path, "testdir")
mkdir(testdir)
unpack(tarball_path, testdir)
# Make sure auditor set the rpath of `hello_world`, even if it links only to
# libgfortran.
@test Auditor._rpaths(joinpath(testdir, "bin", "hello_world_fortran")) == ["\$ORIGIN/../lib"]
end
end
end

@testset "Auditor - execution permission" begin
Expand Down
30 changes: 15 additions & 15 deletions test/building.jl
Original file line number Diff line number Diff line change
Expand Up @@ -196,27 +196,27 @@ end
]
expected_git_shas = Dict(
v"4" => Dict(
x86_64_linux => Base.SHA1("6b705c0ff5760e236ab414fb9a366193f36d3e45"),
ppc64le_linux => Base.SHA1("2fa9900c01dc87dad914de469e662cacd9c48e01"),
armv7l_linux => Base.SHA1("192f05a64cc969cde17c026517166f98048ce27a"),
aarch64_linux => Base.SHA1("fb501d0fb03bbf8f034cff50d8d8a1b2956cdf1a"),
x86_64_macos => Base.SHA1("5a927c7c1b0c7813564bf47ec7ff287071ed5aae"),
x86_64_linux => Base.SHA1("fb3897274fe9b293eb6bfb65063895946e655114"),
ppc64le_linux => Base.SHA1("53a4e6c7e7d05bf245a8b794133b963bb1ebb1c2"),
armv7l_linux => Base.SHA1("28fc03c35a4d30da70fbdefc69ecc6b6bf93f2fb"),
aarch64_linux => Base.SHA1("c1c06efddc8bdce7b33fc9d8b6859f3c63e429ea"),
x86_64_macos => Base.SHA1("6d7c6812ed8d0deb69d47ae467ea4fee9f691e34"),
i686_windows => Base.SHA1("f39858ccc34a63a648cf21d33ae236bfdd706d09"),
),
v"5" => Dict(
x86_64_linux => Base.SHA1("ef9653f47abba2895b14c1086ba40ad8c64ac098"),
ppc64le_linux => Base.SHA1("b402ba20da0b800d37f69e1fbfe0e30c3b11a8db"),
armv7l_linux => Base.SHA1("b282db91a2c2a33485718d8e8a743b7f5c384719"),
aarch64_linux => Base.SHA1("ed873d488f47fb8bf5b4b89bb31ed1cad27ee27c"),
x86_64_macos => Base.SHA1("099b6a75d4f417c9f67c4da9218a56327086ec72"),
x86_64_linux => Base.SHA1("b202768af2c23d5ffa76df338eedeba10044c7f9"),
ppc64le_linux => Base.SHA1("b663282a6101647c0aa87043a632b6cdc08f761f"),
armv7l_linux => Base.SHA1("9a3273d5c7a41e7c2a5ab58b6b69db49a8533bc1"),
aarch64_linux => Base.SHA1("4bab3a85aceb3e589989f1a11a2f092c5038a6e0"),
x86_64_macos => Base.SHA1("86d45de929dfc89dd65cb6222287a1c1309f4d08"),
i686_windows => Base.SHA1("9390a3c24a8e274e6d7245c6c977f97b406bc3f5"),
),
v"6" => Dict(
x86_64_linux => Base.SHA1("b3829adf90f6521e4a05f20924506c8358247e06"),
ppc64le_linux => Base.SHA1("a12153a57fc6d8c415dc77161a39ed8ab01b16b2"),
armv7l_linux => Base.SHA1("a5c66513ca6a0348ca7b1e99412524fb1ee75e87"),
aarch64_linux => Base.SHA1("641031469413f4fa776c74310098b1b181796720"),
x86_64_macos => Base.SHA1("c01c6e840c4268123fbbd8703c8a153219752800"),
x86_64_linux => Base.SHA1("8917015bdd43c961da93b003d67ccd9dd5debd54"),
ppc64le_linux => Base.SHA1("97b7e5682b3cadc873644931b17894fa2ff05335"),
armv7l_linux => Base.SHA1("267b443b17b99ca2a14ea93d2afc2cce51cad05e"),
aarch64_linux => Base.SHA1("b396b1d94aba8642a68122a3515b26e4397217a0"),
x86_64_macos => Base.SHA1("b6216a106353f62e611579d88275f244b4923678"),
i686_windows => Base.SHA1("ae50af4ca8651cb3c8f71f34d0b66ca0d8f14a99"),
),
)
Expand Down

0 comments on commit 6d0e293

Please sign in to comment.