keg_relocate: relocate the interpreter for elf files with INTERP header (Linux)

Some elf files (e.g. created by rust compiler) have INTERP header despite
their magic header denotes shared object instead of executable.

We should relocate the interpreter elf files as long as they have INTERP header.

This should fix the broken bottles for rust based formulae.
This commit is contained in:
Cheng XU 2019-07-18 15:22:09 +08:00
parent 3ab93b6e2b
commit 2c82623318
No known key found for this signature in database
GPG Key ID: B19F15830AB4E690
2 changed files with 19 additions and 1 deletions

View File

@ -39,7 +39,7 @@ class Keg
new_rpath = rpath.join(":")
cmd = [patchelf, "--force-rpath", "--set-rpath", new_rpath]
if file.binary_executable?
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"
"#{new_prefix}/lib/ld.so"

View File

@ -68,6 +68,24 @@ module ELFShim
elf_type == :executable
end
def with_interpreter?
return @with_interpreter if defined? @with_interpreter
@with_interpreter = if binary_executable?
true
elsif dylib?
if which "readelf"
Utils.popen_read("readelf", "-l", to_path).include?(" INTERP ")
elsif which "file"
Utils.popen_read("file", "-L", "-b", to_path).include?(" interpreter ")
else
raise "Please install either readelf (from binutils) or file."
end
else
false
end
end
def dynamic_elf?
return @dynamic_elf if defined? @dynamic_elf