aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmy Kwan <amy.kwan1@ibm.com>2019-11-21 23:06:33 -0600
committerTom Stellard <tstellar@redhat.com>2019-11-27 11:17:05 -0800
commit28f6aac1c102f7d8ba8afce900079e42e67bedca (patch)
tree1060b111ac36a5ae47daea144a0049f47ae4247d
parent19c735edfb7e937894463d0b315896ad972e44da (diff)
downloadllvm-28f6aac1c102f7d8ba8afce900079e42e67bedca.zip
llvm-28f6aac1c102f7d8ba8afce900079e42e67bedca.tar.gz
llvm-28f6aac1c102f7d8ba8afce900079e42e67bedca.tar.bz2
[CMake] Fix LLVM build non-determinism on RHEL
On RHEL, the OS tooling (ar, ranlib) is not deterministic by default. Therefore, we cannot get bit-for-bit identical builds. The goal of this patch is that it adds the flags required to force determinism. Differential Revision: https://reviews.llvm.org/D64817 (cherry picked from commit c84c62c50aa8524dbf96217c337f3b5ee4139000)
-rw-r--r--llvm/cmake/modules/HandleLLVMOptions.cmake22
1 files changed, 22 insertions, 0 deletions
diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake b/llvm/cmake/modules/HandleLLVMOptions.cmake
index 59e1bdb..4425eb9 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -145,6 +145,28 @@ if(APPLE)
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-flat_namespace -Wl,-undefined -Wl,suppress")
endif()
+if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
+ # RHEL7 has ar and ranlib being non-deterministic by default. The D flag forces determinism,
+ # however only GNU version of ar and ranlib (2.27) have this option.
+ # RHEL DTS7 is also affected by this, which uses GNU binutils 2.28
+ execute_process(COMMAND ${CMAKE_AR} rD t.a
+ WORKING_DIRECTORY ${CMAKE_BINARY_DIR} RESULT_VARIABLE AR_RESULT OUTPUT_VARIABLE RANLIB_OUTPUT)
+ if(${AR_RESULT} EQUAL 0)
+ execute_process(COMMAND ${CMAKE_RANLIB} -D t.a
+ WORKING_DIRECTORY ${CMAKE_BINARY_DIR} RESULT_VARIABLE RANLIB_RESULT OUTPUT_VARIABLE RANLIB_OUTPUT)
+ if(${RANLIB_RESULT} EQUAL 0)
+ set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> Dqc <TARGET> <LINK_FLAGS> <OBJECTS>")
+ set(CMAKE_C_ARCHIVE_APPEND "<CMAKE_AR> Dq <TARGET> <LINK_FLAGS> <OBJECTS>")
+ set(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> -D <TARGET>")
+
+ set(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> Dqc <TARGET> <LINK_FLAGS> <OBJECTS>")
+ set(CMAKE_CXX_ARCHIVE_APPEND "<CMAKE_AR> Dq <TARGET> <LINK_FLAGS> <OBJECTS>")
+ set(CMAKE_CXX_ARCHIVE_FINISH "<CMAKE_RANLIB> -D <TARGET>")
+ endif()
+ file(REMOVE ${CMAKE_BINARY_DIR}/t.a)
+ endif()
+endif()
+
if(${CMAKE_SYSTEM_NAME} MATCHES "AIX")
if(NOT LLVM_BUILD_32_BITS)
if (CMAKE_CXX_COMPILER_ID MATCHES "XL")