[lld] r194791 - [PECOFF] Minimum size of DOS stub is 64 byte.
Rui Ueyama
ruiu at google.com
Fri Nov 15 00:00:22 PST 2013
Author: ruiu
Date: Fri Nov 15 02:00:22 2013
New Revision: 194791
URL: http://llvm.org/viewvc/llvm-project?rev=194791&view=rev
Log:
[PECOFF] Minimum size of DOS stub is 64 byte.
Modified:
lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
lld/trunk/test/pecoff/dosstub.test
Modified: lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp?rev=194791&r1=194790&r2=194791&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp Fri Nov 15 02:00:22 2013
@@ -22,6 +22,7 @@
#define DEBUG_TYPE "WriterPECOFF"
+#include <algorithm>
#include <map>
#include <time.h>
#include <vector>
@@ -108,14 +109,17 @@ class DOSStubChunk : public HeaderChunk
public:
DOSStubChunk(const PECOFFLinkingContext &ctx)
: HeaderChunk(), _context(ctx) {
- _size = _context.getDosStub().size();
+ // Minimum size of DOS stub is 64 bytes. The next block (PE header) needs to
+ // be aligned on 8 byte boundary.
+ _size = std::max(_context.getDosStub().size(), 64UL);
+ _size = llvm::RoundUpToAlignment(_size, 8);
}
virtual void write(uint8_t *fileBuffer) {
ArrayRef<uint8_t> array = _context.getDosStub();
std::memcpy(fileBuffer, array.data(), array.size());
auto *header = reinterpret_cast<llvm::object::dos_header *>(fileBuffer);
- header->AddressOfNewExeHeader = array.size();
+ header->AddressOfNewExeHeader = _size;
}
private:
Modified: lld/trunk/test/pecoff/dosstub.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/dosstub.test?rev=194791&r1=194790&r2=194791&view=diff
==============================================================================
--- lld/trunk/test/pecoff/dosstub.test (original)
+++ lld/trunk/test/pecoff/dosstub.test Fri Nov 15 02:00:22 2013
@@ -2,6 +2,9 @@
# RUN: echo "MZ Hello world" > %t.stub
# RUN: lld -flavor link /out:%t.exe /entry:start /stub:%t.stub -- %t.obj
-# RUN: FileCheck %s < %t.exe
+# RUN: FileCheck -check-prefix=FILE %s < %t.exe
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=READOBJ %s
-CHECK: MZ Hello world
+FILE: MZ Hello world
+
+READOBJ: Format: COFF-i386
More information about the llvm-commits
mailing list