Skip to content

Commit 9a1a7b0

Browse files
authored
[Audit] Make sure we're linking to expected libgfortran version (#966)
Audit currently doesn't complain if there is a mismatch between the libgfortran version of the target platform and the one linked by the product.
1 parent 71097f0 commit 9a1a7b0

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

src/auditor/compiler_abi.jl

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ function check_libgfortran_version(oh::ObjectHandle, platform::AbstractPlatform;
4141
return true
4242
end
4343

44-
if verbose && version != nothing
44+
if verbose && version !== nothing
4545
@info("$(path(oh)) locks us to libgfortran v$(version)")
4646
end
4747

4848
if !has_csl && version !== nothing
4949
csl_warning("libgfortran")
5050
end
5151

52-
if libgfortran_version(platform) === nothing && version != nothing
52+
if libgfortran_version(platform) === nothing && version !== nothing
5353
msg = strip(replace("""
5454
$(path(oh)) links to libgfortran! This causes incompatibilities across
5555
major versions of GCC. To remedy this, you must build a tarball for
@@ -60,6 +60,16 @@ function check_libgfortran_version(oh::ObjectHandle, platform::AbstractPlatform;
6060
@warn(msg)
6161
return false
6262
end
63+
64+
if libgfortran_version(platform) !== nothing !== version && libgfortran_version(platform) != version
65+
msg = strip(replace("""
66+
$(path(oh)) links to libgfortran$(version.major), but we are supposedly building
67+
for libgfortran$(libgfortran_version(platform).major). This usually indicates that
68+
the build system is somehow ignoring our choice of compiler!
69+
""", '\n' => ' '))
70+
@warn(msg)
71+
return false
72+
end
6373
return true
6474
end
6575

test/auditing.jl

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,13 +450,25 @@ end
450450
# Attempt to run the executable, we expect it to work since it's our platform:
451451
hello_world_path = locate(hello_world, Prefix(testdir); platform=platform)
452452
with_libgfortran() do
453-
@test strip(String(read(`$hello_world_path`))) == "Hello, World!"
453+
@test readchomp(`$hello_world_path`) == "Hello, World!"
454454
end
455455

456456
# If we audit the testdir, pretending that we're trying to build an ABI-agnostic
457457
# tarball, make sure it warns us about it.
458458
@test_logs (:warn, r"links to libgfortran!") match_mode=:any begin
459-
Auditor.audit(Prefix(testdir); platform=BinaryBuilderBase.abi_agnostic(platform), autofix=false)
459+
@test !Auditor.audit(Prefix(testdir); platform=BinaryBuilderBase.abi_agnostic(platform), autofix=false)
460+
# Make sure audit is otherwise happy with the executable
461+
@test Auditor.audit(Prefix(testdir); platform=platform, autofix=false)
462+
end
463+
464+
# Let's pretend that we're building for a different libgfortran version:
465+
# audit should warn us.
466+
libgfortran_versions = (3, 4, 5)
467+
other_libgfortran_version = libgfortran_versions[findfirst(v -> v != our_libgfortran_version.major, libgfortran_versions)]
468+
@test_logs (:warn, Regex("but we are supposedly building for libgfortran$(other_libgfortran_version)")) readmeta(hello_world_path) do oh
469+
p = deepcopy(platform)
470+
p["libgfortran_version"] = "$(other_libgfortran_version).0.0"
471+
@test !Auditor.audit(Prefix(testdir); platform=p, autofix=false)
460472
end
461473
end
462474
end

0 commit comments

Comments
 (0)