From 1989dd5a982a95f2ded9ce306938e8a370977448 Mon Sep 17 00:00:00 2001 From: Richard Braakman Date: Wed, 27 Aug 2014 14:09:11 +0300 Subject: [PATCH] [tests] Regression test for EGL-glibc TLS conflict bionic and glibc have different layouts for TLS space. Since libEGL used a bionic slot directly (in inlined code), libhybris's hooks didn't translate it properly and libEGL ended up overwriting some unrelated thread-local values in glibc. The problem only showed up when linking with libGLESv2 (which pulls in libEGL), not when linking with libEGL directly. That's why the test was added to test_glesv2.c --- libhybris/hybris/tests/test_glesv2.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/libhybris/hybris/tests/test_glesv2.c b/libhybris/hybris/tests/test_glesv2.c index e5324869..42ed0c26 100644 --- a/libhybris/hybris/tests/test_glesv2.c +++ b/libhybris/hybris/tests/test_glesv2.c @@ -22,6 +22,15 @@ #include #include +/* Regression test: make sure that there's no conflict between + * the TLS slots used via libEGL/bionic and the TLS space allocated + * by the host toolchain. The array declared here should remain zeroed + * regardless of GL activity. (TLS: thread-local storage) + * Since this array is the first __thread storage declared in the main + * program, glibc will allocate it before any others. + */ +__thread void *tls_space[64]; + const char vertex_src [] = " \ attribute vec4 position; \ @@ -175,6 +184,18 @@ int main(int argc, char **argv) printf("terminated\n"); android_dlclose(baz); #endif + + int bad_tls = 0; + for (i=0; i<64; ++i) { + if (tls_space[i] != 0) { + printf("TLS array slot %d polluted: %p\n", i, tls_space[i]); + bad_tls++; + } + } + if (bad_tls) + return 1; + + return 0; } // vim:ts=4:sw=4:noexpandtab