Skip to content

Commit 2cf990f

Browse files
committed
Revert r363633 "[CMake] Fix the value of config.target_cflags for non-macOS Apple platforms. Attempt #2."
This caused Chromium's clang package to stop building, see comment on https://reviews.llvm.org/D61242 for details. > Summary: > The main problem here is that `-*-version_min=` was not being passed to > the compiler when building test cases. This can cause problems when > testing on devices running older OSs because Clang would previously > assume the minimum deployment target is the the latest OS in the SDK > which could be much newer than what the device is running. > > Previously the generated value looked like this: > > `-arch arm64 -isysroot > <path_to_xcode>/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.1.sdk` > > With this change it now looks like: > > `-arch arm64 -stdlib=libc++ -miphoneos-version-min=8.0 -isysroot > <path_to_xcode>/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.1.sdk` > > This mirrors the setting of `config.target_cflags` on macOS. > > This change is made for ASan, LibFuzzer, TSan, and UBSan. > > To implement this a new `get_test_cflags_for_apple_platform()` function > has been added that when given an Apple platform name and architecture > returns a string containing the C compiler flags to use when building > tests. This also calls a new helper function `is_valid_apple_platform()` > that validates Apple platform names. > > This is the second attempt at landing the patch. The first attempt (r359305) > had to be reverted (r359327) due to a buildbot failure. The problem was > that calling `get_test_cflags_for_apple_platform()` can trigger a CMake > error if the provided architecture is not supported by the current > CMake configuration. Previously, this could be triggered by passing > `-DCOMPILER_RT_ENABLE_IOS=OFF` to CMake. The root cause is that we were > generating test configurations for a list of architectures without > checking if the relevant Sanitizer actually supported that architecture. > We now intersect the list of architectures for an Apple platform > with `<SANITIZER>_SUPPORTED_ARCH` (where `<SANITIZER>` is a Sanitizer > name) to iterate through the correct list of architectures. > > rdar://problem/50124489 > > Reviewers: kubamracek, yln, vsk, juliehockett, phosek > > Subscribers: mgorny, javed.absar, kristof.beyls, #sanitizers, llvm-commits > > Tags: #llvm, #sanitizers > > Differential Revision: https://reviews.llvm.org/D61242 llvm-svn: 363779
1 parent cd31e78 commit 2cf990f

File tree

5 files changed

+35
-97
lines changed

5 files changed

+35
-97
lines changed

Diff for: compiler-rt/cmake/config-ix.cmake

-26
Original file line numberDiff line numberDiff line change
@@ -208,32 +208,6 @@ macro(get_test_cc_for_arch arch cc_out cflags_out)
208208
endif()
209209
endmacro()
210210

211-
# Returns CFLAGS that should be used to run tests for the
212-
# specific apple platform and architecture.
213-
function(get_test_cflags_for_apple_platform platform arch cflags_out)
214-
is_valid_apple_platform("${platform}" is_valid_platform)
215-
if (NOT is_valid_platform)
216-
message(FATAL_ERROR "\"${platform}\" is not a valid apple platform")
217-
endif()
218-
set(test_cflags "")
219-
get_target_flags_for_arch(${arch} test_cflags)
220-
list(APPEND test_cflags ${DARWIN_${platform}_CFLAGS})
221-
string(REPLACE ";" " " test_cflags_str "${test_cflags}")
222-
string(APPEND test_cflags_str "${COMPILER_RT_TEST_COMPILER_CFLAGS}")
223-
set(${cflags_out} "${test_cflags_str}" PARENT_SCOPE)
224-
endfunction()
225-
226-
function(is_valid_apple_platform platform is_valid_out)
227-
set(is_valid FALSE)
228-
if ("${platform}" STREQUAL "")
229-
message(FATAL_ERROR "platform cannot be empty")
230-
endif()
231-
if ("${platform}" MATCHES "^(osx|((ios|watchos|tvos)(sim)?))$")
232-
set(is_valid TRUE)
233-
endif()
234-
set(${is_valid_out} ${is_valid} PARENT_SCOPE)
235-
endfunction()
236-
237211
set(ARM64 aarch64)
238212
set(ARM32 arm armhf)
239213
set(HEXAGON hexagon)

Diff for: compiler-rt/test/asan/CMakeLists.txt

+4-15
Original file line numberDiff line numberDiff line change
@@ -81,22 +81,15 @@ endforeach()
8181
# variable to select which iOS device or simulator to use, e.g.:
8282
# SANITIZER_IOSSIM_TEST_DEVICE_IDENTIFIER="iPhone 6"
8383
if(APPLE)
84-
# FIXME(dliew): This logic should be refactored to the way UBSan Darwin
85-
# testing is done.
8684
set(EXCLUDE_FROM_ALL ON)
8785

8886
set(ASAN_TEST_TARGET_CC ${COMPILER_RT_TEST_COMPILER})
8987
set(ASAN_TEST_DYNAMIC True)
9088

91-
list_intersect(ASAN_TEST_IOSSIM_ARCHS ASAN_SUPPORTED_ARCH DARWIN_iossim_ARCHS)
92-
foreach(arch ${ASAN_TEST_IOSSIM_ARCHS})
89+
foreach(arch ${DARWIN_iossim_ARCHS})
9390
set(ASAN_TEST_APPLE_PLATFORM "iossim")
9491
set(ASAN_TEST_TARGET_ARCH ${arch})
95-
get_test_cflags_for_apple_platform(
96-
"${ASAN_TEST_APPLE_PLATFORM}"
97-
"${ASAN_TEST_TARGET_ARCH}"
98-
ASAN_TEST_TARGET_CFLAGS
99-
)
92+
set(ASAN_TEST_TARGET_CFLAGS "-arch ${arch} -isysroot ${DARWIN_iossim_SYSROOT} ${COMPILER_RT_TEST_COMPILER_CFLAGS}")
10093
set(ASAN_TEST_CONFIG_SUFFIX "-${arch}-${ASAN_TEST_APPLE_PLATFORM}")
10194
get_bits_for_arch(${arch} ASAN_TEST_BITS)
10295
string(TOUPPER ${arch} ARCH_UPPER_CASE)
@@ -110,14 +103,10 @@ if(APPLE)
110103
DEPENDS ${ASAN_TEST_DEPS})
111104
endforeach()
112105

113-
list_intersect(ASAN_TEST_IOS_ARCHS ASAN_SUPPORTED_ARCH DARWIN_ios_ARCHS)
114-
foreach (arch ${ASAN_TEST_IOS_ARCHS})
106+
foreach (arch ${DARWIN_ios_ARCHS})
115107
set(ASAN_TEST_APPLE_PLATFORM "ios")
116108
set(ASAN_TEST_TARGET_ARCH ${arch})
117-
get_test_cflags_for_apple_platform(
118-
"${ASAN_TEST_APPLE_PLATFORM}"
119-
"${arch}"
120-
ASAN_TEST_TARGET_CFLAGS)
109+
set(ASAN_TEST_TARGET_CFLAGS "-arch ${arch} -isysroot ${DARWIN_ios_SYSROOT} ${COMPILER_RT_TEST_COMPILER_CFLAGS}")
121110
set(ASAN_TEST_CONFIG_SUFFIX "-${arch}-${ASAN_TEST_APPLE_PLATFORM}")
122111
get_bits_for_arch(${arch} ASAN_TEST_BITS)
123112
string(TOUPPER ${arch} ARCH_UPPER_CASE)

Diff for: compiler-rt/test/fuzzer/CMakeLists.txt

+2-9
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,12 @@ if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
8989
endif()
9090

9191
if (APPLE)
92-
# FIXME(dliew): This logic should be refactored to the way UBSan Darwin
93-
# testing is done.
9492
set(EXCLUDE_FROM_ALL ON)
9593

96-
list_intersect(FUZZER_TEST_IOS_ARCHS FUZZER_SUPPORTED_ARCH DARWIN_ios_ARCHS)
97-
foreach(arch ${FUZZER_TEST_IOS_ARCHS})
94+
foreach(arch ${DARWIN_ios_ARCHS})
9895
set(LIBFUZZER_TEST_APPLE_PLATFORM "ios")
9996
set(LIBFUZZER_TEST_TARGET_ARCH ${arch})
100-
get_test_cflags_for_apple_platform(
101-
"${LIBFUZZER_TEST_APPLE_PLATFORM}"
102-
"${LIBFUZZER_TEST_TARGET_ARCH}"
103-
LIBFUZZER_TEST_FLAGS
104-
)
97+
set(LIBFUZZER_TEST_FLAGS "-arch ${arch} -isysroot ${DARWIN_ios_SYSROOT} ${COMPILER_RT_TEST_COMPILER_CFLAGS}")
10598
set(LIBFUZZER_TEST_CONFIG_SUFFIX "-${arch}-${LIBFUZZER_TEST_APPLE_PLATFORM}")
10699
string(TOUPPER ${arch} ARCH_UPPER_CASE)
107100
set(CONFIG_NAME "IOS${ARCH_UPPER_CASE}Config")

Diff for: compiler-rt/test/tsan/CMakeLists.txt

+28-42
Original file line numberDiff line numberDiff line change
@@ -49,53 +49,39 @@ endforeach()
4949
# variable to select which iOS device or simulator to use, e.g.:
5050
# SANITIZER_IOSSIM_TEST_DEVICE_IDENTIFIER="iPhone 6"
5151
if(APPLE)
52-
# FIXME(dliew): This logic should be refactored to the way UBSan Darwin
53-
# testing is done.
5452
set(EXCLUDE_FROM_ALL ON)
5553

5654
set(TSAN_TEST_TARGET_CC ${COMPILER_RT_TEST_COMPILER})
5755

58-
list_intersect(TSAN_TEST_IOSSIM_ARCHS TSAN_SUPPORTED_ARCH DARWIN_iossim_ARCHS)
59-
foreach(arch ${TSAN_TEST_IOSSIM_ARCHS})
60-
set(TSAN_TEST_APPLE_PLATFORM "iossim")
61-
set(TSAN_TEST_TARGET_ARCH ${arch})
62-
get_test_cflags_for_apple_platform(
63-
"${TSAN_TEST_APPLE_PLATFORM}"
64-
"${TSAN_TEST_TARGET_ARCH}"
65-
TSAN_TEST_TARGET_CFLAGS
66-
)
67-
set(TSAN_TEST_CONFIG_SUFFIX "-${arch}-${TSAN_TEST_APPLE_PLATFORM}")
68-
string(TOUPPER ${arch} ARCH_UPPER_CASE)
69-
set(CONFIG_NAME "IOSSim${ARCH_UPPER_CASE}Config")
70-
configure_lit_site_cfg(
71-
${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
72-
${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg
73-
)
74-
add_lit_testsuite(check-tsan-iossim-${arch} "ThreadSanitizer iOS Simulator ${arch} tests"
75-
${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/
76-
DEPENDS ${TSAN_TEST_DEPS})
77-
endforeach()
56+
set(TSAN_TEST_APPLE_PLATFORM "iossim")
57+
set(arch "x86_64")
58+
set(TSAN_TEST_TARGET_ARCH ${arch})
59+
set(TSAN_TEST_TARGET_CFLAGS "-arch ${arch} -isysroot ${DARWIN_iossim_SYSROOT} ${COMPILER_RT_TEST_COMPILER_CFLAGS}")
60+
set(TSAN_TEST_CONFIG_SUFFIX "-${arch}-${TSAN_TEST_APPLE_PLATFORM}")
61+
string(TOUPPER ${arch} ARCH_UPPER_CASE)
62+
set(CONFIG_NAME "IOSSim${ARCH_UPPER_CASE}Config")
63+
configure_lit_site_cfg(
64+
${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
65+
${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg
66+
)
67+
add_lit_testsuite(check-tsan-iossim-${arch} "ThreadSanitizer iOS Simulator ${arch} tests"
68+
${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/
69+
DEPENDS ${TSAN_TEST_DEPS})
7870

79-
list_intersect(TSAN_TEST_IOS_ARCHS TSAN_SUPPORTED_ARCH DARWIN_ios_ARCHS)
80-
foreach(arch ${TSAN_TEST_IOS_ARCHS})
81-
set(TSAN_TEST_APPLE_PLATFORM "ios")
82-
set(TSAN_TEST_TARGET_ARCH ${arch})
83-
get_test_cflags_for_apple_platform(
84-
"${TSAN_TEST_APPLE_PLATFORM}"
85-
"${TSAN_TEST_TARGET_ARCH}"
86-
TSAN_TEST_TARGET_CFLAGS
87-
)
88-
set(TSAN_TEST_CONFIG_SUFFIX "-${arch}-${TSAN_TEST_APPLE_PLATFORM}")
89-
string(TOUPPER ${arch} ARCH_UPPER_CASE)
90-
set(CONFIG_NAME "IOS${ARCH_UPPER_CASE}Config")
91-
configure_lit_site_cfg(
92-
${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
93-
${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg
94-
)
95-
add_lit_testsuite(check-tsan-ios-${arch} "ThreadSanitizer iOS ${arch} tests"
96-
${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/
97-
DEPENDS ${TSAN_TEST_DEPS})
98-
endforeach()
71+
set(TSAN_TEST_APPLE_PLATFORM "ios")
72+
set(arch "arm64")
73+
set(TSAN_TEST_TARGET_ARCH ${arch})
74+
set(TSAN_TEST_TARGET_CFLAGS "-arch ${arch} -isysroot ${DARWIN_ios_SYSROOT} ${COMPILER_RT_TEST_COMPILER_CFLAGS}")
75+
set(TSAN_TEST_CONFIG_SUFFIX "-${arch}-${TSAN_TEST_APPLE_PLATFORM}")
76+
string(TOUPPER ${arch} ARCH_UPPER_CASE)
77+
set(CONFIG_NAME "IOS${ARCH_UPPER_CASE}Config")
78+
configure_lit_site_cfg(
79+
${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
80+
${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg
81+
)
82+
add_lit_testsuite(check-tsan-ios-${arch} "ThreadSanitizer iOS Simulator ${arch} tests"
83+
${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/
84+
DEPENDS ${TSAN_TEST_DEPS})
9985

10086
set(EXCLUDE_FROM_ALL OFF)
10187
endif()

Diff for: compiler-rt/test/ubsan/CMakeLists.txt

+1-5
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,7 @@ if(APPLE)
113113
endif()
114114
foreach(platform ${UBSAN_APPLE_PLATFORMS})
115115
foreach(arch ${DARWIN_${platform}_ARCHS})
116-
get_test_cflags_for_apple_platform(
117-
"${platform}"
118-
"${arch}"
119-
UBSAN_TEST_TARGET_CFLAGS
120-
)
116+
set(UBSAN_TEST_TARGET_CFLAGS "-arch ${arch} -isysroot ${DARWIN_${platform}_SYSROOT}")
121117
if (";${UBSAN_SUPPORTED_ARCH};" MATCHES ";${arch};")
122118
add_ubsan_device_testsuite("Standalone" ubsan ${platform} ${arch})
123119
endif()

0 commit comments

Comments
 (0)