Allow binary relocation of strings in relative binaries (#13725)
Binaries with relative RPATHS currently do not relocate strings hard-coded in binaries This PR extends the best-effort relocation of strings hard-coded in binaries to those whose RPATHs have been relativized.
This commit is contained in:
parent
dc36b4737d
commit
43b0356e14
@ -536,7 +536,22 @@ def relocate_package(workdir, spec, allow_root):
|
|||||||
newprefix=new_prefix)
|
newprefix=new_prefix)
|
||||||
# If the binary files in the package were not edited to use
|
# If the binary files in the package were not edited to use
|
||||||
# relative RPATHs, then the RPATHs need to be relocated
|
# relative RPATHs, then the RPATHs need to be relocated
|
||||||
if not rel:
|
if rel:
|
||||||
|
if old_path != new_path:
|
||||||
|
files_to_relocate = list(filter(
|
||||||
|
lambda pathname: not relocate.file_is_relocatable(
|
||||||
|
pathname, paths_to_relocate=[old_path, old_prefix]),
|
||||||
|
map(lambda filename: os.path.join(workdir, filename),
|
||||||
|
buildinfo['relocate_binaries'])))
|
||||||
|
|
||||||
|
if len(old_path) < len(new_path) and files_to_relocate:
|
||||||
|
tty.debug('Cannot do a binary string replacement with padding '
|
||||||
|
'for package because %s is longer than %s.' %
|
||||||
|
(new_path, old_path))
|
||||||
|
else:
|
||||||
|
for path_name in files_to_relocate:
|
||||||
|
relocate.replace_prefix_bin(path_name, old_path, new_path)
|
||||||
|
else:
|
||||||
path_names = set()
|
path_names = set()
|
||||||
for filename in buildinfo['relocate_binaries']:
|
for filename in buildinfo['relocate_binaries']:
|
||||||
path_name = os.path.join(workdir, filename)
|
path_name = os.path.join(workdir, filename)
|
||||||
|
@ -651,7 +651,8 @@ def is_relocatable(spec):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def file_is_relocatable(file):
|
def file_is_relocatable(
|
||||||
|
file, paths_to_relocate=[spack.store.layout.root, spack.paths.prefix]):
|
||||||
"""Returns True if the file passed as argument is relocatable.
|
"""Returns True if the file passed as argument is relocatable.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -704,19 +705,13 @@ def file_is_relocatable(file):
|
|||||||
if idpath is not None:
|
if idpath is not None:
|
||||||
set_of_strings.discard(idpath)
|
set_of_strings.discard(idpath)
|
||||||
|
|
||||||
if any(spack.store.layout.root in x for x in set_of_strings):
|
for path_to_relocate in paths_to_relocate:
|
||||||
# One binary has the root folder not in the RPATH,
|
if any(path_to_relocate in x for x in set_of_strings):
|
||||||
# meaning that this spec is not relocatable
|
# One binary has the root folder not in the RPATH,
|
||||||
msg = 'Found "{0}" in {1} strings'
|
# meaning that this spec is not relocatable
|
||||||
tty.debug(msg.format(spack.store.layout.root, file))
|
msg = 'Found "{0}" in {1} strings'
|
||||||
return False
|
tty.debug(msg.format(path_to_relocate, file))
|
||||||
|
return False
|
||||||
if any(spack.paths.prefix in x for x in set_of_strings):
|
|
||||||
# One binary has the root folder not in the RPATH,
|
|
||||||
# meaning that this spec is not relocatable
|
|
||||||
msg = 'Found "{0}" in {1} strings'
|
|
||||||
tty.debug(msg.format(spack.paths.prefix, file))
|
|
||||||
return False
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user