For x86-64, D33100 added a diagnostic for local-exec TLS relocations referencing a preemptible symbol.
This patch generalizes it to non-preemptible symbols (see -Bsymbolic in tls.s)
on all targets.
Local-exec TLS relocations resolve to offsets relative to a fixed point within
the static TLS block, which are only meaningful for the executable.
With this change, clang -fpic -shared -fuse-ld=bfd a.c on the following example will be flagged for AArch64/ARM/i386/x86-64/PowerPC/RISC-V
static __attribute__((tls_model("local-exec"))) __thread long TlsVar = 42; long bump() { return ++TlsVar; }
Note, in GNU ld, at least arm, riscv and x86's ports have the similar
diagnostics, but aarch64 and ppc64 do not error.
I think this should also check for R_NEG_TLS. AFAIK R_NEG_TLS/R_386_TLS_LE_32 is only used on 32-bit x86, and compilers usually prefer R_TLS/R_386_TLS_LE, but it's possible to bypass the new error with assembly:
movl %gs:TlsVar@NTPOFF, %eax ==> R_TLS
movl %gs:TlsVar@TPOFF, %eax ==> R_NEG_TLS