[lld] r191212 - [lld][PECOFF] Calculate SizeOfHeaders field instead of using a hard-coded value
Ron Ofir
ron.ofir at gmail.com
Mon Sep 23 11:08:51 PDT 2013
Author: rono
Date: Mon Sep 23 13:08:51 2013
New Revision: 191212
URL: http://llvm.org/viewvc/llvm-project?rev=191212&view=rev
Log:
[lld][PECOFF] Calculate SizeOfHeaders field instead of using a hard-coded value
Summary: This patch changes WritePECOFF to calculate the value of the SizeOfHeaders PE header field instead of just using 512.
Reviewers: rui314, ruiu
Reviewed By: ruiu
CC: llvm-commits, ruiu
Differential Revision: http://llvm-reviews.chandlerc.com/D1708
Modified:
lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
lld/trunk/test/pecoff/hello.test
Modified: lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp?rev=191212&r1=191211&r2=191212&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp Mon Sep 23 13:08:51 2013
@@ -195,10 +195,6 @@ public:
_peHeader.MajorSubsystemVersion = minOSVersion.majorVersion;
_peHeader.MinorSubsystemVersion = minOSVersion.minorVersion;
- // The combined size of the DOS, PE and section headers including garbage
- // between the end of the header and the beginning of the first section.
- // Must be multiple of FileAlignment.
- _peHeader.SizeOfHeaders = 512;
_peHeader.Subsystem = context.getSubsystem();
// Despite its name, DLL characteristics field has meaning both for
@@ -233,6 +229,11 @@ public:
fileBuffer += sizeof(_coffHeader);
std::memcpy(fileBuffer, &_peHeader, sizeof(_peHeader));
}
+
+ virtual void setSizeOfHeaders(uint64_t size) {
+ // Must be multiple of FileAlignment.
+ _peHeader.SizeOfHeaders = llvm::RoundUpToAlignment(size, SECTOR_SIZE);
+ }
virtual void setSizeOfCode(uint64_t size) {
_peHeader.SizeOfCode = size;
@@ -842,6 +843,11 @@ public:
peHeader->setSizeOfUninitializedData(calcSizeOfUninitializedData());
peHeader->setNumberOfSections(_numSections);
peHeader->setSizeOfImage(_imageSizeInMemory);
+
+ // The combined size of the DOS, PE and section headers including garbage
+ // between the end of the header and the beginning of the first section.
+ peHeader->setSizeOfHeaders(dosStub->size() + peHeader->size() +
+ sectionTable->size() + dataDirectory->size());
setAddressOfEntryPoint(text, peHeader);
}
Modified: lld/trunk/test/pecoff/hello.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/hello.test?rev=191212&r1=191211&r2=191212&view=diff
==============================================================================
--- lld/trunk/test/pecoff/hello.test (original)
+++ lld/trunk/test/pecoff/hello.test Mon Sep 23 13:08:51 2013
@@ -6,6 +6,7 @@
FILE: ImageOptionalHeader {
FILE: SizeOfInitializedData: 1024
+FILE: SizeOfHeaders: 512
FILE: }
# RUN: lld -flavor link /out:%t1 /subsystem:console /force /opt:noref \
More information about the llvm-commits
mailing list