Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore duplicate rpaths in #change_rpath #438

Merged
merged 2 commits into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions lib/macho/macho_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -381,11 +381,9 @@ def rpaths
# rpaths simultaneously.
# @return [void]
# @raise [RpathUnknownError] if no such old runtime path exists
# @raise [RpathExistsError] if the new runtime path already exists
def change_rpath(old_path, new_path, options = {})
old_lc = command(:LC_RPATH).find { |r| r.path.to_s == old_path }
raise RpathUnknownError, old_path if old_lc.nil?
raise RpathExistsError, new_path if rpaths.include?(new_path)

new_lc = LoadCommands::LoadCommand.create(:LC_RPATH, new_path)

Expand Down
12 changes: 8 additions & 4 deletions test/test_macho.rb
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,14 @@ def test_change_rpath
# there should be at least one rpath in each binary
refute_empty rpaths

# We should ignore errors when changing to an existing rpath
# This is the same behaviour as `install_name_tool`
file.change_rpath(rpaths.first, rpaths.first)
new_rpaths = file.rpaths

assert_equal new_rpaths.first, rpaths.first
refute_empty new_rpaths.first, rpaths.first

file.change_rpath(rpaths.first, "/usr/lib")
new_rpaths = file.rpaths

Expand Down Expand Up @@ -574,10 +582,6 @@ def test_rpath_exceptions
file.change_rpath("/this/rpath/doesn't/exist", "/lib")
end

assert_raises MachO::RpathExistsError do
file.change_rpath(file.rpaths.first, file.rpaths.first)
end

assert_raises MachO::RpathExistsError do
file.add_rpath(file.rpaths.first)
end
Expand Down