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

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 17 09:28:01 PDT 2026


================
@@ -778,9 +778,33 @@ void X86_64::scanSection(InputSectionBase &sec, unsigned shard) {
     elf::scanSection1<X86_64, ELF32LE>(*this, sec, shard);
 }
 
+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) {
+    // TLSGD 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
----------------
MaskRay wrote:

The comment was somehow reflowed. Improved the comments here. Emphasized TLSGD/TLSLD / PLTOFF64.

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


More information about the llvm-commits mailing list