[lld] [ELF] Handle and optimize x86-64 PLTOFF64 TLS sequences (PR #216263)
Peter Smith via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 14 03:21:09 PDT 2026
================
@@ -778,9 +778,29 @@ void X86_64::scanSection(InputSectionBase &sec, unsigned shard) {
elf::scanSection1<X86_64, ELF32LE>(*this, sec, shard);
}
+// TLSGD/TLSLD can be directly followed by MOVABS (instead of CALL):
+// leaq x at tlsgd(%rip), %rdi # 48 8d 3d <disp32>
+// movabsq $__tls_get_addr at pltoff, %rax # 48 b8 <imm64>, R_X86_64_PLTOFF64
+// addq %REG, %rax
+// callq *%rax
+static bool isPltOff64Tls(const uint8_t *loc) {
+ return loc[4] == 0x48 && loc[5] == 0xb8;
+}
+
void X86_64::relaxTlsGdToLe(uint8_t *loc, const Relocation &rel,
uint64_t val) const {
if (rel.type == R_X86_64_TLSGD) {
+ if (isPltOff64Tls(loc)) {
+ const uint8_t inst[] = {
----------------
smithp35 wrote:
I'm wondering if it would be best to stick the same comment pattern
```
// Convert
// leaq x at tlsgd(%rip), %rdi
// movabsq $__tls_get_addr at pltoff, %rax
// addq %REG, %rax
// callq *%rax
// to the following three instructions
```
That makes it easier to see where the `loc -3` comes from.
https://github.com/llvm/llvm-project/pull/216263
More information about the llvm-commits
mailing list