]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
systemd: handle llvm-objcopy behaviour when reading .note.dlopen section
authorRoss Burton <ross.burton@arm.com>
Fri, 22 Nov 2024 11:07:13 +0000 (11:07 +0000)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Sat, 23 Nov 2024 14:28:29 +0000 (14:28 +0000)
There are two behavioural differences between the objcopy in binutils
and llvm which resulted in build failures when building systemd with
clang:

1) If the section specified in --dump-section doesn't exist, binutils
set an exit code of 0 whereas llvm sets 1.  This means we need to handle
the exit code so that we raise exceptions on unexpected failures, but
return an empty byte string if the segment isn't found.

2) binutils writes the section to the file name directly, whereas llvm
writes to a temporary file and renames.  This means we can't read the
open fd directly, and instead need to re-open the file to read it.

Signed-off-by: Ross Burton <ross.burton@arm.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/recipes-core/systemd/dlopen-deps.inc

index eaf6ca1f79ad4b37e6833fea49c53c74263e7d9a..e0b333398c283695dc8be3b45e1c4de21aeaed8c 100644 (file)
@@ -12,9 +12,17 @@ python package_generate_dlopen_deps() {
         import tempfile, subprocess
 
         with tempfile.NamedTemporaryFile() as f:
-            cmd = [d.getVar("OBJCOPY"), "--dump-section", f"{segment}={f.name}", filename]
-            subprocess.run(cmd, check=True)
-            return f.read()
+            try:
+                cmd = [d.getVar("OBJCOPY"), "--dump-section", f"{segment}={f.name}", filename]
+                subprocess.run(cmd, check=True)
+                with open(f.name, "rb") as f2:
+                    return f2.read()
+            except subprocess.CalledProcessError as e:
+                # binutils-objcopy has 0 exit code if the segment can't be found, but llvm-objcopy
+                # does not. Assume the failure isn't critical and ignore errors.
+                if e.returncode == 1:
+                    return b""
+                raise e
 
     def parse(buffer, is_little):
         deps = []