Skip to content

Enable Spectre-mitigated MSVC libs for BinSkim builds - #29624

Merged
tianleiwu merged 3 commits into
mainfrom
tlwu/20260708/binskim_libs
Jul 16, 2026
Merged

Enable Spectre-mitigated MSVC libs for BinSkim builds#29624
tianleiwu merged 3 commits into
mainfrom
tlwu/20260708/binskim_libs

Conversation

@tianleiwu

Copy link
Copy Markdown
Contributor

Description

This updates the Windows BinSkim-compliant build flags so /Qspectre builds also link against the MSVC Spectre-mitigated CRT/STL static libraries. /Qspectre only affects ONNX Runtime's own object files; BinSkim BA2024 can still report violations when the default non-Spectre libcmt.lib, libcpmt.lib, or libvcruntime.lib are linked into the final binary.

Motivation and Context

Release validation reported BinSkim BA2024 (EnableSpectreMitigations) warnings for onnxruntime.dll even when ORT was built with --use_binskim_compliant_compile_flags. The warning identified MSVC runtime and STL static libraries as the non-mitigated modules. This change makes the build option select the Spectre-mitigated MSVC library directory when it is available from the Visual Studio toolset.

Key Changes

  • Adds get_msvc_spectre_lib_dir() to locate %VCToolsInstallDir%\lib\spectre\<arch> for the target Windows architecture.
  • Appends a quoted /LIBPATH:<spectre-lib-dir> linker flag whenever Windows BinSkim flags enable /Qspectre and AddressSanitizer is not enabled.
  • Emits a warning when the Spectre-mitigated MSVC libraries cannot be found, with guidance to install the Visual Studio "C++ Spectre-mitigated libs" component.
  • Preserves the existing ASAN behavior because ASAN libraries do not have Spectre-mitigated variants.

Testing

  • python3 -m ruff check tools/ci_build/build.py
  • python3 -m ruff format --check tools/ci_build/build.py

lintrunner -a tools/ci_build/build.py was also attempted. It found the repository config and applied no file changes, but the local environment could not execute the Ruff lintrunner adapters because python is not available on PATH; the direct python3 -m ruff checks above passed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Windows “BinSkim-compliant” build flag handling in tools/ci_build/build.py so that when /Qspectre is enabled, the final link also prefers MSVC’s Spectre-mitigated CRT/STL static libraries (to address BinSkim BA2024 findings on the produced binaries).

Changes:

  • Add get_msvc_spectre_lib_dir(args) to locate %VCToolsInstallDir%\lib\spectre\<arch> (with an arm64ec→arm64 fallback).
  • When /Qspectre is enabled (and ASAN is not), add a /LIBPATH: entry pointing at the Spectre library directory; warn if it can’t be found.

Comment thread tools/ci_build/build.py
Comment thread tools/ci_build/build.py Outdated
jaholme
jaholme previously approved these changes Jul 15, 2026
@tianleiwu

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service rerun

@tianleiwu
tianleiwu enabled auto-merge (squash) July 16, 2026 16:38
@tianleiwu
tianleiwu merged commit f05b218 into main Jul 16, 2026
90 of 96 checks passed
@tianleiwu
tianleiwu deleted the tlwu/20260708/binskim_libs branch July 16, 2026 21:48
tianleiwu added a commit that referenced this pull request Jul 18, 2026
This cherry-picks the following commits for the release:

| Commit ID | PR Number | Commit Title |
|-----------|-----------|-------------|
| dd32f35 | #29590 | Fix libcudart.so.13 hard dependency in pybind
module breaking import on CPU-only Linux |
| cc44a4d | #29706 | [CUDA] Fix XQA GroupQueryAttention
cudaErrorInvalidValue on Blackwell (sm_120) |
| 23a7e9d | #29705 | [CUDA] Do not link nvrtc |
| ee93f83 | #29711 | [CUDA] Update cuda arch list for packages of
cuda 12.8 |
| fea45a3 | #29620 | [CUDA] Add cuDNN-free ArgMax/ArgMin/ReduceSum
and fix LogSoftmax on plugin EP |
| f05b218 | #29624 | Enable Spectre-mitigated MSVC libs for BinSkim
builds |
| 1c89b86 | #29687 | [BUILD] CUDA_QUANT_PREPROCESS off by default and
Adjust CI |
| 41bd391 | #29658 | [CUDA] Fix null allocator passed to plugin EP
kernel PrePack |
| 405fbea | #28896 | Add Windows ARM64 CUDA plugin package and align
CUDA metadata/artifact naming |
| 308f24c | #29622 | Enable fpA_intB GEMM in CUDA builds and add
configurable options |
| 16ebc1d | #29731 | [Build] Use GPU pool to unblock CI temporarily |
|5911a3a263| #29748 | Add OrtErrorCode::ORT_DEVICE_RESET |
|6217f73ec5 | #29663 | Fix plugin EP allocator deleter lifetime |

---------

Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: GitHub Copilot <copilot@example.com>
Co-authored-by: Edward Chen <18449977+edgchen1@users.noreply.github.com>
Co-authored-by: Yen-Shi Wang <yenshiw@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants