tst-tlsmod1.c 1.2 KB

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