From c5e06a5b2fd924036faaee90078e3932c637b085 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mos=C3=A8=20Giordano?= Date: Sat, 3 Jul 2021 20:13:56 +0100 Subject: [PATCH] [Rootfs] Do not use old GCC versions with new LLVM for FreeBSD MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- Project.toml | 2 +- src/Rootfs.jl | 35 ++++++++++++++++++++++++----------- test/rootfs.jl | 9 +++++++++ 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/Project.toml b/Project.toml index 44b1e124..884b43b8 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "BinaryBuilderBase" uuid = "7f725544-6523-48cd-82d1-3fa08ff4056e" authors = ["Elliot Saba "] -version = "0.6.10" +version = "0.6.11" [deps] CodecZlib = "944b1d66-785c-5afd-91f1-9de20f533193" diff --git a/src/Rootfs.jl b/src/Rootfs.jl index a664801f..00f9097d 100644 --- a/src/Rootfs.jl +++ b/src/Rootfs.jl @@ -395,12 +395,14 @@ const available_llvm_builds = [ ] """ - gcc_version(p::AbstractPlatform, , GCC_builds::Vector{GCCBuild}) + gcc_version(p::AbstractPlatform, , GCC_builds::Vector{GCCBuild}; + llvm_version::Union{Nothing,VersionNumber}=nothing) Returns the closest matching GCC version number for the given particular platform, from the given set of options. The compiler ABI and the microarchitecture of the platform will be taken into account. If no match is -found, returns an empty list. +found, returns an empty list. If the keyword argument `llvm_version` is passed, +it is used to filter the version of GCC for FreeBSD platforms. This method assumes that the compiler ABI of the platform represents a platform 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 will return `4.8.5`, as binaries compiled with that version will run on this platform, whereas binaries compiled with `5.2.0` may not. """ -function gcc_version(p::AbstractPlatform, GCC_builds::Vector{GCCBuild}) +function gcc_version(p::AbstractPlatform, GCC_builds::Vector{GCCBuild}; + llvm_version::Union{Nothing,VersionNumber}=nothing) # First, filter by libgfortran version. if libgfortran_version(p) !== nothing 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}) GCC_builds = filter(b -> getversion(b) >= v"5", GCC_builds) end + # LLVMBootstrap 12 needs to be built with GCCBootstrap ≥ 7, see + # . + # 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, see + # . The solution is + # to not allow old GCCBootstrap with new versions of LLVMBootstrap for FreeBSD. + if llvm_version !== nothing && Sys.isfreebsd(p) && llvm_version ≥ v"12" + GCC_builds = filter(b -> getversion(b) ≥ v"6", GCC_builds) + end + # Filter the possible GCC versions depending on the microarchitecture if march(p) in ("avx", "avx2", "neonvfpv4") # "sandybridge", "haswell", "cortex-a53" introduced in GCC v4.9.0: @@ -467,20 +480,20 @@ function select_compiler_versions(p::AbstractPlatform, preferred_gcc_version::VersionNumber = getversion(GCC_builds[1]), preferred_llvm_version::VersionNumber = getversion(LLVM_builds[end]), ) - # Determine which GCC/LLVM build we're going to match with this Platform: - filtered_gcc_builds = gcc_version(p, GCC_builds) - if isempty(filtered_gcc_builds) - error("Impossible compiler constraints $(p) upon $(GCC_builds)!") - end - + # Determine which GCC/LLVM build we're going to match with this Platform. We need to + # pass the chosen version of LLVM to `gcc_version`, so we first select LLVM, then GCC. filtered_llvm_builds = llvm_version(p, LLVM_builds) if isempty(filtered_llvm_builds) error("Impossible compiler constraints $(p) upon $(LLVM_builds)!") end + llvmv = select_closest_version(preferred_llvm_version, filtered_llvm_builds) - # Otherwise, choose the version that is closest to our preferred version + filtered_gcc_builds = gcc_version(p, GCC_builds; llvm_version=llvmv) + if isempty(filtered_gcc_builds) + error("Impossible compiler constraints $(p) upon $(GCC_builds)!") + end gccv = select_closest_version(preferred_gcc_version, filtered_gcc_builds) - llvmv = select_closest_version(preferred_llvm_version, filtered_llvm_builds) + return gccv, llvmv end diff --git a/test/rootfs.jl b/test/rootfs.jl index 3a0d9c0d..831e7f7b 100644 --- a/test/rootfs.jl +++ b/test/rootfs.jl @@ -114,6 +114,15 @@ end # With no constraints, we should get them all back @test gcc_version(Platform("x86_64", "linux"), available_gcc_builds) == getversion.(available_gcc_builds) + # Filter for FreeBSD. No version of LLVM is specified, all versions + # should be available + @test gcc_version(Platform("x86_64", "freebsd"), available_gcc_builds) == getversion.(available_gcc_builds) + # With LLVM 11 all versions of GCC are still allowed + @test gcc_version(Platform("x86_64", "freebsd"), available_gcc_builds; llvm_version=v"11") == getversion.(available_gcc_builds) + # With LLVM 12 we can only use GCC 6+ + @test gcc_version(Platform("x86_64", "freebsd"), available_gcc_builds; llvm_version=v"12") == + filter(≥(v"6"), getversion.(available_gcc_builds)) + # libgfortran v3 and libstdcxx 22 restrict us to only v4.8, v5.2 and v6.1 p = Platform("x86_64", "linux"; libgfortran_version=v"3", libstdcxx_version=v"3.4.22") @test gcc_version(p, available_gcc_builds) == [v"4.8.5", v"5.2.0", v"6.1.0"]