[PATCH] D23732: [ELF] ICF should respect section alignment

Petr Hosek via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 22 12:01:19 PDT 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL279456: [ELF] ICF should respect section alignment (authored by phosek).

Changed prior to commit:
  https://reviews.llvm.org/D23732?vs=68797&id=68897#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D23732

Files:
  lld/trunk/ELF/ICF.cpp
  lld/trunk/test/ELF/icf7.s

Index: lld/trunk/test/ELF/icf7.s
===================================================================
--- lld/trunk/test/ELF/icf7.s
+++ lld/trunk/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.f1
-# CHECK:   removed .text.f2
+# CHECK: selected .text.f2
+# CHECK:   removed .text.f1
 
 # ALIGN: 0000000000011000 .text 00000000 _start
 # ALIGN: 0000000000011100 .text 00000000 f1
Index: lld/trunk/ELF/ICF.cpp
===================================================================
--- lld/trunk/ELF/ICF.cpp
+++ lld/trunk/ELF/ICF.cpp
@@ -302,7 +302,11 @@
   // 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.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D23732.68897.patch
Type: text/x-patch
Size: 1309 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160822/0e6a7068/attachment.bin>


More information about the llvm-commits mailing list