Open patrick-fu opened 1 year ago
Maybe all cocos engine sources should be compiled with "-fvisibility=hidden", whether build for debug or release to fix this crash.
Therefore, when others (e.g. third-party shared library) directly use EGL related APIs, it actually links the fake EGL symbols provided by libcocos.so (eglw.o) instead of system libEGL.so, this leads to a crash.
Yep, it will have problem. Can i know what third-parity shared library that uses EGL you used? And why need to do it like this?
Therefore, when others (e.g. third-party shared library) directly use EGL related APIs, it actually links the fake EGL symbols provided by libcocos.so (eglw.o) instead of system libEGL.so, this leads to a crash.
Yep, it will have problem. Can i know what third-parity shared library that uses EGL you used? And why need to do it like this?
ZEGO RTC SDK, it need to use EGL API to capture and render video frame. The RTC engine directly use a lots of EGL APIs (e.g. eglGetProcAddress) but not requires them by "dlsym".
The core problem is that the RTC shared library always load EGL API symbols from "libcocos.so" but not system "libEGL.so", it happens on runtime (when the App launch) but not link time, so I can not control the EGL symbol link from which library.
So the simplest way is hide cocos engine internal symbols on debug.
By the way, I found out that "-fvisibility=hidden" is the default flag on iOS/macOS for both release and debug, and I dont know why those cocos engine internal symbols needs to be exported on android?
Got it. I was told that, doesn't hide symbols in debug mode just to have meaningful crash stack information on Android. So i think it is better to just hide these EGL symbols in cocos.
I will ask somebody to do it. As these codes seems to be generated by a script.
Cocos Creator version
3.6.2
System information
Android
Issue description
When building for Android debug, all source code will be compiled with "-fvisibility=default" cflag, and native/cocos/renderer/gfx-gles-common/eglw.cpp file contains some custom EGL symbols (the symbol name is exactly the same as the system library libEGL.so)
Therefore, when others (e.g. third-party shared library) directly use EGL related APIs, it actually links the fake EGL symbols provided by libcocos.so (eglw.o) instead of system libEGL.so, this leads to a crash.
Fatal signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 0x70746aa360 in tid 12986 (Thread-2), pid 12720 (.egl.crash.demo)
readelf -a build/android/proj/build/CocosCreatorEglCrashDemo/intermediates/cmake/debug/obj/arm64-v8a/libcocos.so | grep egl
https://github.com/cocos/cocos-engine/blob/1461974c9f1555d195f6ac187d31425485695b62/native/cmake/predefine.cmake#L144
I don't know why cocos engine (eglw.cpp) defines those EGL symbols with the same name (maybe it's a proxy for the system EGL library?) but it doesn't provide the correct EGL functionality.
Relevant error log output
No response
Steps to reproduce
Call any EGL APIs from <EGL/egl.h>
Minimal reproduction project
https://github.com/patrick-fu/CocosCreatorEglCrashDemo