From 53fdb6411337ec322946b65a4800f965c09b6cd8 Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Tue, 2 Aug 2022 11:02:47 +0800 Subject: [PATCH 1/3] keg_relocate (linux): prepend `gcc/lib/current` to `RPATH` when needed This should help keep bottles that require GCC working when Homebrew/homebrew-core#106755 is merged. This only works on freshly-poured bottles. Previously installed bottles will still break on systems with a host GCC older than GCC 11. --- Library/Homebrew/extend/os/linux/keg_relocate.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/Library/Homebrew/extend/os/linux/keg_relocate.rb b/Library/Homebrew/extend/os/linux/keg_relocate.rb index ee1537910cdf5..69061c11991db 100644 --- a/Library/Homebrew/extend/os/linux/keg_relocate.rb +++ b/Library/Homebrew/extend/os/linux/keg_relocate.rb @@ -32,6 +32,7 @@ def change_rpath(file, old_prefix, new_prefix) lib_path = "#{new_prefix}/lib" rpath << lib_path unless rpath.include? lib_path + rpath.prepend HOMEBREW_PREFIX/"opt/gcc/lib/current" if rpath.any? { |rp| rp.match?(%r{lib/gcc/\d+$}) } rpath.join(":") end From 532460c098d7417a7477f7f54e790133880e8d26 Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Tue, 2 Aug 2022 13:29:14 +0800 Subject: [PATCH 2/3] keg_relocate: fix new GCC lib directory Also add comment explaining what this line does, along with a TODO suggesting a replacement once we've shipped the GCC PR. --- Library/Homebrew/extend/os/linux/keg_relocate.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/extend/os/linux/keg_relocate.rb b/Library/Homebrew/extend/os/linux/keg_relocate.rb index 69061c11991db..11a33e3cf524c 100644 --- a/Library/Homebrew/extend/os/linux/keg_relocate.rb +++ b/Library/Homebrew/extend/os/linux/keg_relocate.rb @@ -32,7 +32,13 @@ def change_rpath(file, old_prefix, new_prefix) lib_path = "#{new_prefix}/lib" rpath << lib_path unless rpath.include? lib_path - rpath.prepend HOMEBREW_PREFIX/"opt/gcc/lib/current" if rpath.any? { |rp| rp.match?(%r{lib/gcc/\d+$}) } + + # Add GCC's lib directory (as of GCC 12+) to RPATH when there is existing linkage. + # This fixes linkage for newly-poured bottles. + # TODO: Replace with + # rpath.map! { |path| path = path.sub(%r{lib/gcc/\d+$}, "lib/gcc/current") } + # when Homebrew/homebrew-core#106755 is merged. + rpath.prepend HOMEBREW_PREFIX/"opt/gcc/lib/gcc/current" if rpath.any? { |rp| rp.match?(%r{lib/gcc/\d+$}) } rpath.join(":") end From 1c0eac787403884172dcd76cc0638ac89c7cee55 Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Tue, 2 Aug 2022 19:09:38 +0800 Subject: [PATCH 3/3] Exclude GCC formulae from RPATH modification for GCC --- Library/Homebrew/extend/os/linux/keg_relocate.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/extend/os/linux/keg_relocate.rb b/Library/Homebrew/extend/os/linux/keg_relocate.rb index 11a33e3cf524c..7cc2f27be2169 100644 --- a/Library/Homebrew/extend/os/linux/keg_relocate.rb +++ b/Library/Homebrew/extend/os/linux/keg_relocate.rb @@ -35,10 +35,15 @@ def change_rpath(file, old_prefix, new_prefix) # Add GCC's lib directory (as of GCC 12+) to RPATH when there is existing linkage. # This fixes linkage for newly-poured bottles. - # TODO: Replace with - # rpath.map! { |path| path = path.sub(%r{lib/gcc/\d+$}, "lib/gcc/current") } - # when Homebrew/homebrew-core#106755 is merged. - rpath.prepend HOMEBREW_PREFIX/"opt/gcc/lib/gcc/current" if rpath.any? { |rp| rp.match?(%r{lib/gcc/\d+$}) } + if !name.match?(Version.formula_optionally_versioned_regex(:gcc)) && + rpath.any? { |rp| rp.match?(%r{lib/gcc/\d+$}) } + # TODO: Replace with + # rpath.map! { |path| path = path.sub(%r{lib/gcc/\d+$}, "lib/gcc/current") } + # when + # 1. Homebrew/homebrew-core#106755 is merged + # 2. No formula has a runtime dependency on a versioned GCC (see `envoy.rb`) + rpath.prepend HOMEBREW_PREFIX/"opt/gcc/lib/gcc/current" + end rpath.join(":") end