[ELF] Reject local-exec TLS relocations for -shared
authorFangrui Song <i@maskray.me>
Mon, 21 Dec 2020 16:47:04 +0000 (08:47 -0800)
committerFangrui Song <i@maskray.me>
Mon, 21 Dec 2020 16:47:04 +0000 (08:47 -0800)
commitfb3c1b3de5ce7342438d7451f01a14f9c52323cd
treeffe6dd7a7bc1fc410b3258ba0ced94568a1591c2
parente25afcfa51abbd63ddbe943913af1ba61161ab28
[ELF] Reject local-exec TLS relocations for -shared

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/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.

Differential Revision: https://reviews.llvm.org/D93331
12 files changed:
lld/ELF/Relocations.cpp
lld/test/ELF/Inputs/i386-static-tls-model4.s [deleted file]
lld/test/ELF/aarch64-tls-le.s
lld/test/ELF/arm-tls-le32.s
lld/test/ELF/i386-static-tls-model.s
lld/test/ELF/i386-tls-le.s
lld/test/ELF/i386-zrel-zrela.s
lld/test/ELF/mips-tls-hilo.s
lld/test/ELF/ppc64-local-exec-tls.s
lld/test/ELF/riscv-tls-le.s
lld/test/ELF/tls.s
lld/test/ELF/x86-64-reloc-tpoff32-fpic.s [deleted file]