Skip to content

Commit 5a87c0c

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 (cherry picked from commit ef163f5)
1 parent cbc6fc0 commit 5a87c0c

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
@@ -62,43 +62,51 @@ if(APPLE)
6262
set(DARWIN_osx_BUILTIN_MIN_VER 10.5)
6363
set(DARWIN_osx_BUILTIN_MIN_VER_FLAG
6464
-mmacosx-version-min=${DARWIN_osx_BUILTIN_MIN_VER})
65+
set(DARWIN_osx_BUILTIN_ALL_POSSIBLE_ARCHS ${X86} ${X86_64})
6566

6667
if(COMPILER_RT_ENABLE_IOS)
6768
list(APPEND DARWIN_EMBEDDED_PLATFORMS ios)
6869
set(DARWIN_ios_MIN_VER_FLAG -miphoneos-version-min)
6970
set(DARWIN_ios_BUILTIN_MIN_VER 6.0)
7071
set(DARWIN_ios_BUILTIN_MIN_VER_FLAG
7172
${DARWIN_ios_MIN_VER_FLAG}=${DARWIN_ios_BUILTIN_MIN_VER})
73+
set(DARWIN_ios_BUILTIN_ALL_POSSIBLE_ARCHS ${ARM64} ${ARM32})
74+
set(DARWIN_iossim_BUILTIN_ALL_POSSIBLE_ARCHS ${X86} ${X86_64})
7275
endif()
7376
if(COMPILER_RT_ENABLE_WATCHOS)
7477
list(APPEND DARWIN_EMBEDDED_PLATFORMS watchos)
7578
set(DARWIN_watchos_MIN_VER_FLAG -mwatchos-version-min)
7679
set(DARWIN_watchos_BUILTIN_MIN_VER 2.0)
7780
set(DARWIN_watchos_BUILTIN_MIN_VER_FLAG
7881
${DARWIN_watchos_MIN_VER_FLAG}=${DARWIN_watchos_BUILTIN_MIN_VER})
82+
set(DARWIN_watchos_BUILTIN_ALL_POSSIBLE_ARCHS armv7 armv7k)
83+
set(DARWIN_watchossim_BUILTIN_ALL_POSSIBLE_ARCHS ${X86})
7984
endif()
8085
if(COMPILER_RT_ENABLE_TVOS)
8186
list(APPEND DARWIN_EMBEDDED_PLATFORMS tvos)
8287
set(DARWIN_tvos_MIN_VER_FLAG -mtvos-version-min)
8388
set(DARWIN_tvos_BUILTIN_MIN_VER 9.0)
8489
set(DARWIN_tvos_BUILTIN_MIN_VER_FLAG
8590
${DARWIN_tvos_MIN_VER_FLAG}=${DARWIN_tvos_BUILTIN_MIN_VER})
91+
set(DARWIN_tvos_BUILTIN_ALL_POSSIBLE_ARCHS armv7 arm64)
92+
set(DARWIN_tvossim_BUILTIN_ALL_POSSIBLE_ARCHS ${X86} ${X86_64})
8693
endif()
8794

8895
set(BUILTIN_SUPPORTED_OS osx)
8996

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

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

113121
set(DARWIN_${platform}sim_SKIP_CC_KEXT On)
114122

115-
set(test_arches ${DARWIN_sim_ARCHS})
116-
if(DARWIN_${platform}sim_ARCHS)
117-
set(test_arches DARWIN_${platform}sim_ARCHS)
118-
endif()
119-
120123
darwin_test_archs(${platform}sim
121-
DARWIN_${platform}sim_ARCHS
122-
${test_arches})
123-
message(STATUS "${platform} Simulator supported builtin arches: ${DARWIN_${platform}sim_ARCHS}")
124-
if(DARWIN_${platform}sim_ARCHS)
124+
DARWIN_${platform}sim_BUILTIN_ARCHS
125+
${DARWIN_${platform}sim_BUILTIN_ALL_POSSIBLE_ARCHS}
126+
)
127+
message(STATUS "${platform} Simulator supported builtin arches: ${DARWIN_${platform}sim_BUILTIN_ARCHS}")
128+
if(DARWIN_${platform}sim_BUILTIN_ARCHS)
125129
list(APPEND BUILTIN_SUPPORTED_OS ${platform}sim)
126130
endif()
127-
foreach(arch ${DARWIN_${platform}sim_ARCHS})
131+
foreach(arch ${DARWIN_${platform}sim_BUILTIN_ARCHS})
128132
list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch})
129133
set(CAN_TARGET_${arch} 1)
130134
endforeach()
131135
endif()
132136

133137
if(DARWIN_${platform}_SYSROOT)
134-
set(test_arches ${DARWIN_device_ARCHS})
135-
if(DARWIN_${platform}_ARCHS)
136-
set(test_arches DARWIN_${platform}_ARCHS)
137-
endif()
138-
139138
darwin_test_archs(${platform}
140-
DARWIN_${platform}_ARCHS
141-
${test_arches})
142-
message(STATUS "${platform} supported builtin arches: ${DARWIN_${platform}_ARCHS}")
143-
if(DARWIN_${platform}_ARCHS)
139+
DARWIN_${platform}_BUILTIN_ARCHS
140+
${DARWIN_${platform}_BUILTIN_ALL_POSSIBLE_ARCHS}
141+
)
142+
message(STATUS "${platform} supported builtin arches: ${DARWIN_${platform}_BUILTIN_ARCHS}")
143+
if(DARWIN_${platform}_BUILTIN_ARCHS)
144144
list(APPEND BUILTIN_SUPPORTED_OS ${platform})
145145
endif()
146-
foreach(arch ${DARWIN_${platform}_ARCHS})
146+
foreach(arch ${DARWIN_${platform}_BUILTIN_ARCHS})
147147
list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch})
148148
set(CAN_TARGET_${arch} 1)
149149
endforeach()

0 commit comments

Comments
 (0)