aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Hagelborn <tobias.hagelborn@axis.com>2017-08-25 13:32:37 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-08-27 22:29:44 +0100
commit61a20502a8433729e2c25b8c718e6f93e3bb6614 (patch)
tree80fb0acd2f3a83605d6ce83e3ed31b23579af9cc
parentc72bd726d3e8495aae3e57f524c43b3be6367796 (diff)
downloadopenembedded-core-contrib-61a20502a8433729e2c25b8c718e6f93e3bb6614.tar.gz
package.py: strip_execs: Support for .ko modules
* Support stripping of .ko modules verifying file extension and check of content "vermagic=" Signed-off-by: Tobias Hagelborn <tobiasha@axis.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/lib/oe/package.py23
1 files changed, 14 insertions, 9 deletions
diff --git a/meta/lib/oe/package.py b/meta/lib/oe/package.py
index 839e9a25a0..fcee389aa2 100644
--- a/meta/lib/oe/package.py
+++ b/meta/lib/oe/package.py
@@ -56,9 +56,12 @@ def strip_execs(pn, dstdir, strip_cmd, libdir, base_libdir, qa_already_stripped=
:param qa_already_stripped: Set to True if already-stripped' in ${INSANE_SKIP}
This is for proper logging and messages only.
"""
- import stat, errno, oe.path, oe.utils
+ import stat, errno, oe.path, oe.utils, mmap
- os.chdir(dstdir)
+ # Detect .ko module by searching for "vermagic=" string
+ def is_kernel_module(path):
+ with open(path) as f:
+ return mmap.mmap(f.fileno(), 0, prot=mmap.PROT_READ).find(b"vermagic=") >= 0
# Return type (bits):
# 0 - not elf
@@ -69,7 +72,8 @@ def strip_execs(pn, dstdir, strip_cmd, libdir, base_libdir, qa_already_stripped=
# 16 - kernel module
def is_elf(path):
exec_type = 0
- ret, result = oe.utils.getstatusoutput("file \"%s\"" % path.replace("\"", "\\\""))
+ ret, result = oe.utils.getstatusoutput(
+ "file \"%s\"" % path.replace("\"", "\\\""))
if ret:
bb.error("split_and_strip_files: 'file %s' failed" % path)
@@ -83,14 +87,15 @@ def strip_execs(pn, dstdir, strip_cmd, libdir, base_libdir, qa_already_stripped=
exec_type |= 4
if "shared" in result:
exec_type |= 8
+ if "relocatable" in result and is_kernel_module(path):
+ exec_type |= 16
return exec_type
-
elffiles = {}
inodes = {}
libdir = os.path.abspath(dstdir + os.sep + libdir)
base_libdir = os.path.abspath(dstdir + os.sep + base_libdir)
-
+ exec_mask = stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH
#
# First lets figure out all of the files we may have to process
#
@@ -110,8 +115,9 @@ def strip_execs(pn, dstdir, strip_cmd, libdir, base_libdir, qa_already_stripped=
if not s:
continue
# Check its an excutable
- if (s[stat.ST_MODE] & stat.S_IXUSR) or (s[stat.ST_MODE] & stat.S_IXGRP) or (s[stat.ST_MODE] & stat.S_IXOTH) \
- or ((file.startswith(libdir) or file.startswith(base_libdir)) and ".so" in f):
+ if s[stat.ST_MODE] & exec_mask \
+ or ((file.startswith(libdir) or file.startswith(base_libdir)) and ".so" in f) \
+ or file.endswith('.ko'):
# If it's a symlink, and points to an ELF file, we capture the readlink target
if os.path.islink(file):
continue
@@ -131,8 +137,8 @@ def strip_execs(pn, dstdir, strip_cmd, libdir, base_libdir, qa_already_stripped=
os.unlink(file)
os.link(inodes[s.st_ino], file)
else:
+ # break hardlinks so that we do not strip the original.
inodes[s.st_ino] = file
- # break hardlink
bb.utils.copyfile(file, file)
elffiles[file] = elf_file
@@ -142,7 +148,6 @@ def strip_execs(pn, dstdir, strip_cmd, libdir, base_libdir, qa_already_stripped=
sfiles = []
for file in elffiles:
elf_file = int(elffiles[file])
- #bb.note("Strip %s" % file)
sfiles.append((file, elf_file, strip_cmd))
oe.utils.multiprocess_exec(sfiles, runstrip)