* Jan Beulich:
No, it's a required part of the TLS ABI. This:
__thread int x __attribute__ ((tls_model ("initial-exec")));
int *
f (void)
{
return &x;
}
Compiles to:
f:
movq x@gottpoff(%rip), %rax
addq %fs:0, %rax
ret
It assumes that %fs:0 has this special value. I don't think there is
any other way to get the address of a thread-local variable. This is
already present in the psABI manual, which has a couple of mentions of
%fs:0 in TLS-related examples.
There is also the GCC option -mno-tls-direct-seg-refs, which hard-codes
this assumption, too, even for TLS variables whose address is not taken.
We also have a couple of more GCC assumptions about TCB layout, e.g. for
the stack protector, split stacks, and libitm. Those might be specific
to GNU/Linux.
Thanks,
Florian