Skip to contentSkip to conversation

systemd: Improve detection of executables and libraries

PATCH Superseded Anusmita Dutta Mazumder 2 participants 3 messages Oct 27 – Oct 29

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 systemd: Improve detection of executables and libraries

Use cached mode bits to detect executables independently of host access permissions. Match shared-library basenames with a regex to avoid matching directory names.

---
 meta/recipes-core/systemd/dlopen-deps.inc | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
meta/recipes-core/systemd/dlopen-deps.inc +4 -2
index 37074a9682..4ce9845ad8 100644
@@ -3,7 +3,7 @@ PACKAGEFUNCS =+ "package_generate_dlopen_deps"
 python package_generate_dlopen_deps() {
     # https://systemd.io/ELF_DLOPEN_METADATA/
 
-    import os, struct, json
+    import os, struct, json, re
 
     def extract_segment(filename, segment):
         """
@@ -49,6 +49,7 @@ python package_generate_dlopen_deps() {
     }
 
     shlibs = oe.package.read_shlib_providers(d)
+    shlib_pattern = re.compile(r"\.so(\.|$)")
 
     for pkg, files in pkgfiles.items():
         # Skip -dbg packages as we won't need to generate dependencies for those
@@ -61,7 +62,8 @@ python package_generate_dlopen_deps() {
             if cpath.islink(f):
                 continue
 
-            if os.access(f, os.X_OK) or ".so." in f or f.endswith(".so"):
+            # Scan shared libraries and executable files for dlopen notes.
+            if shlib_pattern.search(os.path.basename(f)) or cpath.is_executable(f):
                 try:
                     elf = oe.qa.ELFFile(f)
                     elf.open()
#1 lore raw
Quoted 31 lines · Anusmita Dutta Mazumder

Use cached mode bits to detect executables independently of host access permissions. Match shared-library basenames with a regex to avoid matching directory names.

---
 meta/recipes-core/systemd/dlopen-deps.inc | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
meta/recipes-core/systemd/dlopen-deps.inc +2 -1
index 37074a9682..4ce9845ad8 100644
@@ -3,7 +3,7 @@ PACKAGEFUNCS =+ "package_generate_dlopen_deps"
 python package_generate_dlopen_deps() {
     # https://systemd.io/ELF_DLOPEN_METADATA/
 
-    import os, struct, json
+    import os, struct, json, re
 
     def extract_segment(filename, segment):
         """
@@ -49,6 +49,7 @@ python package_generate_dlopen_deps() {
     }
 
     shlibs = oe.package.read_shlib_providers(d)
+    shlib_pattern = re.compile(r"\.so(\.|$)")
 
     for pkg, files in pkgfiles.items():
         # Skip -dbg packages as we won't need to generate dependencies for those

meta/recipes-core/systemd/dlopen-deps.inc python package_generate_dlopen_deps() { · line 66

Quoted 6 lines
meta/recipes-core/systemd/dlopen-deps.inc +2 -1
@@ -61,7 +62,8 @@ python package_generate_dlopen_deps() {
             if cpath.islink(f):
                 continue
 
-            if os.access(f, os.X_OK) or ".so." in f or f.endswith(".so"):
+            # Scan shared libraries and executable files for dlopen notes.
+            if shlib_pattern.search(os.path.basename(f)) or cpath.is_executable(f):

Hi,

Thanks for the patch. The switch to is_executable() looks good, but the regex is more complex than the existing code. Could we use something like the following?

if cpath.is_executable(f) or ".so." in os.path.basename(f) or f.endswith(".so"):
...

Best regards,

Signature · 1 line
Paul Barker
#2 lore raw

Hi Paul,
Thank you for the suggestion. That looks simpler and keeps the intended behaviour. I’ll replace the regex with these checks and send a v2.

Regards,
Anusmita