diff --git a/lld/ELF/Arch/X86_64.cpp b/lld/ELF/Arch/X86_64.cpp index 2ae80d274d021a..514ddc5ec8b041 100644 --- a/lld/ELF/Arch/X86_64.cpp +++ b/lld/ELF/Arch/X86_64.cpp @@ -32,6 +32,7 @@ class X86_64 : public TargetInfo { RelType getDynRel(RelType type) const override; void writeGotPltHeader(uint8_t *buf) const override; void writeGotPlt(uint8_t *buf, const Symbol &s) const override; + void writeIgotPlt(uint8_t *buf, const Symbol &s) const override; void writePltHeader(uint8_t *buf) const override; void writePlt(uint8_t *buf, const Symbol &sym, uint64_t pltEntryAddr) const override; @@ -380,6 +381,12 @@ void X86_64::writeGotPlt(uint8_t *buf, const Symbol &s) const { write64le(buf, s.getPltVA() + 6); } +void X86_64::writeIgotPlt(uint8_t *buf, const Symbol &s) const { + // An x86 entry is the address of the ifunc resolver function (for -z rel). + if (config->writeAddends) + write64le(buf, s.getVA()); +} + void X86_64::writePltHeader(uint8_t *buf) const { const uint8_t pltData[] = { 0xff, 0x35, 0, 0, 0, 0, // pushq GOTPLT+8(%rip) diff --git a/lld/test/ELF/x86-64-gotpc-relax.s b/lld/test/ELF/x86-64-gotpc-relax.s index 66aca36b213676..bf10838fc524ed 100644 --- a/lld/test/ELF/x86-64-gotpc-relax.s +++ b/lld/test/ELF/x86-64-gotpc-relax.s @@ -1,12 +1,22 @@ # REQUIRES: x86 # RUN: llvm-mc -filetype=obj -relax-relocations -triple=x86_64-unknown-linux %s -o %t.o +# RUN: ld.lld %t.o -o %t1 --no-apply-dynamic-relocs +# RUN: llvm-readobj -x .got.plt -r %t1 | FileCheck --check-prefixes=RELOC,NO-APPLY-DYNAMIC-RELOCS %s +# RUN: ld.lld %t.o -o %t1 --apply-dynamic-relocs +# RUN: llvm-readobj -x .got.plt -r %t1 | FileCheck --check-prefixes=RELOC,APPLY-DYNAMIC-RELOCS %s # RUN: ld.lld %t.o -o %t1 -# RUN: llvm-readobj -r %t1 | FileCheck --check-prefix=RELOC %s # RUN: llvm-objdump -d %t1 | FileCheck --check-prefix=DISASM %s -## There is no relocations. -# RELOC: Relocations [ -# RELOC: ] +## There is one R_X86_64_IRELATIVE relocations. +# RELOC-LABEL: Relocations [ +# RELOC-NEXT: Section (1) .rela.dyn { +# RELOC-NEXT: 0x202220 R_X86_64_IRELATIVE - 0x201172 +# RELOC-NEXT: } +# RELOC-NEXT: ] +# RELOC-LABEL: Hex dump of section '.got.plt': +# NO-APPLY-DYNAMIC-RELOCS-NEXT: 0x00202220 00000000 00000000 +# APPLY-DYNAMIC-RELOCS-NEXT: 0x00202220 72112000 00000000 +# RELOC-EMPTY: # 0x201173 + 7 - 10 = 0x201170 # 0x20117a + 7 - 17 = 0x201170