summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPatrick Gartung <gartung@fnal.gov>2019-08-01 12:07:04 -0500
committerGitHub <noreply@github.com>2019-08-01 12:07:04 -0500
commit4ff14bd0b239bc6eabfd9d668b09d28699889f7b (patch)
treedb9eae86a731fc7a4654e49cd2d158c5b86cae26 /lib
parent8922c1f666731fb2dfd4d0643a23e0a38f45d1b9 (diff)
downloadspack-4ff14bd0b239bc6eabfd9d668b09d28699889f7b.tar.gz
spack-4ff14bd0b239bc6eabfd9d668b09d28699889f7b.tar.bz2
spack-4ff14bd0b239bc6eabfd9d668b09d28699889f7b.tar.xz
spack-4ff14bd0b239bc6eabfd9d668b09d28699889f7b.zip
Buildcache: skip binary string replacement with padding when the new install path is longer than the old install path. (#12227)
* Raise an exception and exit with a meaningful message when binary path substitution fails. * Skip binary text replacement with padding and issue a warning when the new install path is longer than the old install path.
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/relocate.py37
1 files changed, 32 insertions, 5 deletions
diff --git a/lib/spack/spack/relocate.py b/lib/spack/spack/relocate.py
index cbee103699..2a41682147 100644
--- a/lib/spack/spack/relocate.py
+++ b/lib/spack/spack/relocate.py
@@ -28,6 +28,19 @@ class InstallRootStringException(spack.error.SpackError):
(file_path, root_path))
+class BinaryStringReplacementException(spack.error.SpackError):
+ """
+ Raised when the size of the file changes after binary path substitution.
+ """
+
+ def __init__(self, file_path, old_len, new_len):
+ super(BinaryStringReplacementException, self).__init__(
+ "Doing a binary string replacement in %s failed.\n"
+ "The size of the file changed from %s to %s\n"
+ "when it should have remanined the same." %
+ (file_path, old_len, new_len))
+
+
def get_patchelf():
"""
Builds and installs spack patchelf package on linux platforms
@@ -308,8 +321,11 @@ def replace_prefix_bin(path_name, old_dir, new_dir):
f.seek(0)
original_data_len = len(data)
pat = re.compile(re.escape(old_dir) + b'([^\0]*?)\0')
- data = pat.sub(replace, data)
- assert(len(data) == original_data_len)
+ ndata = pat.sub(replace, data)
+ new_data_len = len(ndata)
+ if not new_data_len == original_data_len:
+ raise BinaryStringReplacementException(
+ path_name, original_data_len, new_data_len)
f.write(data)
f.truncate()
@@ -342,8 +358,13 @@ def relocate_binary(path_names, old_dir, new_dir, allow_root):
modify_macho_object(path_name,
rpaths, deps, idpath,
new_rpaths, new_deps, new_idpath)
- replace_prefix_bin(path_name, old_dir, new_dir)
-
+ if len(new_dir) <= len(old_dir):
+ replace_prefix_bin(path_name, old_dir, new_dir)
+ else:
+ tty.warn('Cannot do a binary string replacement'
+ ' with padding for %s'
+ ' because %s is longer than %s' %
+ (path_name, new_dir, old_dir))
elif platform.system() == 'Linux':
for path_name in path_names:
orig_rpaths = get_existing_elf_rpaths(path_name)
@@ -355,7 +376,13 @@ def relocate_binary(path_names, old_dir, new_dir, allow_root):
new_rpaths = substitute_rpath(n_rpaths,
old_dir, new_dir)
modify_elf_object(path_name, new_rpaths)
- replace_prefix_bin(path_name, old_dir, new_dir)
+ if len(new_dir) <= len(old_dir):
+ replace_prefix_bin(path_name, old_dir, new_dir)
+ else:
+ tty.warn('Cannot do a binary string replacement'
+ ' with padding for %s'
+ ' because %s is longer than %s.' %
+ (path_name, new_dir, old_dir))
else:
tty.die("Relocation not implemented for %s" % platform.system())