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

Revert "Binary patching of build prefixes " #13020

Merged
merged 1 commit into from
Mar 21, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 0 additions & 8 deletions Library/Homebrew/formula_installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1228,14 +1228,6 @@ def pour
keg = Keg.new(formula.prefix)
skip_linkage = formula.bottle_specification.skip_relocation?
keg.replace_placeholders_with_locations tab.changed_files, skip_linkage: skip_linkage

cellar = formula.bottle_specification.tag_to_cellar(Utils::Bottles.tag)
return if [:any, :any_skip_relocation].include?(cellar)

prefix = Pathname(cellar).parent.to_s
return if cellar == HOMEBREW_CELLAR.to_s && prefix == HOMEBREW_PREFIX.to_s

keg.relocate_build_prefix(keg, prefix, HOMEBREW_PREFIX)
end

sig { params(output: T.nilable(String)).void }
Expand Down
2 changes: 0 additions & 2 deletions Library/Homebrew/keg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -529,8 +529,6 @@ def binary_executable_or_library_files
elf_files
end

def codesign_patched_binary(_binary_file); end

private

def resolve_any_conflicts(dst, dry_run: false, verbose: false, overwrite: false)
Expand Down
39 changes: 0 additions & 39 deletions Library/Homebrew/keg_relocate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,45 +165,6 @@ def replace_text_in_files(relocation, files: nil)
changed_files
end

def relocate_build_prefix(keg, old_prefix, new_prefix)
each_unique_file_matching(old_prefix) do |file|
# Skip files which are not binary, as they do not need null padding.
next unless keg.binary_file?(file)

# Skip sharballs, which appear to break if patched.
next if file.text_executable?

# Split binary by null characters into array and substitute new prefix for old prefix.
# Null padding is added if the new string is too short.
file.ensure_writable do
binary = File.binread file
odebug "Replacing build prefix in: #{file}"
binary_strings = binary.split(/#{NULL_BYTE}/o, -1)
match_indices = binary_strings.each_index.select { |i| binary_strings[i].include?(old_prefix) }

# Only perform substitution on strings which match prefix regex.
match_indices.each do |i|
s = binary_strings[i]
binary_strings[i] = s.gsub(old_prefix, new_prefix)
.ljust(s.size, NULL_BYTE)
end

# Rejoin strings by null bytes.
patched_binary = binary_strings.join(NULL_BYTE)
if patched_binary.size != binary.size
raise <<~EOS
Patching failed! Original and patched binary sizes do not match.
Original size: #{binary.size}
Patched size: #{patched_binary.size}
EOS
end

file.atomic_write patched_binary
end
codesign_patched_binary(file)
end
end

def detect_cxx_stdlibs(_options = {})
[]
end
Expand Down
11 changes: 3 additions & 8 deletions Library/Homebrew/software_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,6 @@ def root_url(val = nil, specs = {})
end

class BottleSpecification
RELOCATABLE_CELLARS = [:any, :any_skip_relocation].freeze

extend T::Sig

attr_rw :rebuild
Expand Down Expand Up @@ -520,15 +518,12 @@ def tag_to_cellar(tag = Utils::Bottles.tag)
def compatible_locations?(tag: Utils::Bottles.tag)
cellar = tag_to_cellar(tag)

return true if RELOCATABLE_CELLARS.include?(cellar)
return true if [:any, :any_skip_relocation].include?(cellar)

prefix = Pathname(cellar).parent.to_s

cellar_relocatable = cellar.size >= HOMEBREW_CELLAR.to_s.size && ENV["HOMEBREW_RELOCATE_BUILD_PREFIX"]
prefix_relocatable = prefix.size >= HOMEBREW_PREFIX.to_s.size && ENV["HOMEBREW_RELOCATE_BUILD_PREFIX"]

compatible_cellar = cellar == HOMEBREW_CELLAR.to_s || cellar_relocatable
compatible_prefix = prefix == HOMEBREW_PREFIX.to_s || prefix_relocatable
compatible_cellar = cellar == HOMEBREW_CELLAR.to_s
compatible_prefix = prefix == HOMEBREW_PREFIX.to_s

compatible_cellar && compatible_prefix
end
Expand Down
44 changes: 0 additions & 44 deletions Library/Homebrew/test/keg_relocate/binary_relocation_spec.rb

This file was deleted.