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 Sep 5, 2014
1 parent 3a81ed1 commit cfc05bd
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions libhybris/hybris/tests/test_glesv2.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,23 @@
#include <math.h>
#include <stddef.h>

/* Regression test: make sure that there's no conflict between
* the TLS (thread-local storage) slots used via libEGL/bionic
* and the TLS space allocated by the host toolchain. The array
* declared here should remain unchanged regardless of GL activity.
* Since this array is the first __thread storage declared in the main
* program, glibc will allocate it before any others.
*/
#define SLOT_FILLER (void *) 0x11122111 /* arbitrary non-zero value */
#define S SLOT_FILLER
__thread void *tls_space[64] = {
S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S,
S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S,
S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S,
S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S,
};
#undef S

const char vertex_src [] =
" \
attribute vec4 position; \
Expand Down Expand Up @@ -175,6 +192,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] != SLOT_FILLER) {
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 cfc05bd

Please sign in to comment.