[lld] r240915 - COFF: Add /noentry flag.
Rui Ueyama
ruiu at google.com
Sun Jun 28 12:56:30 PDT 2015
Author: ruiu
Date: Sun Jun 28 14:56:30 2015
New Revision: 240915
URL: http://llvm.org/viewvc/llvm-project?rev=240915&view=rev
Log:
COFF: Add /noentry flag.
This option is sometimes used to create a resource-only DLL that
doesn't need any initialization.
Added:
lld/trunk/test/COFF/noentry.test
Modified:
lld/trunk/COFF/Config.h
lld/trunk/COFF/Driver.cpp
lld/trunk/COFF/Writer.cpp
Modified: lld/trunk/COFF/Config.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Config.h?rev=240915&r1=240914&r2=240915&view=diff
==============================================================================
--- lld/trunk/COFF/Config.h (original)
+++ lld/trunk/COFF/Config.h Sun Jun 28 14:56:30 2015
@@ -43,6 +43,7 @@ struct Configuration {
bool Verbose = false;
WindowsSubsystem Subsystem = llvm::COFF::IMAGE_SUBSYSTEM_UNKNOWN;
StringRef EntryName;
+ bool NoEntry = false;
std::string OutputFile;
bool DoGC = true;
bool Relocatable = true;
Modified: lld/trunk/COFF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Driver.cpp?rev=240915&r1=240914&r2=240915&view=diff
==============================================================================
--- lld/trunk/COFF/Driver.cpp (original)
+++ lld/trunk/COFF/Driver.cpp Sun Jun 28 14:56:30 2015
@@ -275,11 +275,20 @@ bool LinkerDriver::link(llvm::ArrayRef<c
addUndefined(Config->EntryName);
}
+ // Handle /noentry
+ if (Args.hasArg(OPT_noentry)) {
+ if (!Args.hasArg(OPT_dll)) {
+ llvm::errs() << "/noentry must be specified with /dll\n";
+ return false;
+ }
+ Config->NoEntry = true;
+ }
+
// Handle /dll
if (Args.hasArg(OPT_dll)) {
Config->DLL = true;
Config->ManifestID = 2;
- if (Config->EntryName.empty()) {
+ if (Config->EntryName.empty() && !Config->NoEntry) {
Config->EntryName = "_DllMainCRTStartup";
addUndefined("_DllMainCRTStartup");
}
@@ -539,15 +548,15 @@ bool LinkerDriver::link(llvm::ArrayRef<c
// Windows specific -- If entry point name is not given, we need to
// infer that from user-defined entry name. The symbol table takes
// care of details.
- if (Config->EntryName.empty()) {
+ if (Config->EntryName.empty() && !Config->NoEntry) {
auto EntryOrErr = Symtab.findDefaultEntry();
if (auto EC = EntryOrErr.getError()) {
llvm::errs() << EC.message() << "\n";
return false;
}
Config->EntryName = EntryOrErr.get();
+ addUndefined(Config->EntryName);
}
- addUndefined(Config->EntryName);
if (auto EC = Symtab.run()) {
llvm::errs() << EC.message() << "\n";
Modified: lld/trunk/COFF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Writer.cpp?rev=240915&r1=240914&r2=240915&view=diff
==============================================================================
--- lld/trunk/COFF/Writer.cpp (original)
+++ lld/trunk/COFF/Writer.cpp Sun Jun 28 14:56:30 2015
@@ -316,8 +316,10 @@ void Writer::writeHeader() {
PE->Subsystem = Config->Subsystem;
PE->SizeOfImage = SizeOfImage;
PE->SizeOfHeaders = SizeOfHeaders;
- Defined *Entry = cast<Defined>(Symtab->find(Config->EntryName));
- PE->AddressOfEntryPoint = Entry->getRVA();
+ if (!Config->NoEntry) {
+ Defined *Entry = cast<Defined>(Symtab->find(Config->EntryName));
+ PE->AddressOfEntryPoint = Entry->getRVA();
+ }
PE->SizeOfStackReserve = Config->StackReserve;
PE->SizeOfStackCommit = Config->StackCommit;
PE->SizeOfHeapReserve = Config->HeapReserve;
Added: lld/trunk/test/COFF/noentry.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/noentry.test?rev=240915&view=auto
==============================================================================
--- lld/trunk/test/COFF/noentry.test (added)
+++ lld/trunk/test/COFF/noentry.test Sun Jun 28 14:56:30 2015
@@ -0,0 +1,10 @@
+# REQUIRES: winres
+
+# RUN: yaml2obj < %p/Inputs/export.yaml > %t.obj
+# RUN: lld -flavor link2 /out:%t.dll /dll %t.obj
+# RUN: llvm-readobj -file-headers %t.dll | FileCheck -check-prefix=ENTRY %s
+# RUN: lld -flavor link2 /out:%t.dll /dll /noentry %t.obj
+# RUN: llvm-readobj -file-headers %t.dll | FileCheck -check-prefix=NOENTRY %s
+
+ENTRY: AddressOfEntryPoint: 0x1000
+NOENTRY: AddressOfEntryPoint: 0x0
More information about the llvm-commits
mailing list