Make WinCOFFObjectWriter.cpp's timestamp writing not use ENABLE_TIMESTAMPS
authorNico Weber <nicolasweber@gmx.de>
Wed, 6 Jan 2016 19:05:19 +0000 (19:05 +0000)
committerNico Weber <nicolasweber@gmx.de>
Wed, 6 Jan 2016 19:05:19 +0000 (19:05 +0000)
LLVM_ENABLE_TIMESTAMPS controls if timestamps are embedded into llvm's
binaries. Turning it off is useful for deterministic builds.

r246905 made it so that the define suddenly also controls if the binaries that
the llvm binaries _create_ embed timestamps or not – but this shouldn't be a
configure-time option. r256203/r256204 added a driver option to toggle this on
and off, so this patch now passes this driver option in LLVM_ENABLE_TIMESTAMPS
builds so that if LLVM_ENABLE_TIMESTAMPS is set, the build of LLVM is
deterministic – but the built clang can still write timestamps into other
executables when requested.

This also allows removing some of the test machinery added in r292012 to work
around this problem.

See PR24740 for background.
http://reviews.llvm.org/D15783

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

cmake/modules/HandleLLVMOptions.cmake
lib/MC/WinCOFFObjectWriter.cpp
test/MC/COFF/timestamp.s
test/lit.cfg
test/lit.site.cfg.in

index 4c5ffe2f7b28e78094fa3da23ba55314be8eab16..6db258ff66a156f6c611380dcdf693e14a42dd91 100644 (file)
@@ -363,6 +363,36 @@ if( MSVC )
 
   append("/Zc:inline" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
 
 
   append("/Zc:inline" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
 
+  if (NOT LLVM_ENABLE_TIMESTAMPS AND CMAKE_CXX_COMPILER_ID MATCHES "Clang")
+    # clang-cl and cl by default produce non-deterministic binaries because
+    # link.exe /incremental requires a timestamp in the .obj file.  clang-cl
+    # has the flag /Brepro to force deterministic binaries, so pass that when
+    # LLVM_ENABLE_TIMESTAMPS is turned off.
+    # This checks CMAKE_CXX_COMPILER_ID in addition to check_cxx_compiler_flag()
+    # because cl.exe does not emit an error on flags it doesn't understand,
+    # letting check_cxx_compiler_flag() claim it understands all flags.
+    check_cxx_compiler_flag("/Brepro" SUPPORTS_BREPRO)
+    append_if(SUPPORTS_BREPRO "/Brepro" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
+
+    if (SUPPORTS_BREPRO)
+      # Check if /INCREMENTAL is passed to the linker and complain that it
+      # won't work with /Brepro.
+      string(TOUPPER "${CMAKE_EXE_LINKER_FLAGS}" upper_exe_flags)
+      string(TOUPPER "${CMAKE_MODULE_LINKER_FLAGS}" upper_module_flags)
+      string(TOUPPER "${CMAKE_SHARED_LINKER_FLAGS}" upper_shared_flags)
+
+      string(FIND "${upper_exe_flags}" "/INCREMENTAL" exe_index)
+      string(FIND "${upper_module_flags}" "/INCREMENTAL" module_index)
+      string(FIND "${upper_shared_flags}" "/INCREMENTAL" shared_index)
+      
+      if (${exe_index} GREATER -1 OR
+          ${module_index} GREATER -1 OR
+          ${shared_index} GREATER -1)
+        message(FATAL_ERROR "LLVM_ENABLE_TIMESTAMPS not compatible with /INCREMENTAL linking")
+      endif()
+    endif()
+  endif()
+
   # Disable sized deallocation if the flag is supported. MSVC fails to compile
   # the operator new overload in User otherwise.
   check_c_compiler_flag("/WX /Zc:sizedDealloc-" SUPPORTS_SIZED_DEALLOC)
   # Disable sized deallocation if the flag is supported. MSVC fails to compile
   # the operator new overload in User otherwise.
   check_c_compiler_flag("/WX /Zc:sizedDealloc-" SUPPORTS_SIZED_DEALLOC)
index a3820906b76b1104b10b57f6d3429931f3e0bdbd..a76cbdbd5447b231d3213549046e566e17903845 100644 (file)
@@ -969,9 +969,6 @@ void WinCOFFObjectWriter::writeObject(MCAssembler &Asm,
 
   Header.PointerToSymbolTable = offset;
 
 
   Header.PointerToSymbolTable = offset;
 
-  // FIXME: Remove the #else branch and make the #if branch unconditional once
-  // LLVM's self host configuration is aware of /Brepro.
-#if (ENABLE_TIMESTAMPS == 1)
   // MS LINK expects to be able to use this timestamp to implement their
   // /INCREMENTAL feature.
   if (Asm.isIncrementalLinkerCompatible()) {
   // MS LINK expects to be able to use this timestamp to implement their
   // /INCREMENTAL feature.
   if (Asm.isIncrementalLinkerCompatible()) {
@@ -980,12 +977,9 @@ void WinCOFFObjectWriter::writeObject(MCAssembler &Asm,
       Now = UINT32_MAX;
     Header.TimeDateStamp = Now;
   } else {
       Now = UINT32_MAX;
     Header.TimeDateStamp = Now;
   } else {
+    // Have deterministic output if /INCREMENTAL isn't needed. Also matches GNU.
     Header.TimeDateStamp = 0;
   }
     Header.TimeDateStamp = 0;
   }
-#else
-  // We want a deterministic output. It looks like GNU as also writes 0 in here.
-  Header.TimeDateStamp = 0;
-#endif
 
   // Write it all to disk...
   WriteFileHeader(Header);
 
   // Write it all to disk...
   WriteFileHeader(Header);
index a2761575789d0cd6066fa28a1cc27b71c5377c05..140225acf7e8515f90e279723e4611e91bb36271 100644 (file)
@@ -1,5 +1,4 @@
 // RUN: llvm-mc -filetype=obj -triple i686-pc-win32 -incremental-linker-compatible %s -o - | llvm-readobj -h | FileCheck %s
 // RUN: llvm-mc -filetype=obj -triple i686-pc-win32 -incremental-linker-compatible %s -o - | llvm-readobj -h | FileCheck %s
-// REQUIRES: timestamps
 
 // CHECK: ImageFileHeader {
 // CHECK:   TimeDateStamp:
 
 // CHECK: ImageFileHeader {
 // CHECK:   TimeDateStamp:
index 36b4c70440831f3c072ef489be93bd21291b2b20..5cc4d6e0456100b5dfc30ac29ed1d9e0c4eeaae6 100644 (file)
@@ -459,10 +459,6 @@ if platform.system() in ['Windows'] and re.match(r'.*-win32$', config.target_tri
 if not re.match(r'^x86_64.*-(mingw32|windows-gnu|win32)', config.target_triple):
     config.available_features.add('debug_frame')
 
 if not re.match(r'^x86_64.*-(mingw32|windows-gnu|win32)', config.target_triple):
     config.available_features.add('debug_frame')
 
-# Check if we are embedding timestamps.
-if config.enable_timestamps == '1':
-    config.available_features.add('timestamps')
-
 # Check if we should use gmalloc.
 use_gmalloc_str = lit_config.params.get('use_gmalloc', None)
 if use_gmalloc_str is not None:
 # Check if we should use gmalloc.
 use_gmalloc_str = lit_config.params.get('use_gmalloc', None)
 if use_gmalloc_str is not None:
index ae5814f02f41b2763ab313d67a0648487f396268..13f5372ef7e3cee68aaf9209a69ebc6baba77dd5 100644 (file)
@@ -36,7 +36,6 @@ config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@"
 config.have_zlib = "@HAVE_LIBZ@"
 config.have_dia_sdk = @HAVE_DIA_SDK@
 config.enable_ffi = "@LLVM_ENABLE_FFI@"
 config.have_zlib = "@HAVE_LIBZ@"
 config.have_dia_sdk = @HAVE_DIA_SDK@
 config.enable_ffi = "@LLVM_ENABLE_FFI@"
-config.enable_timestamps = "@ENABLE_TIMESTAMPS@"
 config.test_examples = "@ENABLE_EXAMPLES@"
 
 # Support substitution of the tools_dir with user parameters. This is
 config.test_examples = "@ENABLE_EXAMPLES@"
 
 # Support substitution of the tools_dir with user parameters. This is