Skip to content

Commit 8b33b2f

Browse files
authored
Merge pull request swiftlang#25762 from compnerd/cmpxchg
build: add a workaround for android NDK[<21]
2 parents 8a0e7ba + 01e195c commit 8b33b2f

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

cmake/modules/AddSwift.cmake

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,21 @@ function(_add_variant_c_compile_flags)
288288
endif()
289289
endif()
290290

291+
if(CFLAGS_SDK STREQUAL ANDROID)
292+
if(CFLAGS_ARCH STREQUAL x86_64)
293+
# NOTE(compnerd) Android NDK 21 or lower will generate library calls to
294+
# `__sync_val_compare_and_swap_16` rather than lowering to the CPU's
295+
# `cmpxchg16b` instruction as the `cx16` feature is disabled due to a bug
296+
# in Clang. This is being fixed in the current master Clang and will
297+
# hopefully make it into Clang 9.0. In the mean time, workaround this in
298+
# the build.
299+
if(CMAKE_C_COMPILER_ID MATCHES Clang AND CMAKE_C_COMPILER_VERSION
300+
VERSION_LESS 9.0.0)
301+
list(APPEND result -mcx16)
302+
endif()
303+
endif()
304+
endif()
305+
291306
if(CFLAGS_ENABLE_ASSERTIONS)
292307
list(APPEND result "-UNDEBUG")
293308
else()

0 commit comments

Comments
 (0)