Merge pull request #6303 from xu-cheng/rust-elf
keg_relocate: relocate the interpreter for elf files with INTERP header (Linux)
This commit is contained in:
commit
86e64cbb4e
@ -39,7 +39,7 @@ 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.binary_executable?
|
if file.with_interpreter?
|
||||||
old_interpreter = Utils.safe_popen_read(patchelf, "--print-interpreter", file).strip
|
old_interpreter = Utils.safe_popen_read(patchelf, "--print-interpreter", file).strip
|
||||||
new_interpreter = if File.readable? "#{new_prefix}/lib/ld.so"
|
new_interpreter = if File.readable? "#{new_prefix}/lib/ld.so"
|
||||||
"#{new_prefix}/lib/ld.so"
|
"#{new_prefix}/lib/ld.so"
|
||||||
|
|||||||
@ -68,10 +68,28 @@ module ELFShim
|
|||||||
elf_type == :executable
|
elf_type == :executable
|
||||||
end
|
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?
|
def dynamic_elf?
|
||||||
return @dynamic_elf if defined? @dynamic_elf
|
return @dynamic_elf if defined? @dynamic_elf
|
||||||
|
|
||||||
if which "readelf"
|
@dynamic_elf = if which "readelf"
|
||||||
Utils.popen_read("readelf", "-l", to_path).include?(" DYNAMIC ")
|
Utils.popen_read("readelf", "-l", to_path).include?(" DYNAMIC ")
|
||||||
elsif which "file"
|
elsif which "file"
|
||||||
!Utils.popen_read("file", "-L", "-b", to_path)[/dynamic|shared/].nil?
|
!Utils.popen_read("file", "-L", "-b", to_path)[/dynamic|shared/].nil?
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user