Skip to content
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
8 changes: 4 additions & 4 deletions lib/macho/macho_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,10 @@ def change_install_name(old_name, new_name, _options = {})
old_lc = dylib_load_commands.find { |d| d.name.to_s == old_name }
raise DylibUnknownError, old_name if old_lc.nil?

new_lc = LoadCommands::LoadCommand.create(old_lc.type, new_name,
old_lc.timestamp,
old_lc.current_version,
old_lc.compatibility_version)
args = [new_name, old_lc.timestamp, old_lc.current_version,
old_lc.compatibility_version]
args << old_lc.flags if old_lc.is_a?(LoadCommands::DylibUseCommand)
new_lc = LoadCommands::LoadCommand.create(old_lc.type, *args)

replace_command(old_lc, new_lc)
end
Expand Down
22 changes: 22 additions & 0 deletions test/test_macho.rb
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,28 @@ def test_change_install_name_preserves_type
assert_equal old_dylib_types, new_dylib_types
end

def test_change_install_name_preserves_dylib_use_flags
file = MachO::MachOFile.new(fixture(:x86_64, "dylib_use_command-weak-delay.bin"))
old_lc = file.dylib_load_commands.find do |lc|
lc.is_a?(MachO::LoadCommands::DylibUseCommand)
end

assert_equal 9, old_lc.flags
assert old_lc.flag?(:DYLIB_USE_WEAK_LINK)
assert old_lc.flag?(:DYLIB_USE_DELAYED_INIT)

file.change_install_name(old_lc.name.to_s, "new.dylib")

new_lc = file.dylib_load_commands.find { |lc| lc.name.to_s == "new.dylib" }
assert_instance_of MachO::LoadCommands::DylibUseCommand, new_lc
assert_equal old_lc.timestamp, new_lc.timestamp
assert_equal old_lc.current_version, new_lc.current_version
assert_equal old_lc.compatibility_version, new_lc.compatibility_version
assert_equal old_lc.flags, new_lc.flags
assert new_lc.flag?(:DYLIB_USE_WEAK_LINK)
assert new_lc.flag?(:DYLIB_USE_DELAYED_INIT)
end

def test_get_rpaths
filenames = SINGLE_ARCHES.map { |a| fixture(a, "hello.bin") }

Expand Down