From 5cb712ed3c63fb77d39247aaad914c37af2a53f2 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Mon, 5 Dec 2016 01:31:39 +0000 Subject: [PATCH] Simplify ICF alignment handling. llvm-svn: 288630 --- lld/ELF/ICF.cpp | 6 +----- lld/ELF/InputSection.cpp | 2 +- lld/test/ELF/icf7.s | 4 ++-- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/lld/ELF/ICF.cpp b/lld/ELF/ICF.cpp index fbb0e018ec18..002465ed8a86 100644 --- a/lld/ELF/ICF.cpp +++ b/lld/ELF/ICF.cpp @@ -339,11 +339,7 @@ template void ICF::run() { // the same color are consecutive in the vector. std::stable_sort(Sections.begin(), Sections.end(), [](InputSection *A, InputSection *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. diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp index 4e48721f7256..067f6295f294 100644 --- a/lld/ELF/InputSection.cpp +++ b/lld/ELF/InputSection.cpp @@ -622,7 +622,7 @@ template void InputSection::writeTo(uint8_t *Buf) { template void InputSection::replace(InputSection *Other) { - assert(Other->Alignment <= this->Alignment); + this->Alignment = std::max(this->Alignment, Other->Alignment); Other->Repl = this->Repl; Other->Live = false; } diff --git a/lld/test/ELF/icf7.s b/lld/test/ELF/icf7.s index fc96baf381d3..8504ca2ac610 100644 --- a/lld/test/ELF/icf7.s +++ b/lld/test/ELF/icf7.s @@ -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