deploy-ng: Add RPATH to search_path when parsing ELF files

This commit is contained in:
Mitchell Stokes 2017-11-21 14:57:15 -08:00
parent 3995ea4c3b
commit 54dad81646

View File

@ -428,7 +428,7 @@ class build_apps(distutils.core.Command):
elif magic == b'\x7FELF': elif magic == b'\x7FELF':
# Elf magic. Used on (among others) Linux and FreeBSD. # Elf magic. Used on (among others) Linux and FreeBSD.
deps = self._read_dependencies_elf(fp) deps = self._read_dependencies_elf(fp, os.path.dirname(source_path), search_path)
elif magic in (b'\xFE\xED\xFA\xCE', b'\xCE\xFA\xED\xFE', elif magic in (b'\xFE\xED\xFA\xCE', b'\xCE\xFA\xED\xFE',
b'\xFE\xED\xFA\xCF', b'\xCF\xFA\xED\xFE'): b'\xFE\xED\xFA\xCF', b'\xCF\xFA\xED\xFE'):
@ -448,7 +448,7 @@ class build_apps(distutils.core.Command):
for dep in deps: for dep in deps:
self.add_dependency(dep, target_dir, search_path, base) self.add_dependency(dep, target_dir, search_path, base)
def _read_dependencies_elf(self, elf): def _read_dependencies_elf(self, elf, origin, search_path):
""" Having read the first 4 bytes of the ELF file, fetches the """ Having read the first 4 bytes of the ELF file, fetches the
dependent libraries and returns those as a list. """ dependent libraries and returns those as a list. """
@ -499,13 +499,16 @@ class build_apps(distutils.core.Command):
elif tag == 15 or tag == 29: elif tag == 15 or tag == 29:
# An RPATH or RUNPATH entry. # An RPATH or RUNPATH entry.
string = string_tables[link][val : string_tables[link].find(b'\0', val)] string = string_tables[link][val : string_tables[link].find(b'\0', val)]
rpath += string.split(b':') rpath += [
os.path.normpath(i.decode('utf-8').replace('$ORIGIN', origin))
for i in string.split(b':')
]
data = elf.read(entsize) data = elf.read(entsize)
tag, val = struct.unpack_from(dynamic_struct, data) tag, val = struct.unpack_from(dynamic_struct, data)
elf.close() elf.close()
#TODO: should we respect the RPATH? Clear it? Warn about it? search_path += rpath
return needed return needed
def _read_dependencies_macho(self, fp): def _read_dependencies_macho(self, fp):