[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
Wed Apr 28 06:46:32 PDT 2021
arichardson created this revision.
arichardson added reviewers: MaskRay, grimar, pcc.
Herald added subscribers: pengfei, emaste.
arichardson requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
I found this missing case with the new --check-dynamic-relocation flag
while running the lld tests with --apply-dynamic-relocs enabled by default.
This also fixes a broken CHECK in lld/test/ELF/x86-64-gotpc-relax.s:
The test wasn't using CHECK-NEXT, so it was passing despite the output
actually containing relocations. I am not sure when this changed, but I
think this behaviour is correct.
Found with D101450 <https://reviews.llvm.org/D101450> + enabling --apply-dynamic-relocs by default.
Repository:
rG LLVM Github Monorepo
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;
@@ -379,6 +380,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.341180.patch
Type: text/x-patch
Size: 2301 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210428/79db6941/attachment.bin>
More information about the llvm-commits
mailing list