Skip to content

Commit efba759

Browse files
Add spectre mitigation (#15)
1 parent 047f132 commit efba759

File tree

2 files changed

+24
-22
lines changed

2 files changed

+24
-22
lines changed

build.psm1

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -222,13 +222,7 @@ function Start-BuildNativeWindowsBinaries {
222222

223223
$atlBaseFound = $false
224224

225-
if ($vcPath) {
226-
$atlMfcIncludePath = Join-Path -Path $vcPath -ChildPath 'atlmfc/include'
227-
if(Test-Path -Path "$atlMfcIncludePath\atlbase.h") {
228-
Write-Verbose -Verbose "ATLF MFC found under $atlMfcIncludePath\atlbase.h"
229-
$atlBaseFound = $true
230-
}
231-
} elseif ($alternateVCPath) {
225+
if ($alternateVCPath) {
232226
foreach($candidatePath in $alternateVCPath) {
233227
Write-Verbose -Verbose "Looking under $candidatePath"
234228
$atlMfcIncludePath = @(Get-ChildItem -Path $candidatePath -Recurse -Filter 'atlbase.h' -File)
@@ -241,6 +235,12 @@ function Start-BuildNativeWindowsBinaries {
241235
}
242236
}
243237
}
238+
} elseif ($vcPath) {
239+
$atlMfcIncludePath = Join-Path -Path $vcPath -ChildPath 'atlmfc/include'
240+
if(Test-Path -Path "$atlMfcIncludePath\atlbase.h") {
241+
Write-Verbose -Verbose "ATLF MFC found under $atlMfcIncludePath\atlbase.h"
242+
$atlBaseFound = $true
243+
}
244244
} else {
245245
Write-Verbose -Verbose "PATH: $env:PATH"
246246
throw "Visual Studio tools not found in PATH."

src/powershell-native/coreclr_defs.cmake

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ set(CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_SHARED_LINKER_FLAGS_RELWIT
4747
set(CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO} /LTCG")
4848
set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} /LTCG /OPT:REF /OPT:ICF ${NO_INCREMENTAL_LINKER_FLAGS}")
4949

50-
# Force uCRT to be dynamically linked for Release build
51-
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /NODEFAULTLIB:libucrt.lib /DEFAULTLIB:ucrt.lib")
52-
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /NODEFAULTLIB:libucrt.lib /DEFAULTLIB:ucrt.lib")
53-
set(CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO} /NODEFAULTLIB:libucrt.lib /DEFAULTLIB:ucrt.lib")
54-
set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} /NODEFAULTLIB:libucrt.lib /DEFAULTLIB:ucrt.lib")
50+
# Force uCRT to be dynamically linked for Release build
51+
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /NODEFAULTLIB:libucrt.lib /DEFAULTLIB:ucrt.lib")
52+
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /NODEFAULTLIB:libucrt.lib /DEFAULTLIB:ucrt.lib")
53+
set(CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO} /NODEFAULTLIB:libucrt.lib /DEFAULTLIB:ucrt.lib")
54+
set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} /NODEFAULTLIB:libucrt.lib /DEFAULTLIB:ucrt.lib")
5555

5656
#------------------------------------
5757
# Definitions (for platform)
@@ -133,16 +133,18 @@ if (BUILD_ARCH_AMD64)
133133
endif (BUILD_ARCH_AMD64)
134134

135135
# enable control-flow-guard support for native components for non-Arm64 builds
136-
add_compile_options(/guard:cf)
137-
138-
# Statically linked CRT (libcmt[d].lib, libvcruntime[d].lib and libucrt[d].lib) by default. This is done to avoid
139-
# linking in VCRUNTIME140.DLL for a simplified xcopy experience by reducing the dependency on VC REDIST.
140-
#
141-
# For Release builds, we shall dynamically link into uCRT [ucrtbase.dll] (which is pushed down as a Windows Update on downlevel OS) but
142-
# wont do the same for debug/checked builds since ucrtbased.dll is not redistributable and Debug/Checked builds are not
143-
# production-time scenarios.
144-
add_compile_options($<$<OR:$<CONFIG:Release>,$<CONFIG:Relwithdebinfo>>:/MT>)
145-
add_compile_options($<$<OR:$<CONFIG:Debug>,$<CONFIG:Checked>>:/MTd>)
136+
add_compile_options(/guard:cf)
137+
138+
# Statically linked CRT (libcmt[d].lib, libvcruntime[d].lib and libucrt[d].lib) by default. This is done to avoid
139+
# linking in VCRUNTIME140.DLL for a simplified xcopy experience by reducing the dependency on VC REDIST.
140+
#
141+
# For Release builds, we shall dynamically link into uCRT [ucrtbase.dll] (which is pushed down as a Windows Update on downlevel OS) but
142+
# wont do the same for debug/checked builds since ucrtbased.dll is not redistributable and Debug/Checked builds are not
143+
# production-time scenarios.
144+
add_compile_options($<$<OR:$<CONFIG:Release>,$<CONFIG:Relwithdebinfo>>:/MT>)
145+
add_compile_options($<$<OR:$<CONFIG:Debug>,$<CONFIG:Checked>>:/MTd>)
146+
147+
add_compile_options(/Qspectre) # add Spectre mitigation compiler option. (https://docs.microsoft.com/en-us/cpp/build/reference/qspectre?view=vs-2017)
146148

147149
#set(CMAKE_ASM_MASM_FLAGS "${CMAKE_ASM_MASM_FLAGS} /ZH:SHA_256")
148150

0 commit comments

Comments
 (0)