From 8576652fb61c7f76be4895fdbbb12a497a0c4a6c Mon Sep 17 00:00:00 2001 From: MaxsTechReview Date: Mon, 23 Nov 2026 19:09:23 -0500 Subject: [PATCH] fix(fex): thunk libOpenGL with the host GL library (#3099) * fix(fex): x86 programs that use libOpenGL load again * fix(fex): thunk libOpenGL with the host GL library --- .../0015-gl-thunk-overlays-libopengl.patch | 15 ++++++++++ .../overlay/usr/local/bin/droiddeck-fex | 2 +- tools/tests/test_droiddeck_fex.py | 15 ++++++++++ tools/tests/test_fex_gl_thunk_overlay.py | 29 +++++++++++++++++++ 4 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 tools/fex/patches/0015-gl-thunk-overlays-libopengl.patch create mode 100644 tools/tests/test_fex_gl_thunk_overlay.py diff --git a/tools/fex/patches/0015-gl-thunk-overlays-libopengl.patch b/tools/fex/patches/0015-gl-thunk-overlays-libopengl.patch new file mode 100644 index 0000000000..b1557d3c39 --- /dev/null +++ b/tools/fex/patches/0015-gl-thunk-overlays-libopengl.patch @@ -0,0 +1,15 @@ +diff --git a/Data/ThunksDB.json b/Data/ThunksDB.json +index d52ff04..886379a 100644 +--- a/Data/ThunksDB.json ++++ b/Data/ThunksDB.json +@@ -6,7 +6,9 @@ + "@PREFIX_LIB@/libGL.so", + "@PREFIX_LIB@/libGL.so.1", + "@PREFIX_LIB@/libGL.so.1.2.0", +- "@PREFIX_LIB@/libGL.so.1.7.0" ++ "@PREFIX_LIB@/libGL.so.1.7.0", ++ "@PREFIX_LIB@/libOpenGL.so.0", ++ "@PREFIX_LIB@/libOpenGL.so.0.0.0" + ] + }, + "Vulkan": { diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-fex b/tools/linuxfs/overlay/usr/local/bin/droiddeck-fex index df14d93f7e..7c1dd3176f 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-fex +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-fex @@ -51,7 +51,7 @@ PROVIDED = frozenset(( "libssl.so.3", "libcrypto.so.3", "libfreetype.so.6", "libpng16.so.16", "libbrotlidec.so.1", "libbrotlicommon.so.1", "libbz2.so.1.0", "libz.so.1", "libwayland-client.so.0", "libwayland-egl.so.1", "libwayland-server.so.0", "libffi.so.8", - "libgbm.so.1", "libdrm.so.2", "libexpat.so.1", + "libgbm.so.1", "libdrm.so.2", "libexpat.so.1", "libOpenGL.so.0", )) PROVIDED_NEEDS = { "libwayland-client.so.0": ("libffi.so.8",), diff --git a/tools/tests/test_droiddeck_fex.py b/tools/tests/test_droiddeck_fex.py index 22e5017d2d..ce474de509 100644 --- a/tools/tests/test_droiddeck_fex.py +++ b/tools/tests/test_droiddeck_fex.py @@ -526,6 +526,21 @@ class PrepareTest(FexTestCase): for name in names: self.assertEqual((Path(fex["rootfs"]) / "lib" / arch / name).read_bytes(), b"new ABI " + name.encode()) + def test_opengl_dispatch_library_comes_from_the_newer_runtime_when_the_base_lacks_it(self): + self.fex_tool() + sniper = self.runtime() + FEX["materialize"](str(sniper)) + provider = self.graphics(sniper) + for arch in ("x86_64-linux-gnu", "i386-linux-gnu"): + self.write(sniper / "files/lib" / arch / "libGLdispatch.so.0", b"base dispatch") + self.write(provider / "files/lib" / arch / "libOpenGL.so.0.0.0", b"opengl " + arch.encode()) + os.symlink("libOpenGL.so.0.0.0", provider / "files/lib" / arch / "libOpenGL.so.0") + fex, _ = self.quiet(FEX["prepare"]) + for arch in ("x86_64-linux-gnu", "i386-linux-gnu"): + root = Path(fex["rootfs"]) / "lib" / arch + self.assertEqual((root / "libOpenGL.so.0").read_bytes(), b"opengl " + arch.encode()) + self.assertEqual((root / "libGLdispatch.so.0").read_bytes(), b"base dispatch") + def test_gbm_requires_usable_provider_dependencies_on_both_architectures(self): self.fex_tool() sniper = self.runtime() diff --git a/tools/tests/test_fex_gl_thunk_overlay.py b/tools/tests/test_fex_gl_thunk_overlay.py new file mode 100644 index 0000000000..e06d59e632 --- /dev/null +++ b/tools/tests/test_fex_gl_thunk_overlay.py @@ -0,0 +1,29 @@ +from pathlib import Path +import re +import unittest + +PATCH = Path(__file__).resolve().parents[1] / "fex/patches/0015-gl-thunk-overlays-libopengl.patch" + + +def hunk(sign): + lines = [line for line in PATCH.read_text().splitlines() if not line.startswith(("diff ", "index ", "--- ", "+++ ", "@@"))] + return re.findall(r'"([^"]+)"', "\n".join(line[1:] for line in lines if line[:1] in (" ", sign))) + + +class FexGlThunkOverlayTest(unittest.TestCase): + def test_libopengl_joins_the_gl_overlay(self): + before, after = hunk("-"), hunk("+") + self.assertNotIn("@PREFIX_LIB@/libOpenGL.so.0", before) + self.assertIn("@PREFIX_LIB@/libOpenGL.so.0", after) + self.assertIn("@PREFIX_LIB@/libOpenGL.so.0.0.0", after) + self.assertEqual([path for path in before if path.startswith("@PREFIX_LIB@/libGL.")], + [path for path in after if path.startswith("@PREFIX_LIB@/libGL.")]) + self.assertLess(after.index("@PREFIX_LIB@/libGL.so.1.7.0"), after.index("Vulkan")) + self.assertLess(after.index("@PREFIX_LIB@/libOpenGL.so.0.0.0"), after.index("Vulkan")) + + def test_patch_touches_only_the_thunks_database(self): + self.assertEqual(["Data/ThunksDB.json"], re.findall(r"^diff --git a/(\S+) ", PATCH.read_text(), re.M)) + + +if __name__ == "__main__": + unittest.main()