[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
This commit is contained in:
Dan Liew 2019-09-13 17:31:22 +00:00
parent d38f63e5f4
commit ef163f5a20
2 changed files with 32 additions and 31 deletions

View File

@ -94,7 +94,8 @@ function(darwin_test_archs os valid_archs)
set(arch_linker_flags "-arch ${arch} ${os_linker_flags}")
if(TEST_COMPILE_ONLY)
try_compile_only(CAN_TARGET_${os}_${arch} FLAGS -v -arch ${arch} ${DARWIN_${os}_CFLAGS})
# `-w` is used to surpress compiler warnings which `try_compile_only()` treats as an error.
try_compile_only(CAN_TARGET_${os}_${arch} FLAGS -v -arch ${arch} ${DARWIN_${os}_CFLAGS} -w)
else()
set(SAVED_CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS})
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${arch_linker_flags}")
@ -282,7 +283,7 @@ macro(darwin_add_builtin_libraries)
../profile/InstrProfilingPlatformDarwin
../profile/InstrProfilingWriter)
foreach (os ${ARGN})
list_intersect(DARWIN_BUILTIN_ARCHS DARWIN_${os}_ARCHS BUILTIN_SUPPORTED_ARCH)
list_intersect(DARWIN_BUILTIN_ARCHS DARWIN_${os}_BUILTIN_ARCHS BUILTIN_SUPPORTED_ARCH)
foreach (arch ${DARWIN_BUILTIN_ARCHS})
darwin_find_excluded_builtins_list(${arch}_${os}_EXCLUDED_BUILTINS
OS ${os}

View File

@ -64,6 +64,7 @@ if(APPLE)
set(DARWIN_osx_BUILTIN_MIN_VER 10.5)
set(DARWIN_osx_BUILTIN_MIN_VER_FLAG
-mmacosx-version-min=${DARWIN_osx_BUILTIN_MIN_VER})
set(DARWIN_osx_BUILTIN_ALL_POSSIBLE_ARCHS ${X86} ${X86_64})
if(COMPILER_RT_ENABLE_IOS)
list(APPEND DARWIN_EMBEDDED_PLATFORMS ios)
@ -71,6 +72,8 @@ if(APPLE)
set(DARWIN_ios_BUILTIN_MIN_VER 6.0)
set(DARWIN_ios_BUILTIN_MIN_VER_FLAG
${DARWIN_ios_MIN_VER_FLAG}=${DARWIN_ios_BUILTIN_MIN_VER})
set(DARWIN_ios_BUILTIN_ALL_POSSIBLE_ARCHS ${ARM64} ${ARM32})
set(DARWIN_iossim_BUILTIN_ALL_POSSIBLE_ARCHS ${X86} ${X86_64})
endif()
if(COMPILER_RT_ENABLE_WATCHOS)
list(APPEND DARWIN_EMBEDDED_PLATFORMS watchos)
@ -78,6 +81,8 @@ if(APPLE)
set(DARWIN_watchos_BUILTIN_MIN_VER 2.0)
set(DARWIN_watchos_BUILTIN_MIN_VER_FLAG
${DARWIN_watchos_MIN_VER_FLAG}=${DARWIN_watchos_BUILTIN_MIN_VER})
set(DARWIN_watchos_BUILTIN_ALL_POSSIBLE_ARCHS armv7 armv7k)
set(DARWIN_watchossim_BUILTIN_ALL_POSSIBLE_ARCHS ${X86})
endif()
if(COMPILER_RT_ENABLE_TVOS)
list(APPEND DARWIN_EMBEDDED_PLATFORMS tvos)
@ -85,6 +90,8 @@ if(APPLE)
set(DARWIN_tvos_BUILTIN_MIN_VER 9.0)
set(DARWIN_tvos_BUILTIN_MIN_VER_FLAG
${DARWIN_tvos_MIN_VER_FLAG}=${DARWIN_tvos_BUILTIN_MIN_VER})
set(DARWIN_tvos_BUILTIN_ALL_POSSIBLE_ARCHS armv7 arm64)
set(DARWIN_tvossim_BUILTIN_ALL_POSSIBLE_ARCHS ${X86} ${X86_64})
endif()
set(BUILTIN_SUPPORTED_OS osx)
@ -92,15 +99,16 @@ if(APPLE)
# We're setting the flag manually for each target OS
set(CMAKE_OSX_DEPLOYMENT_TARGET "")
if(NOT DARWIN_osx_ARCHS)
set(DARWIN_osx_ARCHS i386 x86_64 x86_64h)
endif()
set(DARWIN_sim_ARCHS i386 x86_64)
set(DARWIN_device_ARCHS armv7 armv7s armv7k arm64)
message(STATUS "OSX supported arches: ${DARWIN_osx_ARCHS}")
foreach(arch ${DARWIN_osx_ARCHS})
# NOTE: We deliberately avoid using `DARWIN_<os>_ARCHS` here because that is
# used by `config-ix.cmake` in the context of building the rest of
# compiler-rt where the global `${TEST_COMPILE_ONLY}` (used by
# `darwin_test_archs()`) has a different value.
darwin_test_archs(osx
DARWIN_osx_BUILTIN_ARCHS
${DARWIN_osx_BUILTIN_ALL_POSSIBLE_ARCHS}
)
message(STATUS "OSX supported builtin arches: ${DARWIN_osx_BUILTIN_ARCHS}")
foreach(arch ${DARWIN_osx_BUILTIN_ARCHS})
list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch})
set(CAN_TARGET_${arch} 1)
endforeach()
@ -114,38 +122,30 @@ if(APPLE)
set(DARWIN_${platform}sim_SKIP_CC_KEXT On)
set(test_arches ${DARWIN_sim_ARCHS})
if(DARWIN_${platform}sim_ARCHS)
set(test_arches DARWIN_${platform}sim_ARCHS)
endif()
darwin_test_archs(${platform}sim
DARWIN_${platform}sim_ARCHS
${test_arches})
message(STATUS "${platform} Simulator supported builtin arches: ${DARWIN_${platform}sim_ARCHS}")
if(DARWIN_${platform}sim_ARCHS)
DARWIN_${platform}sim_BUILTIN_ARCHS
${DARWIN_${platform}sim_BUILTIN_ALL_POSSIBLE_ARCHS}
)
message(STATUS "${platform} Simulator supported builtin arches: ${DARWIN_${platform}sim_BUILTIN_ARCHS}")
if(DARWIN_${platform}sim_BUILTIN_ARCHS)
list(APPEND BUILTIN_SUPPORTED_OS ${platform}sim)
endif()
foreach(arch ${DARWIN_${platform}sim_ARCHS})
foreach(arch ${DARWIN_${platform}sim_BUILTIN_ARCHS})
list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch})
set(CAN_TARGET_${arch} 1)
endforeach()
endif()
if(DARWIN_${platform}_SYSROOT)
set(test_arches ${DARWIN_device_ARCHS})
if(DARWIN_${platform}_ARCHS)
set(test_arches DARWIN_${platform}_ARCHS)
endif()
darwin_test_archs(${platform}
DARWIN_${platform}_ARCHS
${test_arches})
message(STATUS "${platform} supported builtin arches: ${DARWIN_${platform}_ARCHS}")
if(DARWIN_${platform}_ARCHS)
DARWIN_${platform}_BUILTIN_ARCHS
${DARWIN_${platform}_BUILTIN_ALL_POSSIBLE_ARCHS}
)
message(STATUS "${platform} supported builtin arches: ${DARWIN_${platform}_BUILTIN_ARCHS}")
if(DARWIN_${platform}_BUILTIN_ARCHS)
list(APPEND BUILTIN_SUPPORTED_OS ${platform})
endif()
foreach(arch ${DARWIN_${platform}_ARCHS})
foreach(arch ${DARWIN_${platform}_BUILTIN_ARCHS})
list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch})
set(CAN_TARGET_${arch} 1)
endforeach()