tst-tls3.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* glibc test for TLS in ld.so. */
  2. #include <stdio.h>
  3. #ifdef USE_TLS
  4. # include "tls-macros.h"
  5. /* One define int variable, two externs. */
  6. COMMON_INT_DECL(foo);
  7. VAR_INT_DECL(bar);
  8. VAR_INT_DEF(baz);
  9. #endif
  10. extern int in_dso (void);
  11. #define TEST_FUNCTION do_test ()
  12. static int
  13. do_test (void)
  14. {
  15. #ifdef USE_TLS
  16. int result = 0;
  17. int *ap, *bp, *cp;
  18. /* Set the variable using the local exec model. */
  19. puts ("set baz to 3 (LE)");
  20. ap = TLS_LE (baz);
  21. *ap = 3;
  22. /* Get variables using initial exec model. */
  23. puts ("set variables foo and bar (IE)");
  24. ap = TLS_IE (foo);
  25. *ap = 1;
  26. bp = TLS_IE (bar);
  27. *bp = 2;
  28. /* Get variables using local dynamic model. */
  29. fputs ("get sum of foo, bar (GD) and baz (LD)", stdout);
  30. ap = TLS_GD (foo);
  31. bp = TLS_GD (bar);
  32. cp = TLS_LD (baz);
  33. printf (" = %d\n", *ap + *bp + *cp);
  34. result |= *ap + *bp + *cp != 6;
  35. if (*ap != 1)
  36. {
  37. printf ("foo = %d\n", *ap);
  38. result = 1;
  39. }
  40. if (*bp != 2)
  41. {
  42. printf ("bar = %d\n", *bp);
  43. result = 1;
  44. }
  45. if (*cp != 3)
  46. {
  47. printf ("baz = %d\n", *cp);
  48. result = 1;
  49. }
  50. result |= in_dso ();
  51. return result;
  52. #else
  53. return 0;
  54. #endif
  55. }
  56. #include "../test-skeleton.c"