]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
hosttools: force a --no-rosegment option if host ld supports it
authorAlexander Kanavin <alex@linutronix.de>
Fri, 6 Feb 2026 13:57:39 +0000 (14:57 +0100)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Thu, 12 Feb 2026 10:24:10 +0000 (10:24 +0000)
Please see https://bugzilla.yoctoproject.org/show_bug.cgi?id=16087
for the tricky, unpleasant details.

The summary of the issue:

>From Fedora 42 onwards, the --rosegment argument is passed to the
linker by default when building native binaries. This triggers
re-arrangement of sections by patchelf, resulting in binaries which
are loaded incorrectly by older kernel versions. These "contaminated"
native binaries end up in sstate and cause build failures when they
are used on older distros such as AlmaLinux 8 & 9 or Rocky Linux 8 &
9.

[YOCTO #16087]

Signed-off-by: Alexander Kanavin <alex@linutronix.de>
Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
Signed-off-by: Ross Burton <ross.burton@arm.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/classes-global/base.bbclass

index cf303c237a5a93a607c9b20dd85c36c3fc1006ed..22b427a5211bbba3ff589a517565cfc3a02884c0 100644 (file)
@@ -111,6 +111,22 @@ def get_lic_checksum_file_list(d):
             bb.fatal(d.getVar('PN') + ": LIC_FILES_CHKSUM contains an invalid URL: " + url)
     return " ".join(filelist)
 
+# Please see https://bugzilla.yoctoproject.org/show_bug.cgi?id=16087 for details
+# This can be removed after host distributions with kernels < 5.18
+# (e.g. rhel 8/9 and derivatives) are taken out of testing and support.
+def write_ld_wrapper(srctool, desttool):
+    wrapper = "#!/bin/sh\n{} --no-rosegment $@".format(srctool)
+
+    stdout, _ = bb.process.run("{} --help".format(srctool))
+    if "--no-rosegment" in stdout:
+        with open(desttool, 'w') as f:
+            f.write(wrapper)
+        import stat
+        st = os.stat(desttool)
+        os.chmod(desttool, st.st_mode | stat.S_IEXEC)
+    else:
+        os.symlink(srctool, desttool)
+
 def setup_hosttools_dir(dest, toolsvar, d, fatal=True):
     tools = d.getVar(toolsvar).split()
     origbbenv = d.getVar("BB_ORIGENV", False)
@@ -139,7 +155,10 @@ def setup_hosttools_dir(dest, toolsvar, d, fatal=True):
             if os.path.islink(srctool) and os.path.basename(os.readlink(srctool)) == 'ccache':
                 srctool = bb.utils.which(path, tool, executable=True, direction=1)
             if srctool:
-                os.symlink(srctool, desttool)
+                if tool == "ld" or tool.startswith("ld."):
+                    write_ld_wrapper(srctool, desttool)
+                else:
+                    os.symlink(srctool, desttool)
             else:
                 notfound.append(tool)