tst-tls2.c 1.6 KB

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