Skip to content

Commit

Permalink
superenv: disable ConstraintEliminationPass on Xcode 16
Browse files Browse the repository at this point in the history
This can result in build failures (e.g. OpenJDK) and silently miscompile
some formulae (e.g. Vim).

See Homebrew/homebrew-core#195325.
  • Loading branch information
carlocab committed Oct 24, 2024
1 parent e8ee210 commit b7fc8d6
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions Library/Homebrew/extend/ENV/super.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions Library/Homebrew/extend/os/mac/extend/ENV/shared.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions Library/Homebrew/extend/os/mac/extend/ENV/std.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions Library/Homebrew/extend/os/mac/extend/ENV/super.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
5 changes: 5 additions & 0 deletions Library/Homebrew/shims/super/cc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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?
Expand Down

0 comments on commit b7fc8d6

Please sign in to comment.