tst-tls1.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* glibc test for TLS in ld.so. */
  2. #undef _LIBC
  3. #include <stdio.h>
  4. #ifdef USE_TLS
  5. # include "tls-macros.h"
  6. /* Two common 'int' variables in TLS. */
  7. COMMON_INT_DEF(foo);
  8. COMMON_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"