tst-tlsmod1.c 1.2 KB

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