From 4e0132a4f6384b77ba532aa14e5ae94af9ddd681 Mon Sep 17 00:00:00 2001 From: Alexey Min Date: Wed, 14 Aug 2019 10:52:14 +0300 Subject: [PATCH] hybris/libhybris: Fix eglplatform_wayland linking issue (!589) It should not directly call functions from hybris's libEGL, because it is not linking to libEGL. Load libEGL dynamically and resolve function at run time instead. Related: https://github.com/libhybris/libhybris/pull/424 [ci:skip-build]: already built successfully in CI --- ...tform_wayland-link-libEGL-at-runtime.patch | 90 +++++++++++++++++++ hybris/libhybris/APKBUILD | 13 +-- 2 files changed, 98 insertions(+), 5 deletions(-) create mode 100644 hybris/libhybris/0005-eglplatform_wayland-link-libEGL-at-runtime.patch diff --git a/hybris/libhybris/0005-eglplatform_wayland-link-libEGL-at-runtime.patch b/hybris/libhybris/0005-eglplatform_wayland-link-libEGL-at-runtime.patch new file mode 100644 index 000000000..bee5e5404 --- /dev/null +++ b/hybris/libhybris/0005-eglplatform_wayland-link-libEGL-at-runtime.patch @@ -0,0 +1,90 @@ +From 1f4d73a7c3ebfbbeaa91de51ef50c69676da730d Mon Sep 17 00:00:00 2001 +From: Alexey Min +Date: Sat, 31 Aug 2019 01:51:55 +0300 +Subject: [PATCH] eglplatform_wayland: link libEGL at runtime + +hybris_egl_display_get_mapping() function is implemented +in libhybris's libEGL.so. However, eglplatform_wayland.so +is not linked to libEGL directly, causing undefined symbol +errors during loading, if libEGL was not already loaded by +some other dependencies. Therefore, we should load libEGL +at runtime here and resolve this function dynamically. +--- + .../platforms/wayland/eglplatform_wayland.cpp | 40 ++++++++++++++++++- + 1 file changed, 39 insertions(+), 1 deletion(-) + +diff --git a/hybris/egl/platforms/wayland/eglplatform_wayland.cpp b/hybris/egl/platforms/wayland/eglplatform_wayland.cpp +index 191ae76..7668c32 100644 +--- a/hybris/egl/platforms/wayland/eglplatform_wayland.cpp ++++ b/hybris/egl/platforms/wayland/eglplatform_wayland.cpp +@@ -36,6 +36,7 @@ + #include + #include + #include ++#include + extern "C" { + #include + }; +@@ -61,6 +62,13 @@ static EGLSyncKHR (*_eglCreateSyncKHR)(EGLDisplay dpy, EGLenum type, const EGLin + static EGLBoolean (*_eglDestroySyncKHR)(EGLDisplay dpy, EGLSyncKHR sync) = NULL; + static EGLint (*_eglClientWaitSyncKHR)(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, EGLTimeKHR timeout) = NULL; + ++/* The following function is implemented in libhybris's libEGL.so. ++ * However, eglplatform_wayland.so is not linking to libEGL directly, ++ * causing undefined symbol errors during loading, if libEGL was not ++ * already loaded by some other dependencies. Therefore, we should try ++ * to load libEGL at runtime here and resolve this function dynamically */ ++typedef struct _EGLDisplay *(*PFNHYBRISEGLDISPLAYGETMAPPINGPROC)(EGLDisplay dpy); ++ + struct WaylandDisplay { + _EGLDisplay base; + +@@ -202,6 +210,36 @@ extern "C" int waylandws_post(EGLNativeWindowType win, void *buffer) + return ((WaylandNativeWindow *) eglwin->nativewindow)->postBuffer((ANativeWindowBuffer *) buffer); + } + ++/** ++ * Loads libhybris's libEGL at runtime to call hybris_egl_display_get_mapping() ++ */ ++static struct _EGLDisplay *_hybris_egl_display_get_mapping(EGLDisplay dpy) ++{ ++ static void *libEGL_handle = NULL; ++ static PFNHYBRISEGLDISPLAYGETMAPPINGPROC hybris_egl_display_get_mapping_fn = NULL; ++ ++ if (!libEGL_handle) { ++ dlerror(); // cleanup error buffer ++ libEGL_handle = dlopen("libEGL.so.1", RTLD_NOW | RTLD_GLOBAL); ++ if (!libEGL_handle) { ++ HYBRIS_ERROR("ERROR: Failed to dlopen libEGL! %s", dlerror()); ++ abort(); ++ } ++ } ++ ++ if (!hybris_egl_display_get_mapping_fn) { ++ dlerror(); // cleanup error buffer ++ hybris_egl_display_get_mapping_fn = (PFNHYBRISEGLDISPLAYGETMAPPINGPROC)dlsym( ++ libEGL_handle, "hybris_egl_display_get_mapping"); ++ if (!hybris_egl_display_get_mapping_fn) { ++ HYBRIS_ERROR("ERROR: Cannot resolve 'hybris_egl_display_get_mapping' in libEGL! %s", dlerror()); ++ abort(); ++ } ++ } ++ ++ return hybris_egl_display_get_mapping_fn(dpy); ++} ++ + extern "C" wl_buffer *waylandws_createWlBuffer(EGLDisplay dpy, EGLImageKHR image) + { + egl_image *img = reinterpret_cast(image); +@@ -211,7 +249,7 @@ extern "C" wl_buffer *waylandws_createWlBuffer(EGLDisplay dpy, EGLImageKHR image + return NULL; + } + if (img->target == EGL_WAYLAND_BUFFER_WL) { +- WaylandDisplay *wdpy = (WaylandDisplay *)hybris_egl_display_get_mapping(dpy); ++ WaylandDisplay *wdpy = (WaylandDisplay *)_hybris_egl_display_get_mapping(dpy); + server_wlegl_buffer *buf = server_wlegl_buffer_from((wl_resource *)img->egl_buffer); + WaylandNativeWindowBuffer wnb(buf->buf); + // The buffer will be managed by the app, so pass NULL as the queue so that +-- +2.21.0 + diff --git a/hybris/libhybris/APKBUILD b/hybris/libhybris/APKBUILD index d8e6f5607..875d600f9 100644 --- a/hybris/libhybris/APKBUILD +++ b/hybris/libhybris/APKBUILD @@ -1,6 +1,6 @@ pkgname=libhybris pkgver=1.0_git20190508 -pkgrel=2 +pkgrel=3 arch="x86 armhf armv7 aarch64" url="https://github.com/libhybris/libhybris" license="Apache" @@ -13,7 +13,9 @@ source="$pkgname-$_commit.tar.gz::https://github.com/libhybris/libhybris/archive 0001-Make-libhybris-compile-with-musl.patch 0002-tests-Regression-test-for-EGL-glibc-TLS-conflict.patch 0003-PATCH-v2-Implement-X11-EGL-platform-based-on-wayland.patch - 0004-Build-test-hwcomposer-7-caf.patch" + 0004-Build-test-hwcomposer-7-caf.patch + 0005-eglplatform_wayland-link-libEGL-at-runtime.patch +" pkgdesc="libhybris allows to use bionic-based HW adaptations" subpackages="$pkgname-dev $pkgname-egl $pkgname-gles $pkgname-libwayland-egl:_wayland @@ -64,8 +66,8 @@ build() { _arch="arm64" _enable_quirks="--enable-mali-quirks \ --enable-adreno-quirks" - elif [ "$CARCH" == "x86" ]; then - _vers="7.1 4.4" + elif [ "$CARCH" == "x86" ]; then + _vers="7.1 4.4" _ldpath="/usr/libexec/droid-hybris/system/lib:/vendor/lib:/system/lib" _arch="x86" fi @@ -170,4 +172,5 @@ sha512sums="681e8345ba56d5b9684ab3901c9cfdc6d4f48f55ef97611eef14d9471f08f1c0f608 9f7a324f18332e44f8789108e32f0587c268d10adaee0040c42d1bece7ab58e292d68243e7814f34f37b3b5dff590758269e531b4f2fd1991334eda4333f5854 0001-Make-libhybris-compile-with-musl.patch 1355a4403d1af8bdf75b9e4502cbfc093b9788224ce7c24a1f6a53dd7996d385d31a3362577a4293db6b6d0dd0ae4e88140b38c658ff0a288d9acfc2753859bb 0002-tests-Regression-test-for-EGL-glibc-TLS-conflict.patch db7bb0ffc04042b32d870db364df4d38d9769978f26d71f98dd2569b4cae7fb3839c7a0c421b465f931a57fcde38b8eca091b7ae0062e32a7e09b93a701397f3 0003-PATCH-v2-Implement-X11-EGL-platform-based-on-wayland.patch -eda57804fefa1d586e90fb2198c310f65e6dbc7e09b5d1dd7d15df4ab152c4c8915c212230a92c35ec8a013d3ec7a7b1d289653bedb46b7eb2850a477ccebe16 0004-Build-test-hwcomposer-7-caf.patch" +eda57804fefa1d586e90fb2198c310f65e6dbc7e09b5d1dd7d15df4ab152c4c8915c212230a92c35ec8a013d3ec7a7b1d289653bedb46b7eb2850a477ccebe16 0004-Build-test-hwcomposer-7-caf.patch +39cfd9db2bcd77615de7370e0df861ce61a7025d1b39fd049d27f345643626bbe5253515a876f606fc86b678cb85f8634a9df663b5b32a90fa53b37136d25814 0005-eglplatform_wayland-link-libEGL-at-runtime.patch"