[MC] Generate a timestamp for COFF object files
[oota-llvm.git] / lib / MC / WinCOFFObjectWriter.cpp
index 9abd1a1590695bba4ac96e72f9697988212c5737..c9dafb569083e64f3a908060907cebe80070ea3b 100644 (file)
@@ -35,6 +35,7 @@
 #include "llvm/Support/JamCRC.h"
 #include "llvm/Support/TimeValue.h"
 #include <cstdio>
+#include <ctime>
 
 using namespace llvm;
 
@@ -1012,8 +1013,12 @@ void WinCOFFObjectWriter::writeObject(MCAssembler &Asm,
 
   Header.PointerToSymbolTable = offset;
 
-  // We want a deterministic output. It looks like GNU as also writes 0 in here.
-  Header.TimeDateStamp = 0;
+  // MS LINK expects to be able to use this timestamp to implement their
+  // /INCREMENTAL feature.
+  std::time_t Now = time(nullptr);
+  if (Now < 0 || Now > UINT32_MAX)
+    Now = UINT32_MAX;
+  Header.TimeDateStamp = Now;
 
   // Write it all to disk...
   WriteFileHeader(Header);