From aa05c227a030076810f8bfa9b05ed0b593c14f9d Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Thu, 20 Jul 2023 21:49:18 +0800 Subject: [PATCH] os/mac/keg_relocate: avoid rpath re-ordering This should fix the failures seen for `julia` in Homebrew/core.[^1] I've detailed a better/more comprehensive fix as a `TODO` in a comments. However, the problems that the better fix would avoid are comparatively unlikely, so I think we can try this one out for now while I work on implementing the said fix. [^1]: https://github.com/Homebrew/homebrew-core/pull/135398#issuecomment-1643041541 --- Library/Homebrew/extend/os/mac/keg_relocate.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/extend/os/mac/keg_relocate.rb b/Library/Homebrew/extend/os/mac/keg_relocate.rb index 6ad9c06d08..1040651bae 100644 --- a/Library/Homebrew/extend/os/mac/keg_relocate.rb +++ b/Library/Homebrew/extend/os/mac/keg_relocate.rb @@ -57,7 +57,13 @@ class Keg each_linkage_for(file, :rpaths) do |bad_name| # Strip duplicate rpaths and rpaths rooted in the build directory. - if rooted_in_build_directory?(bad_name) || (file.rpaths.count(bad_name) > 1) + if rooted_in_build_directory?(bad_name) || + (file.rpaths(resolve_variable_references: false).count(bad_name) > 1) + # TODO: Drop the `resolve_variable_references` argument above (defaults to `true`) + # and fix `delete_rpath` so that it deletes the *last* LC_RPATH command + # (instead of the first one) to avoid changing LC_RPATH command ordering. + # NOTE: `delete_rpath` will also need to be able to handle rpaths that are different + # strings but resolve to the same location. delete_rpath(bad_name, file) else new_name = opt_name_for(bad_name)