Message ID | 20241122110713.637176-1-ross.burton@arm.com |
---|---|
State | Accepted, archived |
Commit | 98879a8dbd1b7887b43a074193925bf1a55d44e7 |
Headers | show |
Series | systemd: handle llvm-objcopy behaviour when reading .note.dlopen section | expand |
This fixes the problem with clang+llvm-objcopy, please install this patch On Fri, Nov 22, 2024 at 3:07 AM Ross Burton via lists.openembedded.org <ross.burton=arm.com@lists.openembedded.org> wrote: > > 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> > --- > meta/recipes-core/systemd/dlopen-deps.inc | 14 +++++++++++--- > 1 file changed, 11 insertions(+), 3 deletions(-) > > diff --git a/meta/recipes-core/systemd/dlopen-deps.inc b/meta/recipes-core/systemd/dlopen-deps.inc > index eaf6ca1f79a..e0b333398c2 100644 > --- a/meta/recipes-core/systemd/dlopen-deps.inc > +++ b/meta/recipes-core/systemd/dlopen-deps.inc > @@ -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 = [] > -- > 2.34.1 > > > -=-=-=-=-=-=-=-=-=-=-=- > Links: You receive all messages sent to this group. > View/Reply Online (#207600): https://lists.openembedded.org/g/openembedded-core/message/207600 > Mute This Topic: https://lists.openembedded.org/mt/109720382/1997914 > Group Owner: openembedded-core+owner@lists.openembedded.org > Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [raj.khem@gmail.com] > -=-=-=-=-=-=-=-=-=-=-=- >
diff --git a/meta/recipes-core/systemd/dlopen-deps.inc b/meta/recipes-core/systemd/dlopen-deps.inc index eaf6ca1f79a..e0b333398c2 100644 --- a/meta/recipes-core/systemd/dlopen-deps.inc +++ b/meta/recipes-core/systemd/dlopen-deps.inc @@ -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 = []
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> --- meta/recipes-core/systemd/dlopen-deps.inc | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)