[lld] r193385 - [PECOFF] Handle edge case where no section alignment is specified.
Rui Ueyama
ruiu at google.com
Thu Oct 24 17:54:13 PDT 2013
Author: ruiu
Date: Thu Oct 24 19:54:13 2013
New Revision: 193385
URL: http://llvm.org/viewvc/llvm-project?rev=193385&view=rev
Log:
[PECOFF] Handle edge case where no section alignment is specified.
Modified:
lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp
lld/trunk/test/pecoff/Inputs/alignment.obj.yaml
lld/trunk/test/pecoff/alignment.test
Modified: lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp?rev=193385&r1=193384&r2=193385&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp Thu Oct 24 19:54:13 2013
@@ -92,10 +92,20 @@ DefinedAtom::ContentPermissions getPermi
DefinedAtom::Alignment getAlignment(const coff_section *section) {
if (section->Characteristics & llvm::COFF::IMAGE_SCN_TYPE_NO_PAD)
return DefinedAtom::Alignment(0);
+
// Bit [20:24] contains section alignment information. We need to decrease
// the value stored by 1 in order to get the real exponent (e.g, ALIGN_1BYTE
// is 0x00100000, but the exponent should be 0)
- int powerOf2 = ((section->Characteristics >> 20) & 0xf) - 1;
+ uint32_t charactersitcis = (section->Characteristics >> 20) & 0xf;
+
+ // If all bits are off, we treat it as if ALIGN_1BYTE was on. The PE/COFF spec
+ // does not say anything about this case, but CVTRES.EXE does not set any bit
+ // in characteristics[20:24], and its output is intended to be copied to .rsrc
+ // section with no padding, so I think doing this is the right thing.
+ if (charactersitcis == 0)
+ return DefinedAtom::Alignment(0);
+
+ uint32_t powerOf2 = charactersitcis - 1;
return DefinedAtom::Alignment(powerOf2);
}
Modified: lld/trunk/test/pecoff/Inputs/alignment.obj.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/Inputs/alignment.obj.yaml?rev=193385&r1=193384&r2=193385&view=diff
==============================================================================
--- lld/trunk/test/pecoff/Inputs/alignment.obj.yaml (original)
+++ lld/trunk/test/pecoff/Inputs/alignment.obj.yaml Thu Oct 24 19:54:13 2013
@@ -6,22 +6,23 @@ sections:
- Name: .text
Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
Alignment: 256
- SectionData: 5589E583EC14C745FC00000000C744240C00000000C744240807000000C744240400000000C7042400000000FF150000000083EC1031C083C4145DC3
- Relocations:
- - VirtualAddress: 25
- SymbolName: .data
- Type: IMAGE_REL_I386_DIR32
- - VirtualAddress: 33
- SymbolName: .data
- Type: IMAGE_REL_I386_DIR32
+ SectionData: CC
- Name: .text$1
Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
Alignment: 4096
SectionData: 00
- - Name: .data
+ - Name: .data$1
Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
Alignment: 4
- SectionData: 576F726C64210048656C6C6F2C00
+ SectionData: 00
+ - Name: .data$2
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
+ Alignment: 4
+ SectionData: 11
+ - Name: .data$3
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
+ Alignment: 0
+ SectionData: 22
symbols:
- Name: .text
Value: 0
@@ -29,16 +30,30 @@ symbols:
SimpleType: IMAGE_SYM_TYPE_NULL
ComplexType: IMAGE_SYM_DTYPE_NULL
StorageClass: IMAGE_SYM_CLASS_STATIC
- NumberOfAuxSymbols: 1
- AuxiliaryData: 3C0000000300000000000000010000000000
- - Name: .data
+ - Name: .text$1
Value: 0
SectionNumber: 2
SimpleType: IMAGE_SYM_TYPE_NULL
ComplexType: IMAGE_SYM_DTYPE_NULL
StorageClass: IMAGE_SYM_CLASS_STATIC
- NumberOfAuxSymbols: 1
- AuxiliaryData: 0E0000000000000000000000020000000000
+ - Name: .data$1
+ Value: 0
+ SectionNumber: 3
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ - Name: .data$2
+ Value: 0
+ SectionNumber: 4
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ - Name: .data$3
+ Value: 0
+ SectionNumber: 5
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
- Name: _start
Value: 0
SectionNumber: 1
Modified: lld/trunk/test/pecoff/alignment.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/alignment.test?rev=193385&r1=193384&r2=193385&view=diff
==============================================================================
--- lld/trunk/test/pecoff/alignment.test (original)
+++ lld/trunk/test/pecoff/alignment.test Thu Oct 24 19:54:13 2013
@@ -3,4 +3,8 @@
# RUN: lld -flavor link /out:%t1 /subsystem:console /force /entry:start \
# RUN: -- %t.obj && llvm-readobj -sections %t1 | FileCheck %s
-CHECK: VirtualSize: 0x1001
+CHECK: Name: .text
+CHECK-NEXT: VirtualSize: 0x1001
+
+CHECK: Name: .data
+CHECK-NEXT: VirtualSize: 0x6
More information about the llvm-commits
mailing list