From 29a89cc10adb82bf35c2ab486a2b5d96a9e7aadf Mon Sep 17 00:00:00 2001 From: gold Date: Thu, 1 Oct 2026 08:23:04 +0800 Subject: [PATCH] [Fix] (gbm): the two defects only the Android build could find Neither showed up in the Linux build that verified this library, and both are the kind that would have been found by the first person to build the phone half - so they are fixed here rather than left for that person. bionic only declares memfd_create from API 30 and this library builds against 26. The kernel call is far older than the declaration, so it is asked for by number: the same call with the name the headers of this API level do not carry yet. The library carries the tree's logger, which reaches Android's own log through liblog. The main target gets that library in its own Android block; a second target built from the same sources needs it for the same reason, and without it the link is what fails rather than anything in the code. --- CMakeLists.txt | 7 +++++++ MobileGL/MG_Gbm/GbmDevice.cpp | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7e8777fa..de68a52d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1240,3 +1240,10 @@ if (ANDROID AND MOBILEGL_BUILD_EXTMEM_PROBE) endif() endif() endif() + +# The GBM library carries the tree's logger, which reaches Android's own log. The main target gets +# these libraries in its own Android block; a library built from the same sources needs them for the +# same reason, and without them it is the LINK that fails rather than anything in the code. +if (ANDROID) + target_link_libraries(MobileGLGbm PRIVATE log android) +endif() diff --git a/MobileGL/MG_Gbm/GbmDevice.cpp b/MobileGL/MG_Gbm/GbmDevice.cpp index abfb4eba..e4126fc3 100644 --- a/MobileGL/MG_Gbm/GbmDevice.cpp +++ b/MobileGL/MG_Gbm/GbmDevice.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -139,7 +140,15 @@ namespace MobileGL::MG_Gbm device.HeapPath.c_str(), alignedSize, heapErrno, strerror(heapErrno)); } +#if defined(__ANDROID__) && __ANDROID_API__ < 30 + // BIONIC ONLY DECLARES memfd_create FROM API 30, and this library builds against 26. + // The kernel call is far older than the declaration - it has been there since 3.17 - so + // asking for it by number is not a workaround for a missing feature, it is the same call + // with the name the headers of this API level do not carry yet. + const Int fd = static_cast(::syscall(__NR_memfd_create, "mobilegl-gbm", MFD_CLOEXEC)); +#else const Int fd = memfd_create("mobilegl-gbm", MFD_CLOEXEC); +#endif if (fd < 0) { MGLOG_E_ONCE("gbm: memfd_create failed (%d: %s) and no dma-heap node is usable, so no "