blob: bd04b50814142cae349f719be5c5bbc2713876aa [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001#include <stdio.h>
2#include <tls.h>
3
4#define TLS_VAR_INIT_VALUE 99
5
6#ifdef USE_TLS
7__thread int tls_var __attribute__((tls_model("global-dynamic")));
8static __thread int local_tls_var __attribute__((tls_model("local-dynamic")));
9#endif
10
11void __attribute__((constructor)) libtls_ctor(void);
12void libtls_ctor(void)
13{
14 printf("libtls: constructor!\n");
15#ifdef USE_TLS
16 local_tls_var = TLS_VAR_INIT_VALUE;
17 tls_var = local_tls_var;
18#endif
19}
20
21void __attribute__((destructor)) libtls_dtor(void);
22void libtls_dtor(void)
23{
24 printf("libtls: destructor!\n");
25}