Skip to content

Commit 5eb2c69

Browse files
authored
Merge pull request #1031 from alebcay/dylib-use-command-flags
Preserve dylib use-command flags when renaming
2 parents 86da59b + 6528c5a commit 5eb2c69

2 files changed

Lines changed: 26 additions & 4 deletions

File tree

‎lib/macho/macho_file.rb‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -344,10 +344,10 @@ def change_install_name(old_name, new_name, _options = {})
344344
old_lc = dylib_load_commands.find { |d| d.name.to_s == old_name }
345345
raise DylibUnknownError, old_name if old_lc.nil?
346346

347-
new_lc = LoadCommands::LoadCommand.create(old_lc.type, new_name,
348-
old_lc.timestamp,
349-
old_lc.current_version,
350-
old_lc.compatibility_version)
347+
args = [new_name, old_lc.timestamp, old_lc.current_version,
348+
old_lc.compatibility_version]
349+
args << old_lc.flags if old_lc.is_a?(LoadCommands::DylibUseCommand)
350+
new_lc = LoadCommands::LoadCommand.create(old_lc.type, *args)
351351

352352
replace_command(old_lc, new_lc)
353353
end

‎test/test_macho.rb‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,28 @@ def test_change_install_name_preserves_type
552552
assert_equal old_dylib_types, new_dylib_types
553553
end
554554

555+
def test_change_install_name_preserves_dylib_use_flags
556+
file = MachO::MachOFile.new(fixture(:x86_64, "dylib_use_command-weak-delay.bin"))
557+
old_lc = file.dylib_load_commands.find do |lc|
558+
lc.is_a?(MachO::LoadCommands::DylibUseCommand)
559+
end
560+
561+
assert_equal 9, old_lc.flags
562+
assert old_lc.flag?(:DYLIB_USE_WEAK_LINK)
563+
assert old_lc.flag?(:DYLIB_USE_DELAYED_INIT)
564+
565+
file.change_install_name(old_lc.name.to_s, "new.dylib")
566+
567+
new_lc = file.dylib_load_commands.find { |lc| lc.name.to_s == "new.dylib" }
568+
assert_instance_of MachO::LoadCommands::DylibUseCommand, new_lc
569+
assert_equal old_lc.timestamp, new_lc.timestamp
570+
assert_equal old_lc.current_version, new_lc.current_version
571+
assert_equal old_lc.compatibility_version, new_lc.compatibility_version
572+
assert_equal old_lc.flags, new_lc.flags
573+
assert new_lc.flag?(:DYLIB_USE_WEAK_LINK)
574+
assert new_lc.flag?(:DYLIB_USE_DELAYED_INIT)
575+
end
576+
555577
def test_get_rpaths
556578
filenames = SINGLE_ARCHES.map { |a| fixture(a, "hello.bin") }
557579

0 commit comments

Comments
 (0)