Skip to content

Commit ef163f5

Browse files
committed
[CMake] Separate the detection Darwin platforms architectures for the
built-ins from the rest of compiler-rt. The detection of supported platform (os) architectures for Darwin relies on the `darwin_test_archs()` CMake function. This is used both for building the builtins (`builtin-config-ix.cmake`) and for the rest of the compiler-rt (`config-ix.cmake`). `darwin_test_archs()` implements a cache, presumably to speed up CMake re-configures. Unfortunately this caching is buggy because it depends on external global state (i.e. the `TEST_COMPILE_ONLY` variable) and this is not taken into account. For `config-ix.cmake` `TEST_COMPILE_ONLY` is not set and for `builtin-config-ix.cmake` `TEST_COMPILE_ONLY` is set to `On`. This makes the `darwin_test_archs()` function racey in the sense that a call from one calling context will poison the cache for the other calling context. This is actually an issue George Karpenkov discovered a while back and had an incomplete patch for (https://reviews.llvm.org/D45337) but this was never merged. To workaround this, this patch switches to using a different set of variables for the platform architecture builtins, i.e. `DARWIN_<OS>_ARCHS` -> `DARWIN_<OS>_BUILTIN_ARCHS`. This avoids the cache poisoning problem because the cached variable names are different. This also has the advantage that the the configured architectures for builtins and the rest of the compiler-rt are now independent and can be set differently if necessary. Note in `darwin_test_archs()` we also now pass `-w` to the compiler because `try_compile_only()` treats compiler warnings as errors. This was extremely fragile because compiler warnings (can easily appear due to a buggy compiler or SDK headers) would cause compiler-rt to think an architecture on Darwin wasn't supported. rdar://problem/48637491 llvm-svn: 371871
1 parent d38f63e commit ef163f5

File tree

2 files changed

+32
-31
lines changed

2 files changed

+32
-31
lines changed

compiler-rt/cmake/Modules/CompilerRTDarwinUtils.cmake

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ function(darwin_test_archs os valid_archs)
9494

9595
set(arch_linker_flags "-arch ${arch} ${os_linker_flags}")
9696
if(TEST_COMPILE_ONLY)
97-
try_compile_only(CAN_TARGET_${os}_${arch} FLAGS -v -arch ${arch} ${DARWIN_${os}_CFLAGS})
97+
# `-w` is used to surpress compiler warnings which `try_compile_only()` treats as an error.
98+
try_compile_only(CAN_TARGET_${os}_${arch} FLAGS -v -arch ${arch} ${DARWIN_${os}_CFLAGS} -w)
9899
else()
99100
set(SAVED_CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS})
100101
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${arch_linker_flags}")
@@ -282,7 +283,7 @@ macro(darwin_add_builtin_libraries)
282283
../profile/InstrProfilingPlatformDarwin
283284
../profile/InstrProfilingWriter)
284285
foreach (os ${ARGN})
285-
list_intersect(DARWIN_BUILTIN_ARCHS DARWIN_${os}_ARCHS BUILTIN_SUPPORTED_ARCH)
286+
list_intersect(DARWIN_BUILTIN_ARCHS DARWIN_${os}_BUILTIN_ARCHS BUILTIN_SUPPORTED_ARCH)
286287
foreach (arch ${DARWIN_BUILTIN_ARCHS})
287288
darwin_find_excluded_builtins_list(${arch}_${os}_EXCLUDED_BUILTINS
288289
OS ${os}

compiler-rt/cmake/builtin-config-ix.cmake

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -64,43 +64,51 @@ if(APPLE)
6464
set(DARWIN_osx_BUILTIN_MIN_VER 10.5)
6565
set(DARWIN_osx_BUILTIN_MIN_VER_FLAG
6666
-mmacosx-version-min=${DARWIN_osx_BUILTIN_MIN_VER})
67+
set(DARWIN_osx_BUILTIN_ALL_POSSIBLE_ARCHS ${X86} ${X86_64})
6768

6869
if(COMPILER_RT_ENABLE_IOS)
6970
list(APPEND DARWIN_EMBEDDED_PLATFORMS ios)
7071
set(DARWIN_ios_MIN_VER_FLAG -miphoneos-version-min)
7172
set(DARWIN_ios_BUILTIN_MIN_VER 6.0)
7273
set(DARWIN_ios_BUILTIN_MIN_VER_FLAG
7374
${DARWIN_ios_MIN_VER_FLAG}=${DARWIN_ios_BUILTIN_MIN_VER})
75+
set(DARWIN_ios_BUILTIN_ALL_POSSIBLE_ARCHS ${ARM64} ${ARM32})
76+
set(DARWIN_iossim_BUILTIN_ALL_POSSIBLE_ARCHS ${X86} ${X86_64})
7477
endif()
7578
if(COMPILER_RT_ENABLE_WATCHOS)
7679
list(APPEND DARWIN_EMBEDDED_PLATFORMS watchos)
7780
set(DARWIN_watchos_MIN_VER_FLAG -mwatchos-version-min)
7881
set(DARWIN_watchos_BUILTIN_MIN_VER 2.0)
7982
set(DARWIN_watchos_BUILTIN_MIN_VER_FLAG
8083
${DARWIN_watchos_MIN_VER_FLAG}=${DARWIN_watchos_BUILTIN_MIN_VER})
84+
set(DARWIN_watchos_BUILTIN_ALL_POSSIBLE_ARCHS armv7 armv7k)
85+
set(DARWIN_watchossim_BUILTIN_ALL_POSSIBLE_ARCHS ${X86})
8186
endif()
8287
if(COMPILER_RT_ENABLE_TVOS)
8388
list(APPEND DARWIN_EMBEDDED_PLATFORMS tvos)
8489
set(DARWIN_tvos_MIN_VER_FLAG -mtvos-version-min)
8590
set(DARWIN_tvos_BUILTIN_MIN_VER 9.0)
8691
set(DARWIN_tvos_BUILTIN_MIN_VER_FLAG
8792
${DARWIN_tvos_MIN_VER_FLAG}=${DARWIN_tvos_BUILTIN_MIN_VER})
93+
set(DARWIN_tvos_BUILTIN_ALL_POSSIBLE_ARCHS armv7 arm64)
94+
set(DARWIN_tvossim_BUILTIN_ALL_POSSIBLE_ARCHS ${X86} ${X86_64})
8895
endif()
8996

9097
set(BUILTIN_SUPPORTED_OS osx)
9198

9299
# We're setting the flag manually for each target OS
93100
set(CMAKE_OSX_DEPLOYMENT_TARGET "")
94101

95-
if(NOT DARWIN_osx_ARCHS)
96-
set(DARWIN_osx_ARCHS i386 x86_64 x86_64h)
97-
endif()
98-
99-
set(DARWIN_sim_ARCHS i386 x86_64)
100-
set(DARWIN_device_ARCHS armv7 armv7s armv7k arm64)
101-
102-
message(STATUS "OSX supported arches: ${DARWIN_osx_ARCHS}")
103-
foreach(arch ${DARWIN_osx_ARCHS})
102+
# NOTE: We deliberately avoid using `DARWIN_<os>_ARCHS` here because that is
103+
# used by `config-ix.cmake` in the context of building the rest of
104+
# compiler-rt where the global `${TEST_COMPILE_ONLY}` (used by
105+
# `darwin_test_archs()`) has a different value.
106+
darwin_test_archs(osx
107+
DARWIN_osx_BUILTIN_ARCHS
108+
${DARWIN_osx_BUILTIN_ALL_POSSIBLE_ARCHS}
109+
)
110+
message(STATUS "OSX supported builtin arches: ${DARWIN_osx_BUILTIN_ARCHS}")
111+
foreach(arch ${DARWIN_osx_BUILTIN_ARCHS})
104112
list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch})
105113
set(CAN_TARGET_${arch} 1)
106114
endforeach()
@@ -114,38 +122,30 @@ if(APPLE)
114122

115123
set(DARWIN_${platform}sim_SKIP_CC_KEXT On)
116124

117-
set(test_arches ${DARWIN_sim_ARCHS})
118-
if(DARWIN_${platform}sim_ARCHS)
119-
set(test_arches DARWIN_${platform}sim_ARCHS)
120-
endif()
121-
122125
darwin_test_archs(${platform}sim
123-
DARWIN_${platform}sim_ARCHS
124-
${test_arches})
125-
message(STATUS "${platform} Simulator supported builtin arches: ${DARWIN_${platform}sim_ARCHS}")
126-
if(DARWIN_${platform}sim_ARCHS)
126+
DARWIN_${platform}sim_BUILTIN_ARCHS
127+
${DARWIN_${platform}sim_BUILTIN_ALL_POSSIBLE_ARCHS}
128+
)
129+
message(STATUS "${platform} Simulator supported builtin arches: ${DARWIN_${platform}sim_BUILTIN_ARCHS}")
130+
if(DARWIN_${platform}sim_BUILTIN_ARCHS)
127131
list(APPEND BUILTIN_SUPPORTED_OS ${platform}sim)
128132
endif()
129-
foreach(arch ${DARWIN_${platform}sim_ARCHS})
133+
foreach(arch ${DARWIN_${platform}sim_BUILTIN_ARCHS})
130134
list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch})
131135
set(CAN_TARGET_${arch} 1)
132136
endforeach()
133137
endif()
134138

135139
if(DARWIN_${platform}_SYSROOT)
136-
set(test_arches ${DARWIN_device_ARCHS})
137-
if(DARWIN_${platform}_ARCHS)
138-
set(test_arches DARWIN_${platform}_ARCHS)
139-
endif()
140-
141140
darwin_test_archs(${platform}
142-
DARWIN_${platform}_ARCHS
143-
${test_arches})
144-
message(STATUS "${platform} supported builtin arches: ${DARWIN_${platform}_ARCHS}")
145-
if(DARWIN_${platform}_ARCHS)
141+
DARWIN_${platform}_BUILTIN_ARCHS
142+
${DARWIN_${platform}_BUILTIN_ALL_POSSIBLE_ARCHS}
143+
)
144+
message(STATUS "${platform} supported builtin arches: ${DARWIN_${platform}_BUILTIN_ARCHS}")
145+
if(DARWIN_${platform}_BUILTIN_ARCHS)
146146
list(APPEND BUILTIN_SUPPORTED_OS ${platform})
147147
endif()
148-
foreach(arch ${DARWIN_${platform}_ARCHS})
148+
foreach(arch ${DARWIN_${platform}_BUILTIN_ARCHS})
149149
list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch})
150150
set(CAN_TARGET_${arch} 1)
151151
endforeach()

0 commit comments

Comments
 (0)