Skip to content

Commit

Permalink
[tests] Regression test for EGL-glibc TLS conflict
Browse files Browse the repository at this point in the history
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
  • Loading branch information
amtep committed Aug 28, 2014
1 parent 3a81ed1 commit 1989dd5
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions libhybris/hybris/tests/test_glesv2.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@
#include <math.h>
#include <stddef.h>

/* 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; \
Expand Down Expand Up @@ -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

0 comments on commit 1989dd5

Please sign in to comment.