[llvm-branch-commits] [lld] e3ce92b - [ELF] --icf: don't fold a section without relocation and a section with relocations for SHT_REL
Tobias Hieta via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri Feb 24 00:43:05 PST 2023
Author: Fangrui Song
Date: 2023-02-24T09:42:46+01:00
New Revision: e3ce92b7a904c2b4f0acebdf433121b2e45e5f0c
URL: https://github.com/llvm/llvm-project/commit/e3ce92b7a904c2b4f0acebdf433121b2e45e5f0c
DIFF: https://github.com/llvm/llvm-project/commit/e3ce92b7a904c2b4f0acebdf433121b2e45e5f0c.diff
LOG: [ELF] --icf: don't fold a section without relocation and a section with relocations for SHT_REL
Fix https://github.com/llvm/llvm-project/issues/57693
(cherry picked from commit 686cff17cc310884e48ae963bf7507f96950cc90)
Added:
Modified:
lld/ELF/ICF.cpp
lld/test/ELF/icf10.s
Removed:
################################################################################
diff --git a/lld/ELF/ICF.cpp b/lld/ELF/ICF.cpp
index d7a85bcf844fa..c2b0ce9b12b9f 100644
--- a/lld/ELF/ICF.cpp
+++ b/lld/ELF/ICF.cpp
@@ -323,8 +323,9 @@ bool ICF<ELFT>::equalsConstant(const InputSection *a, const InputSection *b) {
const RelsOrRelas<ELFT> ra = a->template relsOrRelas<ELFT>();
const RelsOrRelas<ELFT> rb = b->template relsOrRelas<ELFT>();
- return ra.areRelocsRel() ? constantEq(a, ra.rels, b, rb.rels)
- : constantEq(a, ra.relas, b, rb.relas);
+ return ra.areRelocsRel() || rb.areRelocsRel()
+ ? constantEq(a, ra.rels, b, rb.rels)
+ : constantEq(a, ra.relas, b, rb.relas);
}
// Compare two lists of relocations. Returns true if all pairs of
@@ -371,8 +372,9 @@ template <class ELFT>
bool ICF<ELFT>::equalsVariable(const InputSection *a, const InputSection *b) {
const RelsOrRelas<ELFT> ra = a->template relsOrRelas<ELFT>();
const RelsOrRelas<ELFT> rb = b->template relsOrRelas<ELFT>();
- return ra.areRelocsRel() ? variableEq(a, ra.rels, b, rb.rels)
- : variableEq(a, ra.relas, b, rb.relas);
+ return ra.areRelocsRel() || rb.areRelocsRel()
+ ? variableEq(a, ra.rels, b, rb.rels)
+ : variableEq(a, ra.relas, b, rb.relas);
}
template <class ELFT> size_t ICF<ELFT>::findBoundary(size_t begin, size_t end) {
diff --git a/lld/test/ELF/icf10.s b/lld/test/ELF/icf10.s
index b782f9248448d..3c18c431c3b9d 100644
--- a/lld/test/ELF/icf10.s
+++ b/lld/test/ELF/icf10.s
@@ -1,5 +1,7 @@
# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=i686 %s -o %t.o
+# RUN: ld.lld --icf=all %t.o -o /dev/null --print-icf-sections 2>&1 | FileCheck %s
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-freebsd %s -o %t.o
# RUN: ld.lld --icf=all %t.o -o /dev/null --print-icf-sections 2>&1 | FileCheck %s
@@ -8,10 +10,13 @@
# CHECK-NOT: selected
+.section .text.orig,"ax"
+ .quad -1
+
.section .text.foo,"ax"
.quad -1
- .reloc 0, R_X86_64_NONE, 0
+ .reloc 0, BFD_RELOC_NONE, 0
.section .text.bar,"ax"
.quad -1
- .reloc 1, R_X86_64_NONE, 0
+ .reloc 1, BFD_RELOC_NONE, 0
More information about the llvm-branch-commits
mailing list