Merge pull request #15769 from carlocab/resolve-rpath

os/mac/mach: resolve rpaths too
This commit is contained in:
Carlo Cabrera 2023-07-27 21:04:51 +08:00 committed by GitHub
commit 4c612ab324
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -89,18 +89,15 @@ module MachOShim
def dynamically_linked_libraries(except: :none, resolve_variable_references: true)
lcs = macho.dylib_load_commands.reject { |lc| lc.type == except }
names = lcs.map(&:name).map(&:to_s).uniq
names.map! { |name| resolve_variable_name(name) } if resolve_variable_references
names.map!(&method(:resolve_variable_name)) if resolve_variable_references
names
end
def rpaths(resolve_variable_references: true)
names = macho.rpaths
names.map! { |name| resolve_variable_name(name) } if resolve_variable_references
names.map!(&method(:resolve_variable_name)) if resolve_variable_references
names
end
@ -110,11 +107,22 @@ module MachOShim
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?
target
else
name
end
end
def resolve_rpath(name)
target = T.let(nil, T.nilable(String))
return unless rpaths(resolve_variable_references: true).find do |rpath|
File.exist?(target = File.join(rpath, name.delete_prefix("@rpath")))
end
target
end
def archs
mach_data.map { |m| m.fetch :arch }
end