Merge pull request #7797 from rmNULL/interpreter-method-for-elfshim
Refactoring keg_relocate to use ELFShim#interpreter
This commit is contained in:
commit
b725d65e9e
@ -27,6 +27,7 @@ class Keg
|
||||
# patchelf requires that the ELF file have a .dynstr section.
|
||||
# Skip ELF files that do not have a .dynstr section.
|
||||
return if ["cannot find section .dynstr", "strange: no string table"].include?(old_rpath)
|
||||
|
||||
unless $CHILD_STATUS.success?
|
||||
raise ErrorDuringExecution.new(cmd_rpath, status: $CHILD_STATUS, output: [[:stderr, old_rpath]])
|
||||
end
|
||||
@ -41,15 +42,15 @@ class Keg
|
||||
new_rpath = rpath.join(":")
|
||||
cmd = [patchelf, "--force-rpath", "--set-rpath", new_rpath]
|
||||
|
||||
if file.with_interpreter?
|
||||
old_interpreter = Utils.safe_popen_read(patchelf, "--print-interpreter", file).strip
|
||||
new_interpreter = if File.readable? "#{new_prefix}/lib/ld.so"
|
||||
old_interpreter = file.interpreter
|
||||
new_interpreter = if old_interpreter.nil?
|
||||
nil
|
||||
elsif File.readable? "#{new_prefix}/lib/ld.so"
|
||||
"#{new_prefix}/lib/ld.so"
|
||||
else
|
||||
old_interpreter.sub old_prefix, new_prefix
|
||||
end
|
||||
cmd << "--set-interpreter" << new_interpreter if old_interpreter != new_interpreter
|
||||
end
|
||||
|
||||
return if old_rpath == new_rpath && old_interpreter == new_interpreter
|
||||
|
||||
|
@ -68,28 +68,24 @@ module ELFShim
|
||||
elf_type == :executable
|
||||
end
|
||||
|
||||
def with_interpreter?
|
||||
return @with_interpreter if defined? @with_interpreter
|
||||
def interpreter
|
||||
return @interpreter if defined? @interpreter
|
||||
|
||||
@with_interpreter = if binary_executable?
|
||||
true
|
||||
elsif dylib?
|
||||
if HOMEBREW_PATCHELF_RB
|
||||
@interpreter = if HOMEBREW_PATCHELF_RB
|
||||
begin
|
||||
patchelf_patcher.interpreter.present?
|
||||
patchelf_patcher.interpreter
|
||||
rescue PatchELF::PatchError => e
|
||||
opoo e unless e.to_s.start_with? "No interpreter found"
|
||||
false
|
||||
nil
|
||||
end
|
||||
elsif which "readelf"
|
||||
Utils.popen_read("readelf", "-l", to_path).include?(" INTERP ")
|
||||
elsif which "file"
|
||||
Utils.popen_read("file", "-L", "-b", to_path).include?(" interpreter ")
|
||||
elsif (patchelf = DevelopmentTools.locate "patchelf")
|
||||
interp = Utils.popen_read(patchelf, "--print-interpreter", to_s, err: :out).strip
|
||||
$CHILD_STATUS.success? ? interp : nil
|
||||
elsif (file = DevelopmentTools.locate("file"))
|
||||
output = Utils.popen_read(file, "-L", "-b", to_s, err: :out).strip
|
||||
output[/^ELF.*, interpreter (.+?), /, 1]
|
||||
else
|
||||
raise "Please install either readelf (from binutils) or file."
|
||||
end
|
||||
else
|
||||
false
|
||||
raise "Please install either patchelf or file."
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user