From b7fc8d6969b2aa1c0d828d8755f3f020d4d5bece Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Thu, 24 Oct 2024 11:32:00 +0800 Subject: [PATCH] superenv: disable `ConstraintEliminationPass` on Xcode 16 This can result in build failures (e.g. OpenJDK) and silently miscompile some formulae (e.g. Vim). See Homebrew/homebrew-core#195325. --- Library/Homebrew/extend/ENV/super.rb | 1 + Library/Homebrew/extend/os/mac/extend/ENV/shared.rb | 12 ++++++++++++ Library/Homebrew/extend/os/mac/extend/ENV/std.rb | 4 ++++ Library/Homebrew/extend/os/mac/extend/ENV/super.rb | 7 +++++++ Library/Homebrew/shims/super/cc | 5 +++++ 5 files changed, 29 insertions(+) diff --git a/Library/Homebrew/extend/ENV/super.rb b/Library/Homebrew/extend/ENV/super.rb index c21bd3ce846f2..0820d9fbd50be 100644 --- a/Library/Homebrew/extend/ENV/super.rb +++ b/Library/Homebrew/extend/ENV/super.rb @@ -120,6 +120,7 @@ def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_a # o - Pass `-oso_prefix` to `ld` whenever it is invoked # c - Pass `-ld_classic` to `ld` whenever it is invoked # with `-dead_strip_dylibs` + # E - Pass `-mllvm -enable-constraint-elimination=0` to clang. # # These flags will also be present: # a - apply fix for apr-1-config path diff --git a/Library/Homebrew/extend/os/mac/extend/ENV/shared.rb b/Library/Homebrew/extend/os/mac/extend/ENV/shared.rb index 42a2cea1c7a1f..0687fb406a04b 100644 --- a/Library/Homebrew/extend/os/mac/extend/ENV/shared.rb +++ b/Library/Homebrew/extend/os/mac/extend/ENV/shared.rb @@ -39,4 +39,16 @@ def no_fixup_chains_support? # https://en.wikipedia.org/wiki/Xcode#Xcode_11.0_-_14.x_(since_SwiftUI_framework)_2 OS::Mac::DevelopmentTools.ld64_version >= 711 end + + # ConstraintEliminiationPass can silently miscompile some formulae. + # https://github.com/Homebrew/homebrew-core/issues/195325 + sig { returns(T::Boolean) } + def disable_contraint_elimination? + return false if compiler != :clang + + return false if !MacOS::Xcode.version.null? && MacOS::Xcode.version.major != 16 + return false if !MacOS::CLT.version.null? && MacOS::CLT.version.major != 16 + + true + end end diff --git a/Library/Homebrew/extend/os/mac/extend/ENV/std.rb b/Library/Homebrew/extend/os/mac/extend/ENV/std.rb index c312eb1125234..1125329ab0bd9 100644 --- a/Library/Homebrew/extend/os/mac/extend/ENV/std.rb +++ b/Library/Homebrew/extend/os/mac/extend/ENV/std.rb @@ -114,4 +114,8 @@ def no_weak_imports def no_fixup_chains append "LDFLAGS", "-Wl,-no_fixup_chains" if no_fixup_chains_support? end + + def disable_constraint_elimination_if_needed + append_to_cflags "-mllvm -enable-constraint-elimination=0" if disable_contraint_elimination? + end end diff --git a/Library/Homebrew/extend/os/mac/extend/ENV/super.rb b/Library/Homebrew/extend/os/mac/extend/ENV/super.rb index 940bb6e744646..f5114d9d4c349 100644 --- a/Library/Homebrew/extend/os/mac/extend/ENV/super.rb +++ b/Library/Homebrew/extend/os/mac/extend/ENV/super.rb @@ -159,6 +159,9 @@ def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_a if OS::Mac::DevelopmentTools.ld64_version >= "1015.7" && OS::Mac::DevelopmentTools.ld64_version <= "1022.1" append_to_cccfg "c" end + + # https://github.com/Homebrew/homebrew-core/issues/195325 + disable_constraint_elimination_if_needed end def no_weak_imports @@ -168,4 +171,8 @@ def no_weak_imports def no_fixup_chains append_to_cccfg "f" if no_fixup_chains_support? end + + def disable_constraint_elimination_if_needed + append_to_cccfg "E" if disable_contraint_elimination? + end end diff --git a/Library/Homebrew/shims/super/cc b/Library/Homebrew/shims/super/cc index 458a5dc236fa2..733e28c0ee6ba 100755 --- a/Library/Homebrew/shims/super/cc +++ b/Library/Homebrew/shims/super/cc @@ -299,6 +299,7 @@ class Cmd args.concat(archflags) args << "-std=#{@arg0}" if /c[89]9/.match?(@arg0) args << "-g" if debug_symbols? + args += ["-mllvm", "-enable-constraint-elimination=0"] if disable_contraint_elimination? args end @@ -435,6 +436,10 @@ class Cmd .flat_map { |arg| arg.delete_prefix("-Wl,").split(",") } end + def disable_contraint_elimination? + config.include?("E") + end + def no_fixup_chains? return false unless config.include?("f") return false unless calls_ld?