From 286691ad5e1a8efdd1d98c56dccbacd6cc709b77 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Thu, 17 Jul 2014 00:22:26 +0000 Subject: [PATCH] [PECOFF] Set DLL bit in PE header if DLL. 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 | 2 ++ lld/test/pecoff/dll.test | 7 +++++++ 2 files changed, 9 insertions(+) create mode 100644 lld/test/pecoff/dll.test diff --git a/lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp b/lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp index 65ab03f4c243..73fa4f7195eb 100644 --- a/lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp +++ b/lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp @@ -332,6 +332,8 @@ PEHeaderChunk::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 index 000000000000..666e9f1152b0 --- /dev/null +++ b/lld/test/pecoff/dll.test @@ -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)