[PATCH] D64817: [CMake] Fix LLVM build non-determinism on RHEL
Amy Kwan via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 16 13:35:10 PDT 2019
amyk created this revision.
amyk added reviewers: nemanjai, hubert.reinterpretcast.
amyk added a project: LLVM.
Herald added subscribers: llvm-commits, mgrang, mgorny.
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.
Repository:
rL LLVM
https://reviews.llvm.org/D64817
Files:
llvm/cmake/modules/HandleLLVMOptions.cmake
Index: llvm/cmake/modules/HandleLLVMOptions.cmake
===================================================================
--- llvm/cmake/modules/HandleLLVMOptions.cmake
+++ llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -145,6 +145,25 @@
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-flat_namespace -Wl,-undefined -Wl,suppress")
endif()
+if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
+ # RHEL has ar and ranlib being non-deterministic by default. The D flag forces determinism,
+ # however only GNU version of ar and ranlib have this option
+ execute_process(COMMAND ${CMAKE_RANLIB} --version
+ WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} RESULT_VARIABLE RANLIB_RESULT OUTPUT_VARIABLE RANLIB_OUTPUT)
+ if((${RANLIB_RESULT} EQUAL 0) AND ("${RANLIB_OUTPUT}" MATCHES "GNU ranlib") AND ("${RANLIB_OUTPUT}" MATCHES "([0-9]+\\.[0-9]+)"))
+ # Version 2.23 is the first version of binutils where both ar and ranlib have the D flag
+ if("${CMAKE_MATCH_0}" VERSION_GREATER "2.22")
+ 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()
+ endif()
+endif()
+
if(${CMAKE_SYSTEM_NAME} MATCHES "AIX")
if(NOT LLVM_BUILD_32_BITS)
if (CMAKE_CXX_COMPILER_ID MATCHES "XL")
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D64817.210160.patch
Type: text/x-patch
Size: 1633 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190716/1bef5de8/attachment.bin>
More information about the llvm-commits
mailing list