Skip to content

Commit 691b97c

Browse files
committed
[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
1 parent ef57977 commit 691b97c

5 files changed

+25
-39
lines changed

lld/ELF/SyntheticSections.cpp

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,13 +1285,7 @@ static uint64_t addRelaSz(const RelocationBaseSection &relaDyn) {
12851285
// output section. When this occurs we cannot just use the OutputSection
12861286
// Size. Moreover the [DT_JMPREL, DT_JMPREL + DT_PLTRELSZ) is permitted to
12871287
// overlap with the [DT_RELA, DT_RELA + DT_RELASZ).
1288-
static uint64_t addPltRelSz() {
1289-
size_t size = in.relaPlt->getSize();
1290-
if (in.relaIplt->getParent() == in.relaPlt->getParent() &&
1291-
in.relaIplt->name == in.relaPlt->name)
1292-
size += in.relaIplt->getSize();
1293-
return size;
1294-
}
1288+
static uint64_t addPltRelSz() { return in.relaPlt->getSize(); }
12951289

12961290
// Add remaining entries to complete .dynamic contents.
12971291
template <class ELFT>
@@ -1407,13 +1401,7 @@ DynamicSection<ELFT>::computeContents() {
14071401
addInt(config->useAndroidRelrTags ? DT_ANDROID_RELRENT : DT_RELRENT,
14081402
sizeof(Elf_Relr));
14091403
}
1410-
// .rel[a].plt section usually consists of two parts, containing plt and
1411-
// iplt relocations. It is possible to have only iplt relocations in the
1412-
// output. In that case relaPlt is empty and have zero offset, the same offset
1413-
// as relaIplt has. And we still want to emit proper dynamic tags for that
1414-
// case, so here we always use relaPlt as marker for the beginning of
1415-
// .rel[a].plt section.
1416-
if (isMain && (in.relaPlt->isNeeded() || in.relaIplt->isNeeded())) {
1404+
if (isMain && in.relaPlt->isNeeded()) {
14171405
addInSec(DT_JMPREL, *in.relaPlt);
14181406
entries.emplace_back(DT_PLTRELSZ, addPltRelSz());
14191407
switch (config->emachine) {

lld/test/ELF/aarch64-gnu-ifunc-nonpreemptable.s

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,14 @@ main:
6565
# PIE-EMPTY:
6666
# PIE-NEXT: <myfunc>:
6767
# PIE-NEXT: 10270: adrp x16, 0x30000
68-
# PIE-NEXT: 10274: ldr x17, [x16, #896]
69-
# PIE-NEXT: 10278: add x16, x16, #896
70-
# PIE-NEXT: 1027c: br x17
68+
# PIE-NEXT: ldr x17, [x16, #832]
69+
# PIE-NEXT: add x16, x16, #832
70+
# PIE-NEXT: br x17
7171

7272
# PIE-RELOC: .rela.dyn {
73-
# PIE-RELOC-NEXT: 0x30380 R_AARCH64_IRELATIVE - 0x10260
73+
# PIE-RELOC-NEXT: 0x30340 R_AARCH64_IRELATIVE - 0x10260
7474
# PIE-RELOC-NEXT: }
7575
# PIE-RELOC: Hex dump of section '.got.plt':
76-
# NO-APPLY: 0x00030380 00000000 00000000
77-
# APPLY: 0x00030380 60020100 00000000
76+
# NO-APPLY: 0x00030340 00000000 00000000
77+
# APPLY: 0x00030340 60020100 00000000
7878
# PIE-RELOC-EMPTY:

lld/test/ELF/gnu-ifunc-dyntags.s

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@
99

1010
# CHECK: Name Size VMA
1111
# CHECK: .rela.dyn 00000030 0000000000000248
12-
# CHECK: .got.plt 00000010 00000000000033b0
12+
# CHECK: .got.plt 00000010 0000000000003370
1313

1414
# TAGS: Tag Type Name/Value
1515
# TAGS: 0x0000000000000007 RELA 0x248
1616
# TAGS: 0x0000000000000008 RELASZ 48 (bytes)
17-
# TAGS: 0x0000000000000017 JMPREL 0x0
18-
# TAGS: 0x0000000000000002 PLTRELSZ 0 (bytes)
19-
# TAGS: 0x0000000000000003 PLTGOT 0x33B0
20-
# TAGS: 0x0000000000000014 PLTREL RELA
17+
# TAGS-NOT: JMPREL
18+
# TAGS-NOT: PLTREL
2119

2220
# TAGS: Relocations [
2321
# TAGS-NEXT: Section {{.*}} .rela.dyn {

lld/test/ELF/ppc32-ifunc-nonpreemptible-pic.s

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@
1010
# RUN: llvm-readelf -x .got2 %t | FileCheck --check-prefix=HEX2 %s
1111

1212
# RELOC: .rela.dyn {
13-
# RELOC-NEXT: 0x3024C R_PPC_RELATIVE - 0x101A0
14-
# RELOC-NEXT: 0x30250 R_PPC_IRELATIVE - 0x10188
13+
# RELOC-NEXT: 0x3022C R_PPC_RELATIVE - 0x101A0
14+
# RELOC-NEXT: 0x30230 R_PPC_IRELATIVE - 0x10188
1515
# RELOC-NEXT: }
1616

1717
# SYM: 000101a0 0 FUNC GLOBAL DEFAULT {{.*}} func
1818
# HEX: Hex dump of section '.got2':
19-
# HEX-NEXT: 0x0003024c 00000000 ....
19+
# HEX-NEXT: 0x0003022c 00000000 ....
2020

2121
# HEX2: Hex dump of section '.got2':
22-
# HEX2-NEXT: 0x0003024c 000101a0 ....
22+
# HEX2-NEXT: 0x0003022c 000101a0 ....
2323

2424
.section .got2,"aw"
2525
.long func

lld/test/ELF/riscv-ifunc-nonpreemptible.s

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
# RUN: llvm-objdump -d --no-show-raw-insn %t.64 | FileCheck --check-prefix=DIS64 %s
1717

1818
# RELOC32: .rela.dyn {
19-
# RELOC32-NEXT: 0x3220 R_RISCV_IRELATIVE - 0x117C
19+
# RELOC32-NEXT: 0x3200 R_RISCV_IRELATIVE - 0x117C
2020
# RELOC32-NEXT: }
2121
# RELOC32-LABEL: Hex dump of section '.got.plt':
22-
# NO-APPLY-RELOC32: 0x00003220 00000000
23-
# APPLY-RELOC32: 0x00003220 7c110000
22+
# NO-APPLY-RELOC32: 0x00003200 00000000
23+
# APPLY-RELOC32: 0x00003200 7c110000
2424
# RELOC32-EMPTY:
2525

2626
# SYM32: 0001190 0 FUNC GLOBAL DEFAULT {{.*}} func
@@ -30,18 +30,18 @@
3030
# DIS32-NEXT: addi a0, a0, 0x10
3131
# DIS32: Disassembly of section .iplt:
3232
# DIS32: <func>:
33-
## 32-bit: &.got.plt[func]-. = 0x3220-0x1190 = 4096*2+144
33+
## 32-bit: &.got.plt[func]-. = 0x3200-0x1190 = 4096*2+0x70
3434
# DIS32-NEXT: 1190: auipc t3, 0x2
35-
# DIS32-NEXT: lw t3, 0x90(t3)
35+
# DIS32-NEXT: lw t3, 0x70(t3)
3636
# DIS32-NEXT: jalr t1, t3
3737
# DIS32-NEXT: nop
3838

3939
# RELOC64: .rela.dyn {
40-
# RELOC64-NEXT: 0x3380 R_RISCV_IRELATIVE - 0x1260
40+
# RELOC64-NEXT: 0x3340 R_RISCV_IRELATIVE - 0x1260
4141
# RELOC64-NEXT: }
4242
# RELOC64-LABEL: Hex dump of section '.got.plt':
43-
# NO-APPLY-RELOC64: 0x00003380 00000000 00000000
44-
# APPLY-RELOC64: 0x00003380 60120000 00000000
43+
# NO-APPLY-RELOC64: 0x00003340 00000000 00000000
44+
# APPLY-RELOC64: 0x00003340 60120000 00000000
4545
# RELOC64-EMPTY:
4646

4747
# SYM64: 000000000001270 0 FUNC GLOBAL DEFAULT {{.*}} func
@@ -51,9 +51,9 @@
5151
# DIS64-NEXT: addi a0, a0, 0xc
5252
# DIS64: Disassembly of section .iplt:
5353
# DIS64: <func>:
54-
## 64-bit: &.got.plt[func]-. = 0x3380-0x1270 = 4096*2+272
54+
## 64-bit: &.got.plt[func]-. = 0x3340-0x1270 = 4096*2+0xd0
5555
# DIS64-NEXT: 1270: auipc t3, 0x2
56-
# DIS64-NEXT: ld t3, 0x110(t3)
56+
# DIS64-NEXT: ld t3, 0xd0(t3)
5757
# DIS64-NEXT: jalr t1, t3
5858
# DIS64-NEXT: nop
5959

0 commit comments

Comments
 (0)