[PECOFF] Remember /noentry option so that later passes can handle it.
authorRui Ueyama <ruiu@google.com>
Tue, 22 Jul 2014 22:19:42 +0000 (22:19 +0000)
committerRui Ueyama <ruiu@google.com>
Tue, 22 Jul 2014 22:19:42 +0000 (22:19 +0000)
This is a part of a larger change to move the entry point
processing to a later pass than the driver. On Windows the default
entry point function varies depending on user-provided functions.
That means the driver is not able to correctly know the entry point
function name. Only passes after the core linker can infer it.

llvm-svn: 213697

lld/include/lld/ReaderWriter/PECOFFLinkingContext.h
lld/lib/Driver/WinLinkDriver.cpp

index d76a732..002edb6 100644 (file)
@@ -36,7 +36,7 @@ class Group;
 class PECOFFLinkingContext : public LinkingContext {
 public:
   PECOFFLinkingContext()
-      : _mutex(), _allocMutex(), _baseAddress(invalidBaseAddress),
+      : _mutex(), _allocMutex(), _hasEntry(true), _baseAddress(invalidBaseAddress),
         _stackReserve(1024 * 1024), _stackCommit(4096),
         _heapReserve(1024 * 1024), _heapCommit(4096), _noDefaultLibAll(false),
         _sectionDefaultAlignment(4096),
@@ -118,6 +118,9 @@ public:
       LinkingContext::setEntrySymbolName(decorateSymbol(name));
   }
 
+  void setHasEntry(bool val) { _hasEntry = val; }
+  bool hasEntry() const { return _hasEntry; }
+
   void setBaseAddress(uint64_t addr) { _baseAddress = addr; }
   uint64_t getBaseAddress() const;
 
@@ -305,6 +308,9 @@ private:
   std::recursive_mutex _mutex;
   mutable std::mutex _allocMutex;
 
+  // False if /noentry option is given.
+  bool _hasEntry;
+
   // The start address for the program. The default value for the executable is
   // 0x400000, but can be altered using /base command line option.
   uint64_t _baseAddress;
index e96c030..d226aa7 100644 (file)
@@ -1196,6 +1196,10 @@ bool WinLinkDriver::parse(int argc, const char *argv[],
       ctx.addInitialUndefinedSymbol(ctx.allocate(inputArg->getValue()));
       break;
 
+    case OPT_noentry:
+      ctx.setHasEntry(false);
+      break;
+
     case OPT_nodefaultlib_all:
       ctx.setNoDefaultLibAll(true);
       break;
@@ -1289,7 +1293,7 @@ bool WinLinkDriver::parse(int argc, const char *argv[],
     ctx.addInitialUndefinedSymbol(entry);
 
   // Specify /noentry without /dll is an error.
-  if (parsedArgs->getLastArg(OPT_noentry) && !parsedArgs->getLastArg(OPT_dll)) {
+  if (!ctx.hasEntry() && !parsedArgs->getLastArg(OPT_dll)) {
     diag << "/noentry must be specified with /dll\n";
     return false;
   }