tst-tls3.c 1.2 KB

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