Skip to content

Commit 7c52fe2

Browse files
committed
[CMake] Workaround sanitizer flag bug in swift driver
Some versions of the swift driver have a bug where passing `-sanitize=` does not emit the correct `-fsanitize=` flag for the clang link step. Although this is being fixed, we must be able to correctly build with older versions of the swift driver for some period of time. We workaround that issue by explicitly passing the correct `-fsanitize=` argument ourselves. This works around rdar://107733898
1 parent cd439ba commit 7c52fe2

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

cmake/modules/AddSwift.cmake

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ endfunction()
8686
function(_add_host_variant_swift_sanitizer_flags target)
8787
if(LLVM_USE_SANITIZER)
8888
if(LLVM_USE_SANITIZER STREQUAL "Address")
89-
set(_Swift_SANITIZER_FLAGS "-sanitize=address")
89+
set(_Swift_SANITIZER_FLAGS "-sanitize=address" "-Xclang-linker" "-fsanitize=address")
9090
elseif(LLVM_USE_SANITIZER STREQUAL "HWAddress")
9191
# Not supported?
9292
elseif(LLVM_USE_SANITIZER MATCHES "Memory(WithOrigins)?")
@@ -95,14 +95,14 @@ function(_add_host_variant_swift_sanitizer_flags target)
9595
# Not supported
9696
endif()
9797
elseif(LLVM_USE_SANITIZER STREQUAL "Undefined")
98-
set(_Swift_SANITIZER_FLAGS "-sanitize=undefined")
98+
set(_Swift_SANITIZER_FLAGS "-sanitize=undefined" "-Xclang-linker" "-fsanitize=undefined")
9999
elseif(LLVM_USE_SANITIZER STREQUAL "Thread")
100-
set(_Swift_SANITIZER_FLAGS "-sanitize=thread")
100+
set(_Swift_SANITIZER_FLAGS "-sanitize=thread" "-Xclang-linker" "-fsanitize=thread")
101101
elseif(LLVM_USE_SANITIZER STREQUAL "DataFlow")
102102
# Not supported
103103
elseif(LLVM_USE_SANITIZER STREQUAL "Address;Undefined" OR
104104
LLVM_USE_SANITIZER STREQUAL "Undefined;Address")
105-
set(_Swift_SANITIZER_FLAGS "-sanitize=address" "-sanitize=undefined")
105+
set(_Swift_SANITIZER_FLAGS "-sanitize=address" "-sanitize=undefined" "-Xclang-linker" "-fsanitize=address" "-Xclang-linker" "-fsanitize=undefined")
106106
elseif(LLVM_USE_SANITIZER STREQUAL "Leaks")
107107
# Not supported
108108
else()

0 commit comments

Comments
 (0)