[lld] [ELF] Handle and optimize x86-64 PLTOFF64 TLS sequences (PR #216263)

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 15 14:05:47 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[] = {
----------------
MaskRay wrote:

Thx! Added

https://github.com/llvm/llvm-project/pull/216263


More information about the llvm-commits mailing list