diff options
Diffstat (limited to 'meta/lib/oe/package.py')
-rw-r--r-- | meta/lib/oe/package.py | 73 |
1 files changed, 43 insertions, 30 deletions
diff --git a/meta/lib/oe/package.py b/meta/lib/oe/package.py index 8a303106a9..a435d661a6 100644 --- a/meta/lib/oe/package.py +++ b/meta/lib/oe/package.py | |||
@@ -1,8 +1,11 @@ | |||
1 | import mmap | ||
2 | import subprocess | ||
3 | |||
1 | def runstrip(arg): | 4 | def runstrip(arg): |
2 | # Function to strip a single file, called from split_and_strip_files below | 5 | # Function to strip a single file, called from split_and_strip_files below |
3 | # A working 'file' (one which works on the target architecture) | 6 | # A working 'file' (one which works on the target architecture) |
4 | # | 7 | # |
5 | # The elftype is a bit pattern (explained in split_and_strip_files) to tell | 8 | # The elftype is a bit pattern (explained in is_elf below) to tell |
6 | # us what type of file we're processing... | 9 | # us what type of file we're processing... |
7 | # 4 - executable | 10 | # 4 - executable |
8 | # 8 - shared library | 11 | # 8 - shared library |
@@ -44,6 +47,44 @@ def runstrip(arg): | |||
44 | 47 | ||
45 | return | 48 | return |
46 | 49 | ||
50 | # Detect .ko module by searching for "vermagic=" string | ||
51 | def is_kernel_module(path): | ||
52 | with open(path) as f: | ||
53 | return mmap.mmap(f.fileno(), 0, prot=mmap.PROT_READ).find(b"vermagic=") >= 0 | ||
54 | |||
55 | # Return type (bits): | ||
56 | # 0 - not elf | ||
57 | # 1 - ELF | ||
58 | # 2 - stripped | ||
59 | # 4 - executable | ||
60 | # 8 - shared library | ||
61 | # 16 - kernel module | ||
62 | def is_elf(path): | ||
63 | exec_type = 0 | ||
64 | result = subprocess.check_output(["file", "-b", path], stderr=subprocess.STDOUT).decode("utf-8") | ||
65 | |||
66 | if "ELF" in result: | ||
67 | exec_type |= 1 | ||
68 | if "not stripped" not in result: | ||
69 | exec_type |= 2 | ||
70 | if "executable" in result: | ||
71 | exec_type |= 4 | ||
72 | if "shared" in result: | ||
73 | exec_type |= 8 | ||
74 | if "relocatable" in result: | ||
75 | if path.endswith(".ko") and path.find("/lib/modules/") != -1 and is_kernel_module(path): | ||
76 | exec_type |= 16 | ||
77 | return exec_type | ||
78 | |||
79 | def is_static_lib(path): | ||
80 | if path.endswith('.a') and not os.path.islink(path): | ||
81 | with open(path, 'rb') as fh: | ||
82 | # The magic must include the first slash to avoid | ||
83 | # matching golang static libraries | ||
84 | magic = b'!<arch>\x0a/' | ||
85 | start = fh.read(len(magic)) | ||
86 | return start == magic | ||
87 | return False | ||
47 | 88 | ||
48 | def strip_execs(pn, dstdir, strip_cmd, libdir, base_libdir, qa_already_stripped=False): | 89 | def strip_execs(pn, dstdir, strip_cmd, libdir, base_libdir, qa_already_stripped=False): |
49 | """ | 90 | """ |
@@ -56,35 +97,7 @@ 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} | 97 | :param qa_already_stripped: Set to True if already-stripped' in ${INSANE_SKIP} |
57 | This is for proper logging and messages only. | 98 | This is for proper logging and messages only. |
58 | """ | 99 | """ |
59 | import stat, errno, oe.path, oe.utils, mmap, subprocess | 100 | import stat, errno, oe.path, oe.utils |
60 | |||
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 | ||
65 | |||
66 | # Return type (bits): | ||
67 | # 0 - not elf | ||
68 | # 1 - ELF | ||
69 | # 2 - stripped | ||
70 | # 4 - executable | ||
71 | # 8 - shared library | ||
72 | # 16 - kernel module | ||
73 | def is_elf(path): | ||
74 | exec_type = 0 | ||
75 | result = subprocess.check_output(["file", "-b", path], stderr=subprocess.STDOUT).decode("utf-8") | ||
76 | |||
77 | if "ELF" in result: | ||
78 | exec_type |= 1 | ||
79 | if "not stripped" not in result: | ||
80 | exec_type |= 2 | ||
81 | if "executable" in result: | ||
82 | exec_type |= 4 | ||
83 | if "shared" in result: | ||
84 | exec_type |= 8 | ||
85 | if "relocatable" in result and is_kernel_module(path): | ||
86 | exec_type |= 16 | ||
87 | return exec_type | ||
88 | 101 | ||
89 | elffiles = {} | 102 | elffiles = {} |
90 | inodes = {} | 103 | inodes = {} |