Skip to content

Commit 686cff1

Browse files
committed
[ELF] --icf: don't fold a section without relocation and a section with relocations for SHT_REL
Fix llvm#57693
1 parent 1b9b4f3 commit 686cff1

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

lld/ELF/ICF.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,9 @@ bool ICF<ELFT>::equalsConstant(const InputSection *a, const InputSection *b) {
323323

324324
const RelsOrRelas<ELFT> ra = a->template relsOrRelas<ELFT>();
325325
const RelsOrRelas<ELFT> rb = b->template relsOrRelas<ELFT>();
326-
return ra.areRelocsRel() ? constantEq(a, ra.rels, b, rb.rels)
327-
: constantEq(a, ra.relas, b, rb.relas);
326+
return ra.areRelocsRel() || rb.areRelocsRel()
327+
? constantEq(a, ra.rels, b, rb.rels)
328+
: constantEq(a, ra.relas, b, rb.relas);
328329
}
329330

330331
// Compare two lists of relocations. Returns true if all pairs of
@@ -371,8 +372,9 @@ template <class ELFT>
371372
bool ICF<ELFT>::equalsVariable(const InputSection *a, const InputSection *b) {
372373
const RelsOrRelas<ELFT> ra = a->template relsOrRelas<ELFT>();
373374
const RelsOrRelas<ELFT> rb = b->template relsOrRelas<ELFT>();
374-
return ra.areRelocsRel() ? variableEq(a, ra.rels, b, rb.rels)
375-
: variableEq(a, ra.relas, b, rb.relas);
375+
return ra.areRelocsRel() || rb.areRelocsRel()
376+
? variableEq(a, ra.rels, b, rb.rels)
377+
: variableEq(a, ra.relas, b, rb.relas);
376378
}
377379

378380
template <class ELFT> size_t ICF<ELFT>::findBoundary(size_t begin, size_t end) {

lld/test/ELF/icf10.s

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# REQUIRES: x86
22

3+
# RUN: llvm-mc -filetype=obj -triple=i686 %s -o %t.o
4+
# RUN: ld.lld --icf=all %t.o -o /dev/null --print-icf-sections 2>&1 | FileCheck %s
35
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-freebsd %s -o %t.o
46
# RUN: ld.lld --icf=all %t.o -o /dev/null --print-icf-sections 2>&1 | FileCheck %s
57

@@ -8,10 +10,13 @@
810

911
# CHECK-NOT: selected
1012

13+
.section .text.orig,"ax"
14+
.quad -1
15+
1116
.section .text.foo,"ax"
1217
.quad -1
13-
.reloc 0, R_X86_64_NONE, 0
18+
.reloc 0, BFD_RELOC_NONE, 0
1419

1520
.section .text.bar,"ax"
1621
.quad -1
17-
.reloc 1, R_X86_64_NONE, 0
22+
.reloc 1, BFD_RELOC_NONE, 0

0 commit comments

Comments
 (0)