TLS broken on Android for x86
The specific failure we're seeing is:
08-10 19:48:46.531 100 100 E vndksupport: Could not load /vendor/lib64/egl/libEGL_mesa.so from sphal namespace: dlopen failed: TLS symbol "_glapi_tls_Dispatch" in dlopened "/vendor/lib64/libglapi.so" referenced from "/vendor/lib64/libglapi.so" using IE access model.
This is similar to what @anholt saw in !10389 (0d8e4318):
/* Android 29 gained ELF TLS support, but it doesn't support initial-exec and
* it will throw:
*
* dlopen failed: TLS symbol "(null)" in dlopened
* "/vendor/lib64/egl/libEGL_mesa.so" referenced from
* "/vendor/lib64/egl/libEGL_mesa.so" using IE access model.
*/
The problem is that libglapi.so has DF_STATIC_TLS set in its dynamic section. Clang sets this based on which relocation method is set for TLS. For ARM/ARM64, the change above was sufficient to remove all references to initial-exec TLS, but for x86 and x86_64, there’s additional references to initial-exec TLS:
https://gitlab.freedesktop.org/mesa/mesa/-/blob/main/src/mapi/entry_x86-64_tls.h#L62 with the @GOTTPOFF annotation
https://gitlab.freedesktop.org/mesa/mesa/-/blob/main/src/mapi/glapi/gen/gl_x86-64_asm.py#L144
So... we either need to disable all of glapi’s assembly reference for Android with ELF_TLS (alternate patch to be more scoped and do just this: alternate_android_tls.patch), or add new assembly stubs which support non-initial-exec TLS for the dispatch table.