summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Hatle <mark.hatle@amd.com>2024-07-26 11:22:32 -0500
committerSteve Sakoman <steve@sakoman.com>2024-08-06 19:11:18 -0700
commit0d017528d4477172a34d7a805cf4888e642708d8 (patch)
tree6c1c2de7dab4e1ca1df94715918e1b6bbce05331
parent648d2617ba5538ee22ad8ac7dd33684ea6256c03 (diff)
downloadpoky-0d017528d4477172a34d7a805cf4888e642708d8.tar.gz
package.py: Fix static library processing
When PACKAGE_STRIP_STATIC is enabled the system did not pay attention to hardlinks. This could trigger a race condition during stripping of static libraries where multiple strips (through hardlinks) could run at the same time triggering a truncated or modified file error. The hardlink breaking code is based on the existing code for elf files, but due to the nature of the symlinks needed to be done in a separate block of code. Add support for static-library debugfs hardlinking through the existing inode processing code. Print a note to the logs if the link target can't be found. This isn't strictly an error, but may be useful for debugging an issue where a file isn't present. (From OE-Core rev: c2809691992dab48a360c9516d205ec031378cda) Signed-off-by: Mark Hatle <mark.hatle@amd.com> Signed-off-by: Mark Hatle <mark.hatle@kernel.crashing.org> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org> (cherry picked from commit ff371d69f60a1529ed456acb7d8e9305242e74bd) Signed-off-by: Mark Hatle <mark.hatle@kernel.crashing.org> Signed-off-by: Steve Sakoman <steve@sakoman.com>
-rw-r--r--meta/lib/oe/package.py56
1 files changed, 47 insertions, 9 deletions
diff --git a/meta/lib/oe/package.py b/meta/lib/oe/package.py
index ffe5a2157b..af0923a63f 100644
--- a/meta/lib/oe/package.py
+++ b/meta/lib/oe/package.py
@@ -1065,6 +1065,7 @@ def process_split_and_strip_files(d):
1065 d.getVar('INHIBIT_PACKAGE_DEBUG_SPLIT') != '1'): 1065 d.getVar('INHIBIT_PACKAGE_DEBUG_SPLIT') != '1'):
1066 checkelf = {} 1066 checkelf = {}
1067 checkelflinks = {} 1067 checkelflinks = {}
1068 checkstatic = {}
1068 for root, dirs, files in cpath.walk(dvar): 1069 for root, dirs, files in cpath.walk(dvar):
1069 for f in files: 1070 for f in files:
1070 file = os.path.join(root, f) 1071 file = os.path.join(root, f)
@@ -1078,10 +1079,6 @@ def process_split_and_strip_files(d):
1078 if file in skipfiles: 1079 if file in skipfiles:
1079 continue 1080 continue
1080 1081
1081 if oe.package.is_static_lib(file):
1082 staticlibs.append(file)
1083 continue
1084
1085 try: 1082 try:
1086 ltarget = cpath.realpath(file, dvar, False) 1083 ltarget = cpath.realpath(file, dvar, False)
1087 s = cpath.lstat(ltarget) 1084 s = cpath.lstat(ltarget)
@@ -1093,6 +1090,13 @@ def process_split_and_strip_files(d):
1093 continue 1090 continue
1094 if not s: 1091 if not s:
1095 continue 1092 continue
1093
1094 if oe.package.is_static_lib(file):
1095 # Use a reference of device ID and inode number to identify files
1096 file_reference = "%d_%d" % (s.st_dev, s.st_ino)
1097 checkstatic[file] = (file, file_reference)
1098 continue
1099
1096 # Check its an executable 1100 # Check its an executable
1097 if (s[stat.ST_MODE] & stat.S_IXUSR) or (s[stat.ST_MODE] & stat.S_IXGRP) \ 1101 if (s[stat.ST_MODE] & stat.S_IXUSR) or (s[stat.ST_MODE] & stat.S_IXGRP) \
1098 or (s[stat.ST_MODE] & stat.S_IXOTH) \ 1102 or (s[stat.ST_MODE] & stat.S_IXOTH) \
@@ -1157,6 +1161,27 @@ def process_split_and_strip_files(d):
1157 # Modified the file so clear the cache 1161 # Modified the file so clear the cache
1158 cpath.updatecache(file) 1162 cpath.updatecache(file)
1159 1163
1164 # Do the same hardlink processing as above, but for static libraries
1165 results = list(checkstatic.keys())
1166
1167 # As above, sort the results.
1168 results.sort(key=lambda x: x[0])
1169
1170 for file in results:
1171 # Use a reference of device ID and inode number to identify files
1172 file_reference = checkstatic[file][1]
1173 if file_reference in inodes:
1174 os.unlink(file)
1175 os.link(inodes[file_reference][0], file)
1176 inodes[file_reference].append(file)
1177 else:
1178 inodes[file_reference] = [file]
1179 # break hardlink
1180 bb.utils.break_hardlinks(file)
1181 staticlibs.append(file)
1182 # Modified the file so clear the cache
1183 cpath.updatecache(file)
1184
1160 def strip_pkgd_prefix(f): 1185 def strip_pkgd_prefix(f):
1161 nonlocal dvar 1186 nonlocal dvar
1162 1187
@@ -1195,11 +1220,24 @@ def process_split_and_strip_files(d):
1195 dest = dv["libdir"] + os.path.dirname(src) + dv["dir"] + "/" + os.path.basename(target) + dv["append"] 1220 dest = dv["libdir"] + os.path.dirname(src) + dv["dir"] + "/" + os.path.basename(target) + dv["append"]
1196 fpath = dvar + dest 1221 fpath = dvar + dest
1197 ftarget = dvar + dv["libdir"] + os.path.dirname(target) + dv["dir"] + "/" + os.path.basename(target) + dv["append"] 1222 ftarget = dvar + dv["libdir"] + os.path.dirname(target) + dv["dir"] + "/" + os.path.basename(target) + dv["append"]
1198 bb.utils.mkdirhier(os.path.dirname(fpath)) 1223 if os.access(ftarget, os.R_OK):
1199 # Only one hardlink of separated debug info file in each directory 1224 bb.utils.mkdirhier(os.path.dirname(fpath))
1200 if not os.access(fpath, os.R_OK): 1225 # Only one hardlink of separated debug info file in each directory
1201 #bb.note("Link %s -> %s" % (fpath, ftarget)) 1226 if not os.access(fpath, os.R_OK):
1202 os.link(ftarget, fpath) 1227 #bb.note("Link %s -> %s" % (fpath, ftarget))
1228 os.link(ftarget, fpath)
1229 elif (d.getVar('PACKAGE_DEBUG_STATIC_SPLIT') == '1'):
1230 deststatic = dv["staticlibdir"] + os.path.dirname(src) + dv["staticdir"] + "/" + os.path.basename(file) + dv["staticappend"]
1231 fpath = dvar + deststatic
1232 ftarget = dvar + dv["staticlibdir"] + os.path.dirname(target) + dv["staticdir"] + "/" + os.path.basename(target) + dv["staticappend"]
1233 if os.access(ftarget, os.R_OK):
1234 bb.utils.mkdirhier(os.path.dirname(fpath))
1235 # Only one hardlink of separated debug info file in each directory
1236 if not os.access(fpath, os.R_OK):
1237 #bb.note("Link %s -> %s" % (fpath, ftarget))
1238 os.link(ftarget, fpath)
1239 else:
1240 bb.note("Unable to find inode link target %s" % (target))
1203 1241
1204 # Create symlinks for all cases we were able to split symbols 1242 # Create symlinks for all cases we were able to split symbols
1205 for file in symlinks: 1243 for file in symlinks: