Skip to content

Commit

Permalink
Add support for Address Sanitizer in Windows (Dynamic Linkage only) (m…
Browse files Browse the repository at this point in the history
  • Loading branch information
mxms0 authored Apr 29, 2021
1 parent 23361ac commit eb349b9
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 10 deletions.
11 changes: 11 additions & 0 deletions .azure/azure-pipelines.ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,15 @@ stages:
tls: schannel
config: Debug
extraBuildArgs: -EnableTelemetryAsserts
- template: ./templates/build-config-user.yml
parameters:
image: windows-latest
platform: windows
arch: x64
tls: schannel
config: Debug
extraName: 'sanitize'
extraBuildArgs: -EnableTelemetryAsserts -DynamicCRT -SanitizeAddress -ExtraArtifactDir Sanitize
- template: ./templates/build-config-user.yml
parameters:
image: windows-latest
Expand Down Expand Up @@ -479,6 +488,8 @@ stages:
pool: MsQuic-Win-Latest
platform: windows
tls: schannel
extraArtifactDir: '_Sanitize'
extraArgs: -ExtraArtifactDir Sanitize
- template: ./templates/run-spinquic.yml
parameters:
image: windows-latest
Expand Down
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,12 @@ if(WIN32)
endif()

if(QUIC_ENABLE_SANITIZERS)
message(STATUS "Sanitizers unsupported on this platform.")
# This fails when linking statically, so for today require dynamic linkage
if (QUIC_STATIC_LINK_CRT)
message(FATAL_ERROR "Static linkage unsupported with Address Sanitizer in Windows")
endif()
message(STATUS "Configuring sanitizers")
list(APPEND QUIC_COMMON_FLAGS /fsanitize=address)
endif()

set(QUIC_C_FLAGS ${QUIC_COMMON_FLAGS})
Expand Down
18 changes: 12 additions & 6 deletions scripts/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -408,17 +408,23 @@ function CMake-Build {

if ($IsWindows) {
Copy-Item (Join-Path $BuildDir "obj" $Config "msquic.lib") $ArtifactsDir
if ($PGO -and $Config -eq "Release") {
if ($SanitizeAddress -or ($PGO -and $Config -eq "Release")) {
Install-Module VSSetup -Scope CurrentUser -Force -SkipPublisherCheck
$VSInstallationPath = Get-VSSetupInstance | Select-VSSetupInstance -Latest -Require Microsoft.VisualStudio.Component.VC.Tools.x86.x64 | Select-Object -ExpandProperty InstallationPath
$VCToolVersion = Get-Content -Path "$VSInstallationPath\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt"
$VCToolsPath = "$VSInstallationPath\VC\Tools\MSVC\$VCToolVersion\bin\Host$Arch\$Arch"
if (Test-Path $VCToolsPath) {
Copy-Item (Join-Path $VCToolsPath "pgort140.dll") $ArtifactsDir
Copy-Item (Join-Path $VCToolsPath "pgodb140.dll") $ArtifactsDir
Copy-Item (Join-Path $VCToolsPath "mspdbcore.dll") $ArtifactsDir
Copy-Item (Join-Path $VCToolsPath "tbbmalloc.dll") $ArtifactsDir
Copy-Item (Join-Path $VCToolsPath "pgomgr.exe") $ArtifactsDir
if ($PGO) {
Copy-Item (Join-Path $VCToolsPath "pgort140.dll") $ArtifactsDir
Copy-Item (Join-Path $VCToolsPath "pgodb140.dll") $ArtifactsDir
Copy-Item (Join-Path $VCToolsPath "mspdbcore.dll") $ArtifactsDir
Copy-Item (Join-Path $VCToolsPath "tbbmalloc.dll") $ArtifactsDir
Copy-Item (Join-Path $VCToolsPath "pgomgr.exe") $ArtifactsDir
}
if ($SanitizeAddress) {
Copy-Item (Join-Path $VCToolsPath "clang_rt.asan_dbg_dynamic-x86_64.dll") $ArtifactsDir
Copy-Item (Join-Path $VCToolsPath "clang_rt.asan_dynamic-x86_64.dll") $ArtifactsDir
}
} else {
Log "Failed to find VC Tools path!"
}
Expand Down
2 changes: 1 addition & 1 deletion src/bin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ elseif(QUIC_ENABLE_LOGGING)
install(TARGETS msquic.lttng DESTINATION "${main_lib_dest}")
endif()

if (MSVC)
if (MSVC AND NOT QUIC_ENABLE_SANITIZERS)
target_compile_options(msquic PRIVATE /analyze)
endif()
2 changes: 1 addition & 1 deletion src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ target_link_libraries(core PRIVATE warnings)

set_property(TARGET core PROPERTY FOLDER "libraries")

if (MSVC)
if (MSVC AND NOT QUIC_ENABLE_SANITIZERS)
target_compile_options(core PRIVATE /analyze)
endif()
2 changes: 1 addition & 1 deletion src/platform/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ set_property(TARGET platform PROPERTY FOLDER "libraries")

target_include_directories(platform PRIVATE ${EXTRA_PLATFORM_INCLUDE_DIRECTORIES})

if (MSVC AND (QUIC_TLS STREQUAL "openssl" OR QUIC_TLS STREQUAL "schannel"))
if (MSVC AND (QUIC_TLS STREQUAL "openssl" OR QUIC_TLS STREQUAL "schannel") AND NOT QUIC_ENABLE_SANITIZERS)
target_compile_options(platform PRIVATE /analyze)
endif()

Expand Down

0 comments on commit eb349b9

Please sign in to comment.