Files
clang-p2996/lld/test/pecoff/hello.test
Rui Ueyama 140f6029ce [PECOFF] Fix section header.
The PE/COFF spec says that SizeOfRawData field in the section
header must be a multiple of FileAlignment from the optional
header. LLD emits 512 as FileAlignment, so it must have been
a multiple of 512.

LLD did not follow that. It emitted the actual section size
without the last padding as the SizeOfRawData. Although it's
not correct as per the spec, the Windows loader doesn't seem
to actually bother to check that. Executables created by LLD
worked fine.

However, tools dealing with executalbe files may expect it
to be the correct value, and one instance of it is mt.exe
tool distributed as a part of Windows SDK.

If CMake is invoked with "-E vs_link_exe" option, it silently
run mt.exe to embed a resource file to the resulting file.
And mt.exe sometimes breaks an input file if it's section
header does not follow the standard. That caused a misterous
error that CMake with Ninja occasionally produces a broken
executable.

This patch fixes the section header to make mt.exe and
other tools happy.

llvm-svn: 214453
2014-07-31 22:40:35 +00:00

52 lines
1.8 KiB
Plaintext

# RUN: yaml2obj %p/Inputs/hello.obj.yaml > %t.obj
# RUN: lld -flavor link /out:%t1.exe /subsystem:console /force -- %t.obj
# RUN: llvm-readobj -file-headers %t1.exe | FileCheck -check-prefix=FILE %s
FILE: ImageOptionalHeader {
FILE: SizeOfInitializedData: 1024
FILE: SizeOfHeaders: 512
FILE: }
# RUN: lld -flavor link /out:%t2.exe /subsystem:console /force -- %t.obj
# RUN: llvm-readobj -sections %t2.exe | FileCheck -check-prefix=SECTIONS %s
SECTIONS: Format: COFF-i386
SECTIONS-NEXT: Arch: i386
SECTIONS-NEXT: AddressSize: 32bit
SECTIONS-NEXT: Sections [
SECTIONS-NEXT: Section {
SECTIONS-NEXT: Number: 1
SECTIONS-NEXT: Name: .data
SECTIONS-NEXT: VirtualSize: 0x12
SECTIONS-NEXT: VirtualAddress: 0x1000
SECTIONS-NEXT: RawDataSize: 512
SECTIONS-NEXT: PointerToRawData: 0x200
SECTIONS-NEXT: PointerToRelocations: 0x0
SECTIONS-NEXT: PointerToLineNumbers: 0x0
SECTIONS-NEXT: RelocationCount: 0
SECTIONS-NEXT: LineNumberCount: 0
SECTIONS-NEXT: Characteristics [
SECTIONS-NEXT: IMAGE_SCN_CNT_INITIALIZED_DATA
SECTIONS-NEXT: IMAGE_SCN_MEM_READ
SECTIONS-NEXT: IMAGE_SCN_MEM_WRITE
SECTIONS-NEXT: ]
SECTIONS-NEXT: }
SECTIONS-NEXT: Section {
SECTIONS-NEXT: Number: 2
SECTIONS-NEXT: Name: .text (2E 74 65 78 74 00 00 00)
SECTIONS-NEXT: VirtualSize: 0x1C
SECTIONS-NEXT: VirtualAddress: 0x2000
SECTIONS-NEXT: RawDataSize: 512
SECTIONS-NEXT: PointerToRawData: 0x400
SECTIONS-NEXT: PointerToRelocations: 0x0
SECTIONS-NEXT: PointerToLineNumbers: 0x0
SECTIONS-NEXT: RelocationCount: 0
SECTIONS-NEXT: LineNumberCount: 0
SECTIONS-NEXT: Characteristics [
SECTIONS-NEXT: IMAGE_SCN_CNT_CODE
SECTIONS-NEXT: IMAGE_SCN_MEM_EXECUTE
SECTIONS-NEXT: IMAGE_SCN_MEM_READ
SECTIONS-NEXT: ]
SECTIONS-NEXT: }