[6/8] runqemu: preload uninative libraries when host gl drivers are in use

Message ID 20220206215316.367469-6-alex@linutronix.de
State Accepted, archived
Commit 39c10816d5ec9d9c7952d786d7a3f942d25d0c27
Headers show
Series [1/8] mesa: fold mesa-gl variant into the main recipe using mcextend class | expand

Commit Message

Alexander Kanavin Feb. 6, 2022, 9:53 p.m. UTC
Some of the host distributions build the drivers in a way (RPATH/RUNPATH)
that tricks uninative loader into loading pieces of the host libc, if
the same pieces haven't been previously loaded by native binaries. Mixing
the two libc versions leads to failures.

This change ensures that the correct (uninative) versions are always in use.

Signed-off-by: Alexander Kanavin <alex@linutronix.de>
---
 meta/classes/qemuboot.bbclass | 2 +-
 scripts/runqemu               | 8 ++++++++
 2 files changed, 9 insertions(+), 1 deletion(-)

Patch

diff --git a/meta/classes/qemuboot.bbclass b/meta/classes/qemuboot.bbclass
index cc1cbce69d..229bd88527 100644
--- a/meta/classes/qemuboot.bbclass
+++ b/meta/classes/qemuboot.bbclass
@@ -109,7 +109,7 @@  def qemuboot_vars(d):
     build_vars = ['MACHINE', 'TUNE_ARCH', 'DEPLOY_DIR_IMAGE',
                 'KERNEL_IMAGETYPE', 'IMAGE_NAME', 'IMAGE_LINK_NAME',
                 'STAGING_DIR_NATIVE', 'STAGING_BINDIR_NATIVE',
-                'STAGING_DIR_HOST', 'SERIAL_CONSOLES']
+                'STAGING_DIR_HOST', 'SERIAL_CONSOLES', 'UNINATIVE_LOADER']
     return build_vars + [k for k in d.keys() if k.startswith('QB_')]
 
 do_write_qemuboot_conf[vardeps] += "${@' '.join(qemuboot_vars(d))}"
diff --git a/scripts/runqemu b/scripts/runqemu
index 4e05c1bb15..d60cb2e152 100755
--- a/scripts/runqemu
+++ b/scripts/runqemu
@@ -461,6 +461,14 @@  class BaseConfig(object):
             raise RunQemuError("Could not determine the path to dri drivers on the host via pkg-config.\nPlease install Mesa development files (particularly, dri.pc) on the host machine.")
         os.environ['LIBGL_DRIVERS_PATH'] = dripath.decode('utf-8').strip()
 
+        # This preloads uninative libc pieces and therefore ensures that RPATH/RUNPATH
+        # in host mesa drivers doesn't trick uninative into loading host libc.
+        preload_items = ['libdl.so.2', 'librt.so.1', 'libpthread.so.0']
+        uninative_path = os.path.dirname(self.get("UNINATIVE_LOADER"))
+        if os.path.exists(uninative_path):
+            preload_paths = [os.path.join(uninative_path, i) for i in preload_items]
+            os.environ['LD_PRELOAD'] = " ".join(preload_paths)
+
     def check_args(self):
         for debug in ("-d", "--debug"):
             if debug in sys.argv: