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