os/mac/{keg,mach}: fix cache invalidation

We were rewriting dylib IDs and install names using `MachO::Tools`,
which doesn't update the state of the file in memory. This leads to
those changes being undone when we call `delete_rpath`.

We fix this by making sure the state of the file in memory always
matches the state of file on disk.

Closes #12832.
This commit is contained in:
Carlo Cabrera 2022-02-11 23:05:02 +08:00
parent 1aa0897dc8
commit dee3638653
No known key found for this signature in database
GPG Key ID: C74D447FC549A1D0
2 changed files with 18 additions and 3 deletions

View File

@ -7,7 +7,7 @@ class Keg
@require_relocation = true @require_relocation = true
odebug "Changing dylib ID of #{file}\n from #{file.dylib_id}\n to #{id}" odebug "Changing dylib ID of #{file}\n from #{file.dylib_id}\n to #{id}"
MachO::Tools.change_dylib_id(file, id, strict: false) file.change_dylib_id(id, strict: false)
apply_ad_hoc_signature(file) apply_ad_hoc_signature(file)
rescue MachO::MachOError rescue MachO::MachOError
onoe <<~EOS onoe <<~EOS
@ -23,7 +23,7 @@ class Keg
@require_relocation = true @require_relocation = true
odebug "Changing install name in #{file}\n from #{old}\n to #{new}" odebug "Changing install name in #{file}\n from #{old}\n to #{new}"
MachO::Tools.change_install_name(file, old, new, strict: false) file.change_install_name(old, new, strict: false)
apply_ad_hoc_signature(file) apply_ad_hoc_signature(file)
rescue MachO::MachOError rescue MachO::MachOError
onoe <<~EOS onoe <<~EOS
@ -39,7 +39,7 @@ class Keg
@require_relocation = true @require_relocation = true
odebug "Changing rpath in #{file}\n from #{old}\n to #{new}" odebug "Changing rpath in #{file}\n from #{old}\n to #{new}"
MachO::Tools.change_rpath(file, old, new, strict: false) file.change_rpath(old, new, strict: false)
apply_ad_hoc_signature(file) apply_ad_hoc_signature(file)
rescue MachO::MachOError rescue MachO::MachOError
onoe <<~EOS onoe <<~EOS

View File

@ -64,6 +64,21 @@ module MachOShim
macho.write! macho.write!
end end
def change_rpath(old, new, **options)
macho.change_rpath(old, new, options)
macho.write!
end
def change_dylib_id(id, **options)
macho.change_dylib_id(id, options)
macho.write!
end
def change_install_name(old, new, **options)
macho.change_install_name(old, new, options)
macho.write!
end
def dynamically_linked_libraries(except: :none) def dynamically_linked_libraries(except: :none)
lcs = macho.dylib_load_commands.reject { |lc| lc.type == except } lcs = macho.dylib_load_commands.reject { |lc| lc.type == except }