[PECOFF] Set DLL bit in PE header if DLL.
authorRui Ueyama <ruiu@google.com>
Thu, 17 Jul 2014 00:22:26 +0000 (00:22 +0000)
committerRui Ueyama <ruiu@google.com>
Thu, 17 Jul 2014 00:22:26 +0000 (00:22 +0000)
Windows loader can load a DLL without this bit but it wouldn't
call the initializer function in the DLL if the bit is absent.

llvm-svn: 213216

lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
lld/test/pecoff/dll.test [new file with mode: 0644]

index 65ab03f..73fa4f7 100644 (file)
@@ -332,6 +332,8 @@ PEHeaderChunk<PEHeader>::PEHeaderChunk(const PECOFFLinkingContext &ctx)
   uint16_t characteristics = llvm::COFF::IMAGE_FILE_EXECUTABLE_IMAGE;
   if (!ctx.is64Bit())
     characteristics |= llvm::COFF::IMAGE_FILE_32BIT_MACHINE;
+  if (ctx.isDll())
+    characteristics |= llvm::COFF::IMAGE_FILE_DLL;
   if (ctx.getLargeAddressAware() || ctx.is64Bit())
     characteristics |= llvm::COFF::IMAGE_FILE_LARGE_ADDRESS_AWARE;
   if (ctx.getSwapRunFromCD())
diff --git a/lld/test/pecoff/dll.test b/lld/test/pecoff/dll.test
new file mode 100644 (file)
index 0000000..666e9f1
--- /dev/null
@@ -0,0 +1,7 @@
+# RUN: yaml2obj %p/Inputs/nop.obj.yaml > %t.obj
+#
+# RUN: lld -flavor link /out:%t.exe /subsystem:console \
+# RUN:   /entry:start /dll -- %t.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck %s
+
+CHECK: IMAGE_FILE_DLL (0x2000)