[lld] r332273 - COFF: Allow ICFing sections with different alignments.
Peter Collingbourne via llvm-commits
llvm-commits at lists.llvm.org
Mon May 14 11:36:51 PDT 2018
Author: pcc
Date: Mon May 14 11:36:51 2018
New Revision: 332273
URL: http://llvm.org/viewvc/llvm-project?rev=332273&view=rev
Log:
COFF: Allow ICFing sections with different alignments.
The combined section gets the maximum alignment of all sections.
Differential Revision: https://reviews.llvm.org/D46786
Modified:
lld/trunk/COFF/Chunks.cpp
lld/trunk/COFF/ICF.cpp
lld/trunk/test/COFF/icf-different-align.test
Modified: lld/trunk/COFF/Chunks.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Chunks.cpp?rev=332273&r1=332272&r2=332273&view=diff
==============================================================================
--- lld/trunk/COFF/Chunks.cpp (original)
+++ lld/trunk/COFF/Chunks.cpp Mon May 14 11:36:51 2018
@@ -438,6 +438,7 @@ ArrayRef<uint8_t> SectionChunk::getConte
}
void SectionChunk::replace(SectionChunk *Other) {
+ Alignment = std::max(Alignment, Other->Alignment);
Other->Repl = Repl;
Other->Live = false;
}
Modified: lld/trunk/COFF/ICF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/ICF.cpp?rev=332273&r1=332272&r2=332273&view=diff
==============================================================================
--- lld/trunk/COFF/ICF.cpp (original)
+++ lld/trunk/COFF/ICF.cpp Mon May 14 11:36:51 2018
@@ -67,8 +67,8 @@ private:
// Returns a hash value for S.
uint32_t ICF::getHash(SectionChunk *C) {
- return hash_combine(C->getOutputCharacteristics(), C->SectionName, C->Relocs.size(),
- C->Alignment, uint32_t(C->Header->SizeOfRawData),
+ return hash_combine(C->getOutputCharacteristics(), C->SectionName,
+ C->Relocs.size(), uint32_t(C->Header->SizeOfRawData),
C->Checksum, C->getContents());
}
@@ -168,7 +168,7 @@ bool ICF::equalsConstant(const SectionCh
// Compare section attributes and contents.
return A->getOutputCharacteristics() == B->getOutputCharacteristics() &&
- A->SectionName == B->SectionName && A->Alignment == B->Alignment &&
+ A->SectionName == B->SectionName &&
A->Header->SizeOfRawData == B->Header->SizeOfRawData &&
A->Checksum == B->Checksum && A->getContents() == B->getContents() &&
assocEquals(A, B);
Modified: lld/trunk/test/COFF/icf-different-align.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/icf-different-align.test?rev=332273&r1=332272&r2=332273&view=diff
==============================================================================
--- lld/trunk/test/COFF/icf-different-align.test (original)
+++ lld/trunk/test/COFF/icf-different-align.test Mon May 14 11:36:51 2018
@@ -2,9 +2,14 @@
# RUN: lld-link /entry:foo /out:%t.exe /subsystem:console /include:bar \
# RUN: /verbose %t.obj > %t.log 2>&1
# RUN: FileCheck %s < %t.log
+# RUN: llvm-objdump -s %t.exe | FileCheck --check-prefix=OBJDUMP %s
-# CHECK-NOT: Selected foo
-# CHECK-NOT: Removed bar
+# CHECK: Selected foo
+# CHECK: Removed bar
+
+# OBJDUMP: Contents of section .text:
+# OBJDUMP-NEXT: 140001000 00cccccc cccccccc cccccccc cccccccc
+# OBJDUMP-NEXT: 140001010 4883ec28 e8000000 004883c4 28c3
--- !COFF
header:
@@ -19,6 +24,10 @@ sections:
Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_LNK_COMDAT, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
Alignment: 16
SectionData: 4883EC28E8000000004883C428C3
+ - Name: '.text'
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 1
+ SectionData: 00
symbols:
- Name: '.text$mn'
Value: 0
More information about the llvm-commits
mailing list