[lld] 691b97c - [ELF] Remove zero-value DT_JMPREL when IPLT is present while PLT isn't
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sat Mar 23 01:02:14 PDT 2024
Author: Fangrui Song
Date: 2024-03-23T01:02:08-07:00
New Revision: 691b97c884a15a7eac641ddf67c9f2f30fb4e747
URL: https://github.com/llvm/llvm-project/commit/691b97c884a15a7eac641ddf67c9f2f30fb4e747
DIFF: https://github.com/llvm/llvm-project/commit/691b97c884a15a7eac641ddf67c9f2f30fb4e747.diff
LOG: [ELF] Remove zero-value DT_JMPREL when IPLT is present while PLT isn't
The zero-value DT_JMPREL is benign but not needed.
This is also code simplification available after https://reviews.llvm.org/D65651
Added:
Modified:
lld/ELF/SyntheticSections.cpp
lld/test/ELF/aarch64-gnu-ifunc-nonpreemptable.s
lld/test/ELF/gnu-ifunc-dyntags.s
lld/test/ELF/ppc32-ifunc-nonpreemptible-pic.s
lld/test/ELF/riscv-ifunc-nonpreemptible.s
Removed:
################################################################################
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index 248ff6b4a865a3..10eda17f0cb3dc 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -1285,13 +1285,7 @@ static uint64_t addRelaSz(const RelocationBaseSection &relaDyn) {
// output section. When this occurs we cannot just use the OutputSection
// Size. Moreover the [DT_JMPREL, DT_JMPREL + DT_PLTRELSZ) is permitted to
// overlap with the [DT_RELA, DT_RELA + DT_RELASZ).
-static uint64_t addPltRelSz() {
- size_t size = in.relaPlt->getSize();
- if (in.relaIplt->getParent() == in.relaPlt->getParent() &&
- in.relaIplt->name == in.relaPlt->name)
- size += in.relaIplt->getSize();
- return size;
-}
+static uint64_t addPltRelSz() { return in.relaPlt->getSize(); }
// Add remaining entries to complete .dynamic contents.
template <class ELFT>
@@ -1407,13 +1401,7 @@ DynamicSection<ELFT>::computeContents() {
addInt(config->useAndroidRelrTags ? DT_ANDROID_RELRENT : DT_RELRENT,
sizeof(Elf_Relr));
}
- // .rel[a].plt section usually consists of two parts, containing plt and
- // iplt relocations. It is possible to have only iplt relocations in the
- // output. In that case relaPlt is empty and have zero offset, the same offset
- // as relaIplt has. And we still want to emit proper dynamic tags for that
- // case, so here we always use relaPlt as marker for the beginning of
- // .rel[a].plt section.
- if (isMain && (in.relaPlt->isNeeded() || in.relaIplt->isNeeded())) {
+ if (isMain && in.relaPlt->isNeeded()) {
addInSec(DT_JMPREL, *in.relaPlt);
entries.emplace_back(DT_PLTRELSZ, addPltRelSz());
switch (config->emachine) {
diff --git a/lld/test/ELF/aarch64-gnu-ifunc-nonpreemptable.s b/lld/test/ELF/aarch64-gnu-ifunc-nonpreemptable.s
index 4f33dde9d1a9e5..54a27a8cc0d9f5 100644
--- a/lld/test/ELF/aarch64-gnu-ifunc-nonpreemptable.s
+++ b/lld/test/ELF/aarch64-gnu-ifunc-nonpreemptable.s
@@ -65,14 +65,14 @@ main:
# PIE-EMPTY:
# PIE-NEXT: <myfunc>:
# PIE-NEXT: 10270: adrp x16, 0x30000
-# PIE-NEXT: 10274: ldr x17, [x16, #896]
-# PIE-NEXT: 10278: add x16, x16, #896
-# PIE-NEXT: 1027c: br x17
+# PIE-NEXT: ldr x17, [x16, #832]
+# PIE-NEXT: add x16, x16, #832
+# PIE-NEXT: br x17
# PIE-RELOC: .rela.dyn {
-# PIE-RELOC-NEXT: 0x30380 R_AARCH64_IRELATIVE - 0x10260
+# PIE-RELOC-NEXT: 0x30340 R_AARCH64_IRELATIVE - 0x10260
# PIE-RELOC-NEXT: }
# PIE-RELOC: Hex dump of section '.got.plt':
-# NO-APPLY: 0x00030380 00000000 00000000
-# APPLY: 0x00030380 60020100 00000000
+# NO-APPLY: 0x00030340 00000000 00000000
+# APPLY: 0x00030340 60020100 00000000
# PIE-RELOC-EMPTY:
diff --git a/lld/test/ELF/gnu-ifunc-dyntags.s b/lld/test/ELF/gnu-ifunc-dyntags.s
index fd80dc24f2f8e8..57a17245a3e880 100644
--- a/lld/test/ELF/gnu-ifunc-dyntags.s
+++ b/lld/test/ELF/gnu-ifunc-dyntags.s
@@ -9,15 +9,13 @@
# CHECK: Name Size VMA
# CHECK: .rela.dyn 00000030 0000000000000248
-# CHECK: .got.plt 00000010 00000000000033b0
+# CHECK: .got.plt 00000010 0000000000003370
# TAGS: Tag Type Name/Value
# TAGS: 0x0000000000000007 RELA 0x248
# TAGS: 0x0000000000000008 RELASZ 48 (bytes)
-# TAGS: 0x0000000000000017 JMPREL 0x0
-# TAGS: 0x0000000000000002 PLTRELSZ 0 (bytes)
-# TAGS: 0x0000000000000003 PLTGOT 0x33B0
-# TAGS: 0x0000000000000014 PLTREL RELA
+# TAGS-NOT: JMPREL
+# TAGS-NOT: PLTREL
# TAGS: Relocations [
# TAGS-NEXT: Section {{.*}} .rela.dyn {
diff --git a/lld/test/ELF/ppc32-ifunc-nonpreemptible-pic.s b/lld/test/ELF/ppc32-ifunc-nonpreemptible-pic.s
index a93f3cecb0c6c1..c9a0381b610a46 100644
--- a/lld/test/ELF/ppc32-ifunc-nonpreemptible-pic.s
+++ b/lld/test/ELF/ppc32-ifunc-nonpreemptible-pic.s
@@ -10,16 +10,16 @@
# RUN: llvm-readelf -x .got2 %t | FileCheck --check-prefix=HEX2 %s
# RELOC: .rela.dyn {
-# RELOC-NEXT: 0x3024C R_PPC_RELATIVE - 0x101A0
-# RELOC-NEXT: 0x30250 R_PPC_IRELATIVE - 0x10188
+# RELOC-NEXT: 0x3022C R_PPC_RELATIVE - 0x101A0
+# RELOC-NEXT: 0x30230 R_PPC_IRELATIVE - 0x10188
# RELOC-NEXT: }
# SYM: 000101a0 0 FUNC GLOBAL DEFAULT {{.*}} func
# HEX: Hex dump of section '.got2':
-# HEX-NEXT: 0x0003024c 00000000 ....
+# HEX-NEXT: 0x0003022c 00000000 ....
# HEX2: Hex dump of section '.got2':
-# HEX2-NEXT: 0x0003024c 000101a0 ....
+# HEX2-NEXT: 0x0003022c 000101a0 ....
.section .got2,"aw"
.long func
diff --git a/lld/test/ELF/riscv-ifunc-nonpreemptible.s b/lld/test/ELF/riscv-ifunc-nonpreemptible.s
index 21c6075451104b..eda5548eef8b99 100644
--- a/lld/test/ELF/riscv-ifunc-nonpreemptible.s
+++ b/lld/test/ELF/riscv-ifunc-nonpreemptible.s
@@ -16,11 +16,11 @@
# 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: 0x3200 R_RISCV_IRELATIVE - 0x117C
# RELOC32-NEXT: }
# RELOC32-LABEL: Hex dump of section '.got.plt':
-# NO-APPLY-RELOC32: 0x00003220 00000000
-# APPLY-RELOC32: 0x00003220 7c110000
+# NO-APPLY-RELOC32: 0x00003200 00000000
+# APPLY-RELOC32: 0x00003200 7c110000
# RELOC32-EMPTY:
# SYM32: 0001190 0 FUNC GLOBAL DEFAULT {{.*}} func
@@ -30,18 +30,18 @@
# DIS32-NEXT: addi a0, a0, 0x10
# DIS32: Disassembly of section .iplt:
# DIS32: <func>:
-## 32-bit: &.got.plt[func]-. = 0x3220-0x1190 = 4096*2+144
+## 32-bit: &.got.plt[func]-. = 0x3200-0x1190 = 4096*2+0x70
# DIS32-NEXT: 1190: auipc t3, 0x2
-# DIS32-NEXT: lw t3, 0x90(t3)
+# DIS32-NEXT: lw t3, 0x70(t3)
# DIS32-NEXT: jalr t1, t3
# DIS32-NEXT: nop
# RELOC64: .rela.dyn {
-# RELOC64-NEXT: 0x3380 R_RISCV_IRELATIVE - 0x1260
+# RELOC64-NEXT: 0x3340 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
+# NO-APPLY-RELOC64: 0x00003340 00000000 00000000
+# APPLY-RELOC64: 0x00003340 60120000 00000000
# RELOC64-EMPTY:
# SYM64: 000000000001270 0 FUNC GLOBAL DEFAULT {{.*}} func
@@ -51,9 +51,9 @@
# DIS64-NEXT: addi a0, a0, 0xc
# DIS64: Disassembly of section .iplt:
# DIS64: <func>:
-## 64-bit: &.got.plt[func]-. = 0x3380-0x1270 = 4096*2+272
+## 64-bit: &.got.plt[func]-. = 0x3340-0x1270 = 4096*2+0xd0
# DIS64-NEXT: 1270: auipc t3, 0x2
-# DIS64-NEXT: ld t3, 0x110(t3)
+# DIS64-NEXT: ld t3, 0xd0(t3)
# DIS64-NEXT: jalr t1, t3
# DIS64-NEXT: nop
More information about the llvm-commits
mailing list