summaryrefslogtreecommitdiffstats
path: root/meta/lib
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:30:06 +0100
commit90c1e0da59e7919a511405063d4125d9629fcc2a (patch)
treef3d50f830740ab959ce165b4b798b5c07a7df681 /meta/lib
parentf46240c7ba1bb6dca421a9744bfb47c1bea44b74 (diff)
downloadpoky-90c1e0da59e7919a511405063d4125d9629fcc2a.tar.gz
package.py: strip_execs: Support for .ko modules
* Support stripping of .ko modules verifying file extension and check of content "vermagic=" (From OE-Core rev: 61a20502a8433729e2c25b8c718e6f93e3bb6614) Signed-off-by: Tobias Hagelborn <tobiasha@axis.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib')
-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=
56 :param qa_already_stripped: Set to True if already-stripped' in ${INSANE_SKIP} 56 :param qa_already_stripped: Set to True if already-stripped' in ${INSANE_SKIP}
57 This is for proper logging and messages only. 57 This is for proper logging and messages only.
58 """ 58 """
59 import stat, errno, oe.path, oe.utils 59 import stat, errno, oe.path, oe.utils, mmap
60 60
61 os.chdir(dstdir) 61 # Detect .ko module by searching for "vermagic=" string
62 def is_kernel_module(path):
63 with open(path) as f:
64 return mmap.mmap(f.fileno(), 0, prot=mmap.PROT_READ).find(b"vermagic=") >= 0
62 65
63 # Return type (bits): 66 # Return type (bits):
64 # 0 - not elf 67 # 0 - not elf
@@ -69,7 +72,8 @@ def strip_execs(pn, dstdir, strip_cmd, libdir, base_libdir, qa_already_stripped=
69 # 16 - kernel module 72 # 16 - kernel module
70 def is_elf(path): 73 def is_elf(path):
71 exec_type = 0 74 exec_type = 0
72 ret, result = oe.utils.getstatusoutput("file \"%s\"" % path.replace("\"", "\\\"")) 75 ret, result = oe.utils.getstatusoutput(
76 "file \"%s\"" % path.replace("\"", "\\\""))
73 77
74 if ret: 78 if ret:
75 bb.error("split_and_strip_files: 'file %s' failed" % path) 79 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=
83 exec_type |= 4 87 exec_type |= 4
84 if "shared" in result: 88 if "shared" in result:
85 exec_type |= 8 89 exec_type |= 8
90 if "relocatable" in result and is_kernel_module(path):
91 exec_type |= 16
86 return exec_type 92 return exec_type
87 93
88
89 elffiles = {} 94 elffiles = {}
90 inodes = {} 95 inodes = {}
91 libdir = os.path.abspath(dstdir + os.sep + libdir) 96 libdir = os.path.abspath(dstdir + os.sep + libdir)
92 base_libdir = os.path.abspath(dstdir + os.sep + base_libdir) 97 base_libdir = os.path.abspath(dstdir + os.sep + base_libdir)
93 98 exec_mask = stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH
94 # 99 #
95 # First lets figure out all of the files we may have to process 100 # First lets figure out all of the files we may have to process
96 # 101 #
@@ -110,8 +115,9 @@ def strip_execs(pn, dstdir, strip_cmd, libdir, base_libdir, qa_already_stripped=
110 if not s: 115 if not s:
111 continue 116 continue
112 # Check its an excutable 117 # Check its an excutable
113 if (s[stat.ST_MODE] & stat.S_IXUSR) or (s[stat.ST_MODE] & stat.S_IXGRP) or (s[stat.ST_MODE] & stat.S_IXOTH) \ 118 if s[stat.ST_MODE] & exec_mask \
114 or ((file.startswith(libdir) or file.startswith(base_libdir)) and ".so" in f): 119 or ((file.startswith(libdir) or file.startswith(base_libdir)) and ".so" in f) \
120 or file.endswith('.ko'):
115 # If it's a symlink, and points to an ELF file, we capture the readlink target 121 # If it's a symlink, and points to an ELF file, we capture the readlink target
116 if os.path.islink(file): 122 if os.path.islink(file):
117 continue 123 continue
@@ -131,8 +137,8 @@ def strip_execs(pn, dstdir, strip_cmd, libdir, base_libdir, qa_already_stripped=
131 os.unlink(file) 137 os.unlink(file)
132 os.link(inodes[s.st_ino], file) 138 os.link(inodes[s.st_ino], file)
133 else: 139 else:
140 # break hardlinks so that we do not strip the original.
134 inodes[s.st_ino] = file 141 inodes[s.st_ino] = file
135 # break hardlink
136 bb.utils.copyfile(file, file) 142 bb.utils.copyfile(file, file)
137 elffiles[file] = elf_file 143 elffiles[file] = elf_file
138 144
@@ -142,7 +148,6 @@ def strip_execs(pn, dstdir, strip_cmd, libdir, base_libdir, qa_already_stripped=
142 sfiles = [] 148 sfiles = []
143 for file in elffiles: 149 for file in elffiles:
144 elf_file = int(elffiles[file]) 150 elf_file = int(elffiles[file])
145 #bb.note("Strip %s" % file)
146 sfiles.append((file, elf_file, strip_cmd)) 151 sfiles.append((file, elf_file, strip_cmd))
147 152
148 oe.utils.multiprocess_exec(sfiles, runstrip) 153 oe.utils.multiprocess_exec(sfiles, runstrip)