Simplify ICF alignment handling.
authorRui Ueyama <ruiu@google.com>
Mon, 5 Dec 2016 01:31:39 +0000 (01:31 +0000)
committerRui Ueyama <ruiu@google.com>
Mon, 5 Dec 2016 01:31:39 +0000 (01:31 +0000)
llvm-svn: 288630

lld/ELF/ICF.cpp
lld/ELF/InputSection.cpp
lld/test/ELF/icf7.s

index fbb0e01..002465e 100644 (file)
@@ -339,11 +339,7 @@ template <class ELFT> void ICF<ELFT>::run() {
   // the same color are consecutive in the vector.
   std::stable_sort(Sections.begin(), Sections.end(),
                    [](InputSection<ELFT> *A, InputSection<ELFT> *B) {
-                     if (A->Color[0] != B->Color[0])
-                       return A->Color[0] < B->Color[0];
-                     // Within a group, put the highest alignment
-                     // requirement first, so that's the one we'll keep.
-                     return B->Alignment < A->Alignment;
+                     return A->Color[0] < B->Color[0];
                    });
 
   // Compare static contents and assign unique IDs for each static content.
index 4e48721..067f629 100644 (file)
@@ -622,7 +622,7 @@ template <class ELFT> void InputSection<ELFT>::writeTo(uint8_t *Buf) {
 
 template <class ELFT>
 void InputSection<ELFT>::replace(InputSection<ELFT> *Other) {
-  assert(Other->Alignment <= this->Alignment);
+  this->Alignment = std::max(this->Alignment, Other->Alignment);
   Other->Repl = this->Repl;
   Other->Live = false;
 }
index fc96baf..8504ca2 100644 (file)
@@ -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.f2
-# CHECK:   removed .text.f1
+# CHECK: selected .text.f1
+# CHECK:   removed .text.f2
 
 # ALIGN: 0000000000201000 .text 00000000 _start
 # ALIGN: 0000000000201100 .text 00000000 f1