[PATCH] D44018: [COFF] Make the DOS stub a real DOS program

Rui Ueyama via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 2 11:04:14 PST 2018

ruiu added inline comments.

Comment at: COFF/Writer.cpp:64
+static unsigned char DOSProgram[] = {
+  0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd, 0x21, 0xb8, 0x01, 0x4c,
Maybe it's easier to make it always 64-byte long and use sizeof(DOSProgram) instead of alignTo()

  static unsigned char DOSProgram[64] = { ... };

Comment at: COFF/Writer.cpp:689
 template <typename PEHeaderTy> void Writer::writeHeader() {
-  // Write DOS stub
+  // Write DOS header.
   uint8_t *Buf = Buffer->getBufferStart();
It's perhaps better to expand this comment a bit so that the thing we are doing here is not important to understand the linker itself -- it's just a small DOS program at beginning of every PE/COFF executable to help DOS 2.0 (!) users that the program needs Windows.

Comment at: COFF/Writer.cpp:693
+  Buf += sizeof(dos_header);
   DOS->Magic[0] = 'M';
   DOS->Magic[1] = 'Z';
hans wrote:
> Is there a guarantee that the buffer is zero-initialized? Otherwise maybe we should memset DOS here, because it's important that the un-set fields are really zero if this is going to be loaded.
The buffer is a new mmap'ed file, so it is guaranteed to be zero-initialized.

(The situation is different for ELF executable sections because we write INT3 or equivalent before writing anything to that regions, but that's not relevant here because this is COFF header.)


More information about the llvm-commits mailing list