[ELF] Support non-RAX/non-adjacent R_X86_64_GOTPC32_TLSDESC/R_X86_64_TLSDESC_CALL
authorFangrui Song <i@maskray.me>
Tue, 23 Nov 2021 18:30:11 +0000 (10:30 -0800)
committerFangrui Song <i@maskray.me>
Tue, 23 Nov 2021 18:30:11 +0000 (10:30 -0800)
commit38ed1db7e8740fce236d1893ff9e20cc22ef0ada
tree017a9637def87f3cddf33a0aa75fb8954b63e424
parent0d3add216f04b99ed1db1a05c39975d4a9c83e6b
[ELF] Support non-RAX/non-adjacent R_X86_64_GOTPC32_TLSDESC/R_X86_64_TLSDESC_CALL

The current TLSDESC optimization code assumes:
```
leaq x@tlsdesc(%rip), %rax
call *x@tlscall(%rax)       # adjacent
```

From https://gitlab.freedesktop.org/mesa/mesa/-/issues/5665 , it seems that the
two instructions may not be adjacent in GCC 10's output:
```
leaq x@tlsdesc(%rip), %rax
something else
call *x@tlscall(%rax)
```

This patch supports the case. While here, support non-RAX registers for
R_X86_64_GOTPC32_TLSDESC, in case the compiler generates inefficient:

```
leaq x@tlsdesc(%rip), %rcx  # or %rdx, %rbx, %rdi, ...
movq %rcx, %rax
call *x@tlscall(%rax)       # GNU ld/gold error for non-RAX
```

Differential Revision: https://reviews.llvm.org/D114416
lld/ELF/Arch/X86_64.cpp
lld/docs/ReleaseNotes.rst
lld/test/ELF/invalid/x86-64-tlsdesc-gd.s
lld/test/ELF/x86-64-tlsdesc-gd.s