[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:10 PDT 2026
================
@@ -830,6 +850,18 @@ void X86_64::relaxTlsGdToLe(uint8_t *loc, const Relocation &rel,
void X86_64::relaxTlsGdToIe(uint8_t *loc, const Relocation &rel,
uint64_t val) const {
if (rel.type == R_X86_64_TLSGD) {
+ if (isPltOff64Tls(loc)) {
+ const uint8_t inst[] = {
+ 0x64, 0x48, 0x8b, 0x04, 0x25, 0x00, 0x00,
+ 0x00, 0x00, // mov %fs:0x0,%rax
+ 0x48, 0x03, 0x05, 0, 0, 0, 0, // addq x at gottpoff(%rip),%rax
+ 0x66, 0x0f, 0x1f, 0x44, 0x00, 0x00, // nopw 0x0(%rax,%rax,1)
+ };
+ memcpy(loc - 3, inst, sizeof(inst));
+ // The new displacement is 9 bytes ahead of the original one.
----------------
smithp35 wrote:
There's a comment in the case below on line 879 that I think captures the meaning a bit better. Could we use that (with 9 instead of 8)
> // Both code sequences are PC relatives, but since we are moving the
// constant forward by 8 bytes we have to subtract the value by 8.
https://github.com/llvm/llvm-project/pull/216263
More information about the llvm-commits
mailing list