From 0477944e71d837e76cbea86943d7ad8d2e4b5dc0 Mon Sep 17 00:00:00 2001 From: Michael Cho Date: Sat, 3 Aug 2024 14:26:55 -0400 Subject: [PATCH] shims/super/cc: pass `-ld_classic` if needed for `-dead_strip_dylibs` --- Library/Homebrew/extend/ENV/super.rb | 4 +++- Library/Homebrew/extend/os/mac/extend/ENV/super.rb | 4 ++++ Library/Homebrew/shims/super/cc | 6 ++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/extend/ENV/super.rb b/Library/Homebrew/extend/ENV/super.rb index b3629b790b..7a3677bd88 100644 --- a/Library/Homebrew/extend/ENV/super.rb +++ b/Library/Homebrew/extend/ENV/super.rb @@ -104,11 +104,13 @@ module Superenv # K - Don't strip -arch , -m32, or -m64 # d - Don't strip -march=. Use only in formulae that # have runtime detection of CPU features. - # w - Pass -no_weak_imports to the linker # D - Generate debugging information + # w - Pass `-no_weak_imports` to the linker # f - Pass `-no_fixup_chains` to `ld` whenever it # is invoked with `-undefined dynamic_lookup` # o - Pass `-oso_prefix` to `ld` whenever it is invoked + # c - Pass `-ld_classic` to `ld` whenever it is invoked + # with `-dead_strip_dylibs` # # These flags will also be present: # a - apply fix for apr-1-config path diff --git a/Library/Homebrew/extend/os/mac/extend/ENV/super.rb b/Library/Homebrew/extend/os/mac/extend/ENV/super.rb index 56a7f06ec1..c18a8e95c2 100644 --- a/Library/Homebrew/extend/os/mac/extend/ENV/super.rb +++ b/Library/Homebrew/extend/os/mac/extend/ENV/super.rb @@ -143,6 +143,10 @@ module Superenv # Strip build prefixes from linker where supported, for deterministic builds. append_to_cccfg "o" if DevelopmentTools.ld64_version >= 512 + + # Pass `-ld_classic` whenever the linker is invoked with `-dead_strip_dylibs` + # on `ld` versions that don't properly handle that option. + append_to_cccfg "c" if DevelopmentTools.ld64_version >= "1015.7" && DevelopmentTools.ld64_version <= "1022.1" end def no_weak_imports diff --git a/Library/Homebrew/shims/super/cc b/Library/Homebrew/shims/super/cc index 47761798c3..854e6cc065 100755 --- a/Library/Homebrew/shims/super/cc +++ b/Library/Homebrew/shims/super/cc @@ -324,11 +324,13 @@ class Cmd args << "-no_weak_imports" if no_weak_imports? args << "-no_fixup_chains" if no_fixup_chains? args << "-oso_prefix" << formula_buildpath if oso_prefix? && formula_buildpath + args << "-ld_classic" if ld_classic? when :ccld, :cxxld args << "-Wl,-headerpad_max_install_names" args << "-Wl,-no_weak_imports" if no_weak_imports? args << "-Wl,-no_fixup_chains" if no_fixup_chains? args << "-Wl,-oso_prefix,#{formula_buildpath}" if oso_prefix? && formula_buildpath + args << "-Wl,-ld_classic" if ld_classic? end args end @@ -441,6 +443,10 @@ class Cmd config.include?("o") && !configure? end + def ld_classic? + config.include?("c") && calls_ld? && @args.any? { |arg| arg.match?(/^(-Wl,)?-dead_strip_dylibs$/) } + end + def calls_ld? return true if mode == :ld return false unless [:ccld, :cxxld].include?(mode)