Skip to content

Commit 76243a2

Browse files
authoredJan 28, 2025
[windows][toolchain] Build sanitizers and builtins standalone for all SDKs (#78861)
Unified builds of compiler-rt together with LLVM failed for the Android SDKs. It got too complicated to redirect the way LLVM would configure the nested build-trees. Standalone builds slightly increase build time, but they turned out much simpler and we end up with less duplication of definitions.

9 files changed

+62
-76
lines changed
 

‎cmake/caches/Windows-aarch64.cmake

-17
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,6 @@ set(LLVM_DEFAULT_TARGET_TRIPLE aarch64-unknown-windows-msvc CACHE STRING "")
2626
set(LLVM_APPEND_VC_REV NO CACHE BOOL "")
2727
set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR YES CACHE BOOL "")
2828
set(LLVM_ENABLE_PYTHON YES CACHE BOOL "")
29-
set(LLVM_RUNTIME_TARGETS
30-
aarch64-unknown-windows-msvc
31-
CACHE STRING "")
32-
foreach(target ${LLVM_RUNTIME_TARGETS})
33-
set(RUNTIMES_${target}_LLVM_ENABLE_RUNTIMES
34-
compiler-rt
35-
CACHE STRING "")
36-
set(RUNTIMES_${target}_CMAKE_MT mt CACHE STRING "")
37-
set(RUNTIMES_${target}_CMAKE_SYSTEM_NAME Windows CACHE STRING "")
38-
set(RUNTIMES_${target}_CMAKE_BUILD_TYPE Release CACHE STRING "")
39-
set(RUNTIMES_${target}_COMPILER_RT_BUILD_CRT NO CACHE BOOL "")
40-
set(RUNTIMES_${target}_COMPILER_RT_BUILD_LIBFUZZER NO CACHE BOOL "")
41-
set(RUNTIMES_${target}_COMPILER_RT_BUILD_PROFILE YES CACHE BOOL "")
42-
set(RUNTIMES_${target}_COMPILER_RT_BUILD_SANITIZERS NO CACHE BOOL "")
43-
set(RUNTIMES_${target}_COMPILER_RT_BUILD_XRAY NO CACHE BOOL "")
44-
endforeach()
4529

4630
set(LLVM_TARGETS_TO_BUILD AArch64 ARM WebAssembly X86 CACHE STRING "")
4731

@@ -167,7 +151,6 @@ set(LLVM_DISTRIBUTION_COMPONENTS
167151
libclang
168152
libclang-headers
169153
LTO
170-
runtimes
171154
${LLVM_TOOLCHAIN_TOOLS}
172155
${CLANG_TOOLS}
173156
${LLD_TOOLS}

‎cmake/caches/Windows-x86_64.cmake

-58
Original file line numberDiff line numberDiff line change
@@ -27,62 +27,6 @@ set(LLVM_APPEND_VC_REV NO CACHE BOOL "")
2727
set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR YES CACHE BOOL "")
2828
set(LLVM_ENABLE_PYTHON YES CACHE BOOL "")
2929

30-
set(DEFAULT_BUILTIN_TARGETS
31-
x86_64-unknown-windows-msvc
32-
aarch64-unknown-windows-msvc)
33-
# Build the android builtins if NDK path is provided.
34-
if(NOT "$ENV{NDKPATH}" STREQUAL "")
35-
list(APPEND DEFAULT_BUILTIN_TARGETS
36-
aarch64-unknown-linux-android
37-
x86_64-unknown-linux-android)
38-
endif()
39-
40-
# The builtin targets are used to build the compiler-rt builtins.
41-
set(LLVM_BUILTIN_TARGETS ${DEFAULT_BUILTIN_TARGETS} CACHE STRING "")
42-
43-
# The runtime targets are used to build the compiler-rt profile library.
44-
set(LLVM_RUNTIME_TARGETS
45-
x86_64-unknown-windows-msvc
46-
aarch64-unknown-windows-msvc
47-
CACHE STRING "")
48-
49-
foreach(target ${LLVM_RUNTIME_TARGETS})
50-
set(RUNTIMES_${target}_LLVM_ENABLE_RUNTIMES
51-
compiler-rt
52-
CACHE STRING "")
53-
set(RUNTIMES_${target}_CMAKE_MT mt CACHE STRING "")
54-
set(RUNTIMES_${target}_CMAKE_SYSTEM_NAME Windows CACHE STRING "")
55-
set(RUNTIMES_${target}_CMAKE_BUILD_TYPE Release CACHE STRING "")
56-
set(RUNTIMES_${target}_COMPILER_RT_BUILD_BUILTINS NO CACHE BOOL "")
57-
set(RUNTIMES_${target}_COMPILER_RT_BUILD_CRT NO CACHE BOOL "")
58-
set(RUNTIMES_${target}_COMPILER_RT_BUILD_LIBFUZZER NO CACHE BOOL "")
59-
set(RUNTIMES_${target}_COMPILER_RT_BUILD_ORC NO CACHE BOOL "")
60-
set(RUNTIMES_${target}_COMPILER_RT_BUILD_PROFILE YES CACHE BOOL "")
61-
set(RUNTIMES_${target}_COMPILER_RT_BUILD_SANITIZERS NO CACHE BOOL "")
62-
set(RUNTIMES_${target}_COMPILER_RT_BUILD_XRAY NO CACHE BOOL "")
63-
endforeach()
64-
65-
foreach(target ${LLVM_BUILTIN_TARGETS})
66-
set(BUILTINS_${target}_CMAKE_MT mt CACHE STRING "")
67-
if(${target} MATCHES windows-msvc)
68-
set(BUILTINS_${target}_CMAKE_SYSTEM_NAME Windows CACHE STRING "")
69-
elseif(${target} MATCHES linux-android)
70-
# Use a single 'linux' directory and arch-based lib names on Android.
71-
set(BUILTINS_${target}_LLVM_ENABLE_PER_TARGET_RUNTIME_DIR NO CACHE BOOL "")
72-
set(BUILTINS_${target}_CMAKE_SYSTEM_NAME Android CACHE STRING "")
73-
if(${target} MATCHES aarch64)
74-
set(BUILTINS_${target}_CMAKE_ANDROID_ARCH_ABI arm64-v8a CACHE STRING "")
75-
else()
76-
set(BUILTINS_${target}_CMAKE_ANDROID_ARCH_ABI x86_64 CACHE STRING "")
77-
endif()
78-
set(BUILTINS_${target}_CMAKE_ANDROID_NDK $ENV{NDKPATH} CACHE PATH "")
79-
set(BUILTINS_${target}_CMAKE_ANDROID_API 21 CACHE STRING "")
80-
set(BUILTINS_${target}_CMAKE_C_COMPILER_TARGET "${target}21" CACHE STRING "")
81-
set(BUILTINS_${target}_CMAKE_CXX_COMPILER_TARGET "${target}21" CACHE STRING "")
82-
endif()
83-
set(BUILTINS_${target}_CMAKE_BUILD_TYPE Release CACHE STRING "")
84-
endforeach()
85-
8630
set(LLVM_TARGETS_TO_BUILD AArch64 ARM WebAssembly X86 CACHE STRING "")
8731

8832
# Disable certain targets to reduce the configure time or to avoid configuration
@@ -207,8 +151,6 @@ set(LLVM_DISTRIBUTION_COMPONENTS
207151
libclang
208152
libclang-headers
209153
LTO
210-
builtins
211-
runtimes
212154
${LLVM_TOOLCHAIN_TOOLS}
213155
${CLANG_TOOLS}
214156
${LLD_TOOLS}

‎test/Driver/sanitize_coverage.swift

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// XFAIL: OS=windows-msvc
2+
13
// Different sanitizer coverage types
24
// RUN: %swiftc_driver -driver-print-jobs -sanitize-coverage=func -sanitize=address %s | %FileCheck -check-prefix=SANCOV_FUNC %s
35
// RUN: %swiftc_driver -driver-print-jobs -sanitize-coverage=bb -sanitize=address %s | %FileCheck -check-prefix=SANCOV_BB %s

‎test/IRGen/address_sanitizer_use_odr_indicator.swift

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// XFAIL: OS=windows-msvc
12
// REQUIRES: asan_runtime
23

34
// Default instrumentation that does not use ODR indicators

‎test/Interpreter/indirect_enum.swift

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// XFAIL: OS=windows-msvc
2+
13
// RUN: %target-swiftc_driver %s -g -sanitize=address -o %t_asan-binary
24
// RUN: %target-codesign %t_asan-binary
35
// RUN: env ASAN_OPTIONS=detect_leaks=0 %target-run %t_asan-binary

‎test/Reflection/typeref_decoding_asan.swift

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// UNSUPPORTED: OS=linux-gnu && CPU=aarch64
2+
// XFAIL: OS=windows-msvc
23

34
// rdar://100805115
45
// UNSUPPORTED: CPU=arm64e

‎test/Sanitizers/asan/asan.swift

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// XFAIL: OS=windows-msvc
2+
13
// RUN: %target-swiftc_driver %s -g -sanitize=address -o %t_asan-binary
24
// RUN: %target-codesign %t_asan-binary
35
// RUN: env %env-ASAN_OPTIONS=abort_on_error=0 not %target-run %t_asan-binary 2>&1 | %FileCheck %s

‎test/Sanitizers/sanitizer_coverage.swift

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// For now restrict this test to platforms where we know this test will pass
1010
// REQUIRES: CPU=x86_64
1111
// UNSUPPORTED: remote_run
12+
// XFAIL: OS=windows-msvc
1213

1314
func sayHello() {
1415
print("Hello")

‎utils/build.ps1

+53-1
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,8 @@ enum TargetComponent {
423423
Foundation
424424
XCTest
425425
Testing
426+
ClangBuiltins
427+
ClangRuntime
426428
}
427429

428430
function Get-TargetProjectBinaryCache($Arch, [TargetComponent]$Project) {
@@ -1690,13 +1692,61 @@ function Build-LLVM([Platform]$Platform, $Arch) {
16901692
-Bin (Get-TargetProjectBinaryCache $Arch LLVM) `
16911693
-Arch $Arch `
16921694
-Platform $Platform `
1693-
-UseMSVCCompilers C,CXX `
1695+
-UseBuiltCompilers C,CXX `
16941696
-Defines @{
16951697
CMAKE_SYSTEM_NAME = $Platform.ToString();
16961698
LLVM_HOST_TRIPLE = $Arch.LLVMTarget;
16971699
}
16981700
}
16991701

1702+
function Build-Sanitizers([Platform]$Platform, $Arch) {
1703+
$LLVMTargetCache = $(Get-TargetProjectBinaryCache $Arch LLVM)
1704+
$LITVersionStr = $(Invoke-Program $(Get-PythonExecutable) "$LLVMTargetCache\bin\llvm-lit.py" --version)
1705+
if (-not ($LITVersionStr -match "lit (\d+)\.\d+\.\d+.*")) {
1706+
throw "Unexpected version string output from llvm-lit.py"
1707+
}
1708+
$LLVMVersionMajor = $Matches.1
1709+
$InstallTo = "$($HostArch.ToolchainInstallRoot)\usr\lib\clang\$LLVMVersionMajor"
1710+
Write-Host "Sanitizers SDK directory: $InstallTo"
1711+
1712+
Build-CMakeProject `
1713+
-Src $SourceCache\llvm-project\compiler-rt\lib\builtins `
1714+
-Bin "$(Get-TargetProjectBinaryCache $Arch ClangBuiltins)" `
1715+
-InstallTo $InstallTo `
1716+
-Arch $Arch `
1717+
-Platform $Platform `
1718+
-UseBuiltCompilers ASM,C,CXX `
1719+
-BuildTargets "install-compiler-rt" `
1720+
-Defines (@{
1721+
CMAKE_SYSTEM_NAME = $Platform.ToString();
1722+
LLVM_DIR = "$LLVMTargetCache\lib\cmake\llvm";
1723+
LLVM_ENABLE_PER_TARGET_RUNTIME_DIR = "YES";
1724+
COMPILER_RT_DEFAULT_TARGET_ONLY = "YES";
1725+
})
1726+
1727+
Build-CMakeProject `
1728+
-Src $SourceCache\llvm-project\compiler-rt `
1729+
-Bin "$(Get-TargetProjectBinaryCache $Arch ClangRuntime)" `
1730+
-InstallTo $InstallTo `
1731+
-Arch $Arch `
1732+
-Platform $Platform `
1733+
-UseBuiltCompilers ASM,C,CXX `
1734+
-BuildTargets "install-compiler-rt" `
1735+
-Defines (@{
1736+
CMAKE_SYSTEM_NAME = $Platform.ToString();
1737+
LLVM_DIR = "$LLVMTargetCache\lib\cmake\llvm";
1738+
LLVM_ENABLE_PER_TARGET_RUNTIME_DIR = "YES";
1739+
COMPILER_RT_DEFAULT_TARGET_ONLY = "YES";
1740+
COMPILER_RT_BUILD_BUILTINS = "NO";
1741+
COMPILER_RT_BUILD_CRT = "NO";
1742+
COMPILER_RT_BUILD_LIBFUZZER = "NO";
1743+
COMPILER_RT_BUILD_ORC = "NO";
1744+
COMPILER_RT_BUILD_XRAY = "NO";
1745+
COMPILER_RT_BUILD_PROFILE = "YES";
1746+
COMPILER_RT_BUILD_SANITIZERS = "YES";
1747+
})
1748+
}
1749+
17001750
function Build-ZLib([Platform]$Platform, $Arch) {
17011751
$ArchName = $Arch.LLVMName
17021752

@@ -2919,6 +2969,7 @@ if (-not $SkipBuild) {
29192969
Invoke-BuildStep Build-FoundationMacros -Build Windows $BuildArch
29202970
Invoke-BuildStep Build-TestingMacros -Build Windows $BuildArch
29212971
Invoke-BuildStep Build-Foundation Windows $Arch
2972+
Invoke-BuildStep Build-Sanitizers Windows $Arch
29222973
Invoke-BuildStep Build-XCTest Windows $Arch
29232974
Invoke-BuildStep Build-Testing Windows $Arch
29242975
Invoke-BuildStep Write-SDKSettingsPlist Windows $Arch
@@ -2938,6 +2989,7 @@ if (-not $SkipBuild) {
29382989
Invoke-BuildStep Build-Runtime Android $Arch
29392990
Invoke-BuildStep Build-Dispatch Android $Arch
29402991
Invoke-BuildStep Build-Foundation Android $Arch
2992+
Invoke-BuildStep Build-Sanitizers Android $Arch
29412993
Invoke-BuildStep Build-XCTest Android $Arch
29422994
Invoke-BuildStep Build-Testing Android $Arch
29432995
Invoke-BuildStep Write-SDKSettingsPlist Android $Arch

0 commit comments

Comments
 (0)
Please sign in to comment.