tst-tls1.c 1.6 KB

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