os/mac/mach: avoid recursively resolving rpaths

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, embree/embree#455.
This commit is contained in:
Carlo Cabrera 2023-08-05 23:40:22 +08:00
parent b0da6e58c2
commit b5334b818c
No known key found for this signature in database
GPG Key ID: C74D447FC549A1D0

View File

@ -97,17 +97,18 @@ module MachOShim
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