tst-tls2.c 1.5 KB

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