[PATCH] D101452: [ELF] Write R_X86_64_IRELATIVE addends with -z rel

Alexander Richardson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 9 02:42:50 PDT 2021


This revision was automatically updated to reflect the committed changes.
Closed by commit rG79332fb72202: [ELF] Write R_X86_64_IRELATIVE addends with -z rel (authored by arichardson).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D101452/new/

https://reviews.llvm.org/D101452

Files:
  lld/ELF/Arch/X86_64.cpp
  lld/test/ELF/x86-64-gotpc-relax.s


Index: lld/test/ELF/x86-64-gotpc-relax.s
===================================================================
--- lld/test/ELF/x86-64-gotpc-relax.s
+++ 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
Index: lld/ELF/Arch/X86_64.cpp
===================================================================
--- lld/ELF/Arch/X86_64.cpp
+++ lld/ELF/Arch/X86_64.cpp
@@ -32,6 +32,7 @@
   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 @@
   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)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101452.357455.patch
Type: text/x-patch
Size: 2301 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210709/acf34c86/attachment.bin>


More information about the llvm-commits mailing list