tst-tls5.h 542 B

123456789101112131415161718192021222324252627
  1. #include <stdint.h>
  2. #include <stdlib.h>
  3. #if USE_TLS && HAVE___THREAD
  4. struct tls_obj
  5. {
  6. const char *name;
  7. uintptr_t addr;
  8. size_t size;
  9. size_t align;
  10. };
  11. extern struct tls_obj tls_registry[];
  12. #define TLS_REGISTER(x) \
  13. static void __attribute__((constructor)) \
  14. tls_register_##x (void) \
  15. { \
  16. size_t i; \
  17. for (i = 0; tls_registry[i].name; ++i); \
  18. tls_registry[i].name = #x; \
  19. tls_registry[i].addr = (uintptr_t) &x; \
  20. tls_registry[i].size = sizeof (x); \
  21. tls_registry[i].align = __alignof__ (x); \
  22. }
  23. #endif