[MC] Generate a timestamp for COFF object files
authorDavid Majnemer <david.majnemer@gmail.com>
Tue, 1 Sep 2015 23:46:11 +0000 (23:46 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Tue, 1 Sep 2015 23:46:11 +0000 (23:46 +0000)
The MS incremental linker seems to inspect the timestamp written into
the object file to determine whether or not it's contents need to be
considered.  Failing to set the timestamp to a date newer than the
executable will result in the object file not participating in
subsequent links.  To ameliorate this, write the current time into the
object file's TimeDateStamp field.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@246607 91177308-0d34-0410-b5e6-96231b3b80d8

lib/MC/WinCOFFObjectWriter.cpp
test/MC/COFF/timestamp.s

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);
index 18736a2b2d688e8d11aeff4c0dd41a32e6e909db..917e1e717a89c895c733a6f026998b1365d4d6af 100644 (file)
@@ -1,4 +1,4 @@
 // RUN: llvm-mc -filetype=obj -triple i686-pc-win32 %s -o - | llvm-readobj -h | FileCheck %s
 
 // CHECK: ImageFileHeader {
-// CHECK:   TimeDateStamp: {{.*}} (0x0)
+// CHECK:   TimeDateStamp: {{.*}}