[lld] r279456 - [ELF] ICF should respect section alignment
Petr Hosek via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 22 11:53:09 PDT 2016
Author: phosek
Date: Mon Aug 22 13:53:09 2016
New Revision: 279456
URL: http://llvm.org/viewvc/llvm-project?rev=279456&view=rev
Log:
[ELF] ICF should respect section alignment
When performing ICF, we have to respect the alignment requirement
of each section within each group.
Differential Revision: https://reviews.llvm.org/D23732
Modified:
lld/trunk/ELF/ICF.cpp
lld/trunk/test/ELF/icf7.s
Modified: lld/trunk/ELF/ICF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/ICF.cpp?rev=279456&r1=279455&r2=279456&view=diff
==============================================================================
--- lld/trunk/ELF/ICF.cpp (original)
+++ lld/trunk/ELF/ICF.cpp Mon Aug 22 13:53:09 2016
@@ -302,7 +302,11 @@ template <class ELFT> void ICF<ELFT>::ru
// the same group are consecutive in the vector.
std::stable_sort(V.begin(), V.end(),
[](InputSection<ELFT> *A, InputSection<ELFT> *B) {
- return A->GroupId < B->GroupId;
+ if (A->GroupId != B->GroupId)
+ return A->GroupId < B->GroupId;
+ // Within a group, put the highest alignment
+ // requirement first, so that's the one we'll keep.
+ return B->Alignment < A->Alignment;
});
// Compare static contents and assign unique IDs for each static content.
Modified: lld/trunk/test/ELF/icf7.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/icf7.s?rev=279456&r1=279455&r2=279456&view=diff
==============================================================================
--- lld/trunk/test/ELF/icf7.s (original)
+++ lld/trunk/test/ELF/icf7.s Mon Aug 22 13:53:09 2016
@@ -4,8 +4,8 @@
# RUN: ld.lld %t -o %t2 --icf=all --verbose | FileCheck %s
# RUN: llvm-objdump -t %t2 | FileCheck -check-prefix=ALIGN %s
-# CHECK: selected .text.f1
-# CHECK: removed .text.f2
+# CHECK: selected .text.f2
+# CHECK: removed .text.f1
# ALIGN: 0000000000011000 .text 00000000 _start
# ALIGN: 0000000000011100 .text 00000000 f1
More information about the llvm-commits
mailing list