https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87998
Bug ID: 87998 Summary: defining an alias for a TLS variable Product: gcc Version: 9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- In the following snippet the declaration of the alias seems unsafe (or at least hard to reason about) because it's not clear which thread's variable the alias is bound to and what happens if the alias is used after the thread exits. Running the case on x86_64-linux shows the alias is distinct from the TLS variable in the main thread. GCC should at least issue a warning for the code if not reject it with an error. $ cat t.c && gcc -Wall -Wextra t.c && ./a.out __thread int a = 123; extern __attribute ((alias ("a"))) int b; int main (void) { a = 456; __builtin_printf ("a = %i (@%p)\n" "b = %i (@%p)\n", a, &a, b, &b); } a = 456 (@0x7fda5bc9d6fc) b = 123 (@0x600dfc)