[lld] e564932 - [ELF] Write R_RISCV_IRELATIVE addends with -z rel
Alex Richardson via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 9 02:42:01 PDT 2021
Author: Alex Richardson
Date: 2021-07-09T10:41:40+01:00
New Revision: e5649328428f107962bf82a43299ba126514aae9
URL: https://github.com/llvm/llvm-project/commit/e5649328428f107962bf82a43299ba126514aae9
DIFF: https://github.com/llvm/llvm-project/commit/e5649328428f107962bf82a43299ba126514aae9.diff
LOG: [ELF] Write R_RISCV_IRELATIVE addends with -z rel
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 is the same as D101452 just for RISC-V
Reviewed By: MaskRay
Differential Revision: https://reviews.llvm.org/D101454
Added:
Modified:
lld/ELF/Arch/RISCV.cpp
lld/test/ELF/riscv-ifunc-nonpreemptible.s
Removed:
################################################################################
diff --git a/lld/ELF/Arch/RISCV.cpp b/lld/ELF/Arch/RISCV.cpp
index ca4178b18e76..0bb079274e59 100644
--- a/lld/ELF/Arch/RISCV.cpp
+++ b/lld/ELF/Arch/RISCV.cpp
@@ -26,6 +26,7 @@ class RISCV final : public TargetInfo {
uint32_t calcEFlags() const override;
void writeGotHeader(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;
@@ -147,6 +148,15 @@ void RISCV::writeGotPlt(uint8_t *buf, const Symbol &s) const {
write32le(buf, in.plt->getVA());
}
+void RISCV::writeIgotPlt(uint8_t *buf, const Symbol &s) const {
+ if (config->writeAddends) {
+ if (config->is64)
+ write64le(buf, s.getVA());
+ else
+ write32le(buf, s.getVA());
+ }
+}
+
void RISCV::writePltHeader(uint8_t *buf) const {
// 1: auipc t2, %pcrel_hi(.got.plt)
// sub t1, t1, t3
diff --git a/lld/test/ELF/riscv-ifunc-nonpreemptible.s b/lld/test/ELF/riscv-ifunc-nonpreemptible.s
index 99d75a28a391..0ab322961898 100644
--- a/lld/test/ELF/riscv-ifunc-nonpreemptible.s
+++ b/lld/test/ELF/riscv-ifunc-nonpreemptible.s
@@ -1,19 +1,27 @@
# REQUIRES: riscv
# RUN: llvm-mc -filetype=obj -triple=riscv32 %s -o %t.32.o
# RUN: ld.lld -pie %t.32.o -o %t.32
-# RUN: llvm-readobj -r %t.32 | FileCheck --check-prefix=RELOC32 %s
+# RUN: ld.lld -pie %t.32.o -o %t.32-apply --apply-dynamic-relocs
+# RUN: llvm-readobj -r -x .got.plt %t.32 | FileCheck --check-prefixes=RELOC32,NO-APPLY-RELOC32 %s
+# RUN: llvm-readobj -r -x .got.plt %t.32-apply | FileCheck --check-prefixes=RELOC32,APPLY-RELOC32 %s
# RUN: llvm-readelf -s %t.32 | FileCheck --check-prefix=SYM32 %s
# RUN: llvm-objdump -d --no-show-raw-insn %t.32 | FileCheck --check-prefix=DIS32 %s
# RUN: llvm-mc -filetype=obj -triple=riscv64 %s -o %t.64.o
# RUN: ld.lld -pie %t.64.o -o %t.64
-# RUN: llvm-readobj -r %t.64 | FileCheck --check-prefix=RELOC64 %s
+# RUN: ld.lld -pie %t.64.o -o %t.64-apply --apply-dynamic-relocs
+# RUN: llvm-readobj -r -x .got.plt %t.64 | FileCheck --check-prefixes=RELOC64,NO-APPLY-RELOC64 %s
+# RUN: llvm-readobj -r -x .got.plt %t.64-apply | FileCheck --check-prefixes=RELOC64,APPLY-RELOC64 %s
# RUN: llvm-readelf -s %t.64 | FileCheck --check-prefix=SYM64 %s
# RUN: llvm-objdump -d --no-show-raw-insn %t.64 | FileCheck --check-prefix=DIS64 %s
# RELOC32: .rela.dyn {
# RELOC32-NEXT: 0x3220 R_RISCV_IRELATIVE - 0x117C
# RELOC32-NEXT: }
+# RELOC32-LABEL: Hex dump of section '.got.plt':
+# NO-APPLY-RELOC32: 0x00003220 00000000
+# APPLY-RELOC32: 0x00003220 7c110000
+# RELOC32-EMPTY:
# SYM32: 0001190 0 FUNC GLOBAL DEFAULT {{.*}} func
@@ -31,6 +39,10 @@
# RELOC64: .rela.dyn {
# RELOC64-NEXT: 0x3380 R_RISCV_IRELATIVE - 0x1260
# RELOC64-NEXT: }
+# RELOC64-LABEL: Hex dump of section '.got.plt':
+# NO-APPLY-RELOC64: 0x00003380 00000000 00000000
+# APPLY-RELOC64: 0x00003380 60120000 00000000
+# RELOC64-EMPTY:
# SYM64: 000000000001270 0 FUNC GLOBAL DEFAULT {{.*}} func
More information about the llvm-commits
mailing list