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

Fix deletion of duplicate rpaths #357

Merged
merged 2 commits into from
May 15, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 2 additions & 5 deletions lib/macho/macho_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -418,11 +418,8 @@ def delete_rpath(path, _options = {})
rpath_cmds = command(:LC_RPATH).select { |r| r.path.to_s == path }
raise RpathUnknownError, path if rpath_cmds.empty?

# delete the commands in reverse order, offset descending. this
# allows us to defer (expensive) field population until the very end
rpath_cmds.reverse_each { |cmd| delete_command(cmd, :repopulate => false) }

populate_fields
# delete the commands in reverse order, offset descending.
rpath_cmds.reverse_each { |cmd| delete_command(cmd) }
end

# Write all Mach-O data to the given filename.
Expand Down
Binary file added test/bin/x86_64/libdupe.dylib
Binary file not shown.
5 changes: 5 additions & 0 deletions test/test_macho.rb
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,10 @@ def test_delete_rpath
end
end

groups << ["libdupe.dylib", "libdupe_actual.dylib"].map do |fn|
fixture(:x86_64, fn)
end

groups.each do |filename, actual|
file = MachO::MachOFile.new(filename)

Expand All @@ -460,6 +464,7 @@ def test_delete_rpath
# ensure we can actually re-load and parse the modified file
modified = MachO::MachOFile.new(actual)

assert_empty modified.rpaths
assert_equal file.serialize.bytesize, modified.serialize.bytesize
assert_operator modified.ncmds, :<, orig_ncmds
assert_operator modified.sizeofcmds, :<, orig_sizeofcmds
Expand Down