Skip to content

Commit 28f6aac

Browse files
amy-kwantstellar
authored andcommitted
[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 c84c62c)
1 parent 19c735e commit 28f6aac

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

llvm/cmake/modules/HandleLLVMOptions.cmake

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,28 @@ if(APPLE)
145145
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-flat_namespace -Wl,-undefined -Wl,suppress")
146146
endif()
147147

148+
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
149+
# RHEL7 has ar and ranlib being non-deterministic by default. The D flag forces determinism,
150+
# however only GNU version of ar and ranlib (2.27) have this option.
151+
# RHEL DTS7 is also affected by this, which uses GNU binutils 2.28
152+
execute_process(COMMAND ${CMAKE_AR} rD t.a
153+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR} RESULT_VARIABLE AR_RESULT OUTPUT_VARIABLE RANLIB_OUTPUT)
154+
if(${AR_RESULT} EQUAL 0)
155+
execute_process(COMMAND ${CMAKE_RANLIB} -D t.a
156+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR} RESULT_VARIABLE RANLIB_RESULT OUTPUT_VARIABLE RANLIB_OUTPUT)
157+
if(${RANLIB_RESULT} EQUAL 0)
158+
set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> Dqc <TARGET> <LINK_FLAGS> <OBJECTS>")
159+
set(CMAKE_C_ARCHIVE_APPEND "<CMAKE_AR> Dq <TARGET> <LINK_FLAGS> <OBJECTS>")
160+
set(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> -D <TARGET>")
161+
162+
set(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> Dqc <TARGET> <LINK_FLAGS> <OBJECTS>")
163+
set(CMAKE_CXX_ARCHIVE_APPEND "<CMAKE_AR> Dq <TARGET> <LINK_FLAGS> <OBJECTS>")
164+
set(CMAKE_CXX_ARCHIVE_FINISH "<CMAKE_RANLIB> -D <TARGET>")
165+
endif()
166+
file(REMOVE ${CMAKE_BINARY_DIR}/t.a)
167+
endif()
168+
endif()
169+
148170
if(${CMAKE_SYSTEM_NAME} MATCHES "AIX")
149171
if(NOT LLVM_BUILD_32_BITS)
150172
if (CMAKE_CXX_COMPILER_ID MATCHES "XL")

0 commit comments

Comments
 (0)