Skip to content
Snippets Groups Projects
Unverified Commit ab06303e authored by William Woodruff's avatar William Woodruff Committed by GitHub
Browse files

Merge pull request #5413 from woodruffw-forks/rewrite-rpaths-in-install-names

mac/keg_relocate: Rewrite rpaths in install names
parents 056da818 02216eed
No related branches found
No related tags found
No related merge requests found
......@@ -69,12 +69,32 @@ class Keg
new_name = fixed_name(file, bad_name)
change_install_name(bad_name, new_name, file) unless new_name == bad_name
end
# If none of the install names reference RPATH(s), then we can safely
# remove all RPATHs from the file.
if file.dynamically_linked_libraries.none? { |lib| lib.start_with?("@rpath") }
# Note: This could probably be made more efficient by reverse-sorting
# the RPATHs by offset and calling MachOFile#delete_command
# with repopulate: false.
file.rpaths.each { |r| file.delete_rpath(r) }
end
end
end
generic_fix_dynamic_linkage
end
def expand_rpath(file, bad_name)
suffix = bad_name.sub(/^@rpath/, "")
file.rpaths.each do |rpath|
return rpath/suffix if (rpath/suffix).exist?
end
opoo "Could not find library #{bad_name} for #{file}"
bad_name
end
# If file is a dylib or bundle itself, look for the dylib named by
# bad_name relative to the lib directory, so that we can skip the more
# expensive recursive search if possible.
......@@ -87,6 +107,8 @@ class Keg
"@loader_path/#{bad_name}"
elsif file.mach_o_executable? && (lib + bad_name).exist?
"#{lib}/#{bad_name}"
elsif bad_name.start_with?("@rpath") && ENV["HOMEBREW_RELOCATE_METAVARS"]
expand_rpath file, bad_name
elsif (abs_name = find_dylib(bad_name)) && abs_name.exist?
abs_name.to_s
else
......@@ -97,7 +119,7 @@ class Keg
def each_install_name_for(file, &block)
dylibs = file.dynamically_linked_libraries
dylibs.reject! { |fn| fn =~ /^@(loader_|executable_|r)path/ }
dylibs.reject! { |fn| fn =~ /^@(loader|executable)_path/ }
dylibs.each(&block)
end
......
......@@ -2,6 +2,10 @@ require "macho"
require "os/mac/architecture_list"
module MachOShim
extend Forwardable
delegate [:dylib_id, :rpaths, :delete_rpath] => :macho
# @private
def macho
@macho ||= begin
......@@ -56,10 +60,6 @@ module MachOShim
lcs.map(&:name).map(&:to_s).uniq
end
def dylib_id
macho.dylib_id
end
def archs
mach_data.map { |m| m.fetch :arch }.extend(ArchitectureListExtension)
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment