COFF: ICF should not merge sectinos if their alignments are not the same.
There's actually a room to improve this patch. Instead of not merging sections that have different alignements, we can choose the section that has the largest alignment requirement among all sections that are otherwise considered the same. Then all section alignments are satisfied, so we can merge them. I don't know if that improvement could make any difference for real-world input, so I'll leave it alone. Would be interesting to revisit later. llvm-svn: 248581
This commit is contained in:
parent
c9e746b9e6
commit
548d22c073
|
@ -62,8 +62,8 @@ public:
|
|||
virtual void writeTo(uint8_t *Buf) const {}
|
||||
|
||||
// The writer sets and uses the addresses.
|
||||
uint64_t getRVA() { return RVA; }
|
||||
uint32_t getAlign() { return Align; }
|
||||
uint64_t getRVA() const { return RVA; }
|
||||
uint32_t getAlign() const { return Align; }
|
||||
void setRVA(uint64_t V) { RVA = V; }
|
||||
void setOutputSectionOff(uint64_t V) { OutputSectionOff = V; }
|
||||
|
||||
|
|
|
@ -85,6 +85,7 @@ uint64_t ICF::getHash(SectionChunk *C) {
|
|||
return hash_combine(C->getPermissions(),
|
||||
hash_value(C->SectionName),
|
||||
C->NumRelocs,
|
||||
C->getAlign(),
|
||||
uint32_t(C->Header->SizeOfRawData),
|
||||
C->Checksum);
|
||||
}
|
||||
|
@ -122,6 +123,7 @@ bool ICF::equalsConstant(const SectionChunk *A, const SectionChunk *B) {
|
|||
// Compare section attributes and contents.
|
||||
return A->getPermissions() == B->getPermissions() &&
|
||||
A->SectionName == B->SectionName &&
|
||||
A->getAlign() == B->getAlign() &&
|
||||
A->Header->SizeOfRawData == B->Header->SizeOfRawData &&
|
||||
A->Checksum == B->Checksum &&
|
||||
A->getContents() == B->getContents();
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
# RUN: yaml2obj < %s > %t.obj
|
||||
# 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
|
||||
|
||||
# CHECK-NOT: Selected foo
|
||||
# CHECK-NOT: Removed bar
|
||||
|
||||
---
|
||||
header:
|
||||
Machine: IMAGE_FILE_MACHINE_AMD64
|
||||
Characteristics: []
|
||||
sections:
|
||||
- Name: '.text$mn'
|
||||
Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_LNK_COMDAT, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
|
||||
Alignment: 8
|
||||
SectionData: 4883EC28E8000000004883C428C3
|
||||
- Name: '.text$mn'
|
||||
Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_LNK_COMDAT, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
|
||||
Alignment: 16
|
||||
SectionData: 4883EC28E8000000004883C428C3
|
||||
symbols:
|
||||
- Name: '.text$mn'
|
||||
Value: 0
|
||||
SectionNumber: 1
|
||||
SimpleType: IMAGE_SYM_TYPE_NULL
|
||||
ComplexType: IMAGE_SYM_DTYPE_NULL
|
||||
StorageClass: IMAGE_SYM_CLASS_STATIC
|
||||
SectionDefinition:
|
||||
Length: 14
|
||||
NumberOfRelocations: 0
|
||||
NumberOfLinenumbers: 0
|
||||
CheckSum: 1682752513
|
||||
Number: 0
|
||||
Selection: IMAGE_COMDAT_SELECT_NODUPLICATES
|
||||
- Name: '.text$mn'
|
||||
Value: 0
|
||||
SectionNumber: 2
|
||||
SimpleType: IMAGE_SYM_TYPE_NULL
|
||||
ComplexType: IMAGE_SYM_DTYPE_NULL
|
||||
StorageClass: IMAGE_SYM_CLASS_STATIC
|
||||
SectionDefinition:
|
||||
Length: 14
|
||||
NumberOfRelocations: 0
|
||||
NumberOfLinenumbers: 0
|
||||
CheckSum: 1682752513
|
||||
Number: 0
|
||||
Selection: IMAGE_COMDAT_SELECT_NODUPLICATES
|
||||
- Name: foo
|
||||
Value: 0
|
||||
SectionNumber: 1
|
||||
SimpleType: IMAGE_SYM_TYPE_NULL
|
||||
ComplexType: IMAGE_SYM_DTYPE_FUNCTION
|
||||
StorageClass: IMAGE_SYM_CLASS_EXTERNAL
|
||||
- Name: bar
|
||||
Value: 0
|
||||
SectionNumber: 2
|
||||
SimpleType: IMAGE_SYM_TYPE_NULL
|
||||
ComplexType: IMAGE_SYM_DTYPE_FUNCTION
|
||||
StorageClass: IMAGE_SYM_CLASS_EXTERNAL
|
||||
...
|
Loading…
Reference in New Issue