Skip to content

Commit

Permalink
os/mac/mach: avoid recursively resolving rpaths
Browse files Browse the repository at this point in the history
This is just a recipe for infinite loops. Plus, recursive references are
likely to be invalid, so we don't really gain much by attempting to
resolve them.[^1] (But we could if we made the logic here much more
complicated.)

Fixes a CI failure seen at Homebrew/homebrew-core#138323.

[^1]: See, for example, RenderKit/embree#455.
  • Loading branch information
carlocab authored and dduugg committed Sep 30, 2023
1 parent b54e6f7 commit d539ced
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Library/Homebrew/os/mac/mach.rb
Expand Up @@ -97,17 +97,18 @@ def dynamically_linked_libraries(except: :none, resolve_variable_references: tru

def rpaths(resolve_variable_references: true)
names = macho.rpaths
names.map!(&method(:resolve_variable_name)) if resolve_variable_references
# Don't recursively resolve rpaths to avoid infinite loops.
names.map! { |name| resolve_variable_name(name, resolve_rpaths: false) } if resolve_variable_references

names
end

def resolve_variable_name(name)
def resolve_variable_name(name, resolve_rpaths: true)
if name.start_with? "@loader_path"
Pathname(name.sub("@loader_path", dirname)).cleanpath.to_s
elsif name.start_with?("@executable_path") && binary_executable?
Pathname(name.sub("@executable_path", dirname)).cleanpath.to_s
elsif name.start_with?("@rpath") && (target = resolve_rpath(name)).present?
elsif resolve_rpaths && name.start_with?("@rpath") && (target = resolve_rpath(name)).present?
target
else
name
Expand Down

0 comments on commit d539ced

Please sign in to comment.