Skip to content

Commit c422448

Browse files
giordanostaticfloat
authored andcommitted
[Rootfs] Do not use old GCC versions with new LLVM for FreeBSD
LLVMBootstrap 12 needs to be built with GCCBootstrap ≥ 7. However, when building for FreeBSD with LLVMBootstrap 12 we can't use `ld` from binutils < 2.26 (which corresponds to GCCBootstrap < 6) to link some object files. The solution is to not allow old GCCBootstrap with new versions of LLVMBootstrap for FreeBSD.
1 parent f9cd155 commit c422448

File tree

3 files changed

+34
-12
lines changed

3 files changed

+34
-12
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 <staticfloat@gmail.com>"]
4-
version = "0.6.10"
4+
version = "0.6.11"
55

66
[deps]
77
CodecZlib = "944b1d66-785c-5afd-91f1-9de20f533193"

src/Rootfs.jl

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -395,12 +395,14 @@ const available_llvm_builds = [
395395
]
396396

397397
"""
398-
gcc_version(p::AbstractPlatform, , GCC_builds::Vector{GCCBuild})
398+
gcc_version(p::AbstractPlatform, , GCC_builds::Vector{GCCBuild};
399+
llvm_version::Union{Nothing,VersionNumber}=nothing)
399400
400401
Returns the closest matching GCC version number for the given particular
401402
platform, from the given set of options. The compiler ABI and the
402403
microarchitecture of the platform will be taken into account. If no match is
403-
found, returns an empty list.
404+
found, returns an empty list. If the keyword argument `llvm_version` is passed,
405+
it is used to filter the version of GCC for FreeBSD platforms.
404406
405407
This method assumes that the compiler ABI of the platform represents a platform
406408
that binaries will be run on, and thus versions are always rounded down; e.g. if
@@ -409,7 +411,8 @@ the only GCC versions available to be picked from are `4.8.5` and `5.2.0`, it
409411
will return `4.8.5`, as binaries compiled with that version will run on this
410412
platform, whereas binaries compiled with `5.2.0` may not.
411413
"""
412-
function gcc_version(p::AbstractPlatform, GCC_builds::Vector{GCCBuild})
414+
function gcc_version(p::AbstractPlatform, GCC_builds::Vector{GCCBuild};
415+
llvm_version::Union{Nothing,VersionNumber}=nothing)
413416
# First, filter by libgfortran version.
414417
if libgfortran_version(p) !== nothing
415418
GCC_builds = filter(b -> getabi(b).libgfortran_version == libgfortran_version(p), GCC_builds)
@@ -432,6 +435,16 @@ function gcc_version(p::AbstractPlatform, GCC_builds::Vector{GCCBuild})
432435
GCC_builds = filter(b -> getversion(b) >= v"5", GCC_builds)
433436
end
434437

438+
# LLVMBootstrap 12 needs to be built with GCCBootstrap ≥ 7, see
439+
# <https://github.com/JuliaPackaging/BinaryBuilderBase.jl/pull/112#issuecomment-776940748>.
440+
# However, when building for FreeBSD with LLVMBootstrap 12 we can't use `ld` from
441+
# binutils < 2.26 (which corresponds to GCCBootstrap < 6) to link some object files, see
442+
# <https://github.com/JuliaPackaging/BinaryBuilderBase.jl/issues/158>. The solution is
443+
# to not allow old GCCBootstrap with new versions of LLVMBootstrap for FreeBSD.
444+
if llvm_version !== nothing && Sys.isfreebsd(p) && llvm_version v"12"
445+
GCC_builds = filter(b -> getversion(b) v"6", GCC_builds)
446+
end
447+
435448
# Filter the possible GCC versions depending on the microarchitecture
436449
if march(p) in ("avx", "avx2", "neonvfpv4")
437450
# "sandybridge", "haswell", "cortex-a53" introduced in GCC v4.9.0:
@@ -467,20 +480,20 @@ function select_compiler_versions(p::AbstractPlatform,
467480
preferred_gcc_version::VersionNumber = getversion(GCC_builds[1]),
468481
preferred_llvm_version::VersionNumber = getversion(LLVM_builds[end]),
469482
)
470-
# Determine which GCC/LLVM build we're going to match with this Platform:
471-
filtered_gcc_builds = gcc_version(p, GCC_builds)
472-
if isempty(filtered_gcc_builds)
473-
error("Impossible compiler constraints $(p) upon $(GCC_builds)!")
474-
end
475-
483+
# Determine which GCC/LLVM build we're going to match with this Platform. We need to
484+
# pass the chosen version of LLVM to `gcc_version`, so we first select LLVM, then GCC.
476485
filtered_llvm_builds = llvm_version(p, LLVM_builds)
477486
if isempty(filtered_llvm_builds)
478487
error("Impossible compiler constraints $(p) upon $(LLVM_builds)!")
479488
end
489+
llvmv = select_closest_version(preferred_llvm_version, filtered_llvm_builds)
480490

481-
# Otherwise, choose the version that is closest to our preferred version
491+
filtered_gcc_builds = gcc_version(p, GCC_builds; llvm_version=llvmv)
492+
if isempty(filtered_gcc_builds)
493+
error("Impossible compiler constraints $(p) upon $(GCC_builds)!")
494+
end
482495
gccv = select_closest_version(preferred_gcc_version, filtered_gcc_builds)
483-
llvmv = select_closest_version(preferred_llvm_version, filtered_llvm_builds)
496+
484497
return gccv, llvmv
485498
end
486499

test/rootfs.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,15 @@ end
114114
# With no constraints, we should get them all back
115115
@test gcc_version(Platform("x86_64", "linux"), available_gcc_builds) == getversion.(available_gcc_builds)
116116

117+
# Filter for FreeBSD. No version of LLVM is specified, all versions
118+
# should be available
119+
@test gcc_version(Platform("x86_64", "freebsd"), available_gcc_builds) == getversion.(available_gcc_builds)
120+
# With LLVM 11 all versions of GCC are still allowed
121+
@test gcc_version(Platform("x86_64", "freebsd"), available_gcc_builds; llvm_version=v"11") == getversion.(available_gcc_builds)
122+
# With LLVM 12 we can only use GCC 6+
123+
@test gcc_version(Platform("x86_64", "freebsd"), available_gcc_builds; llvm_version=v"12") ==
124+
filter((v"6"), getversion.(available_gcc_builds))
125+
117126
# libgfortran v3 and libstdcxx 22 restrict us to only v4.8, v5.2 and v6.1
118127
p = Platform("x86_64", "linux"; libgfortran_version=v"3", libstdcxx_version=v"3.4.22")
119128
@test gcc_version(p, available_gcc_builds) == [v"4.8.5", v"5.2.0", v"6.1.0"]

0 commit comments

Comments
 (0)