Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions tools/ci_build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,40 @@
return vcpkg_install_options


def get_msvc_spectre_lib_dir(args):

Check warning on line 323 in tools/ci_build/build.py

View workflow job for this annotation

GitHub Actions / Optional Lint

[misspell] reported by reviewdog 🐶 "spectre" is a misspelling of "specter" Raw Output: ./tools/ci_build/build.py:323:13: "spectre" is a misspelling of "specter"
"""Return the directory that holds the MSVC Spectre-mitigated CRT/STL static libraries for the

Check warning on line 324 in tools/ci_build/build.py

View workflow job for this annotation

GitHub Actions / Optional Lint

[misspell] reported by reviewdog 🐶 "Spectre" is a misspelling of "Specter" Raw Output: ./tools/ci_build/build.py:324:48: "Spectre" is a misspelling of "Specter"
target architecture, or None if it cannot be located.

The /Qspectre compile flag only mitigates ONNX Runtime's own object files. The prebuilt MSVC
CRT/STL static libraries (libcmt.lib, libcpmt.lib, libvcruntime.lib) that get linked into the
binaries also need to be the Spectre-mitigated variants, otherwise BinSkim BA2024

Check warning on line 329 in tools/ci_build/build.py

View workflow job for this annotation

GitHub Actions / Optional Lint

[misspell] reported by reviewdog 🐶 "Spectre" is a misspelling of "Specter" Raw Output: ./tools/ci_build/build.py:329:33: "Spectre" is a misspelling of "Specter"
(EnableSpectreMitigations) still fails. Those variants ship in the "C++ Spectre-mitigated libs"

Check warning on line 330 in tools/ci_build/build.py

View workflow job for this annotation

GitHub Actions / Optional Lint

[misspell] reported by reviewdog 🐶 "Spectre" is a misspelling of "Specter" Raw Output: ./tools/ci_build/build.py:330:76: "Spectre" is a misspelling of "Specter"
Visual Studio component under %VCToolsInstallDir%\\lib\\spectre\\<arch>.
"""
vctools_dir = os.environ.get("VCToolsInstallDir") # noqa: SIM112
if not vctools_dir:
return None
if args.arm:
arch = "arm"
elif args.arm64:
arch = "arm64"
elif args.arm64ec:
arch = "arm64ec"
else:
# Default to the target architecture selected by vcvarsall.bat (x86, x64, arm, arm64),
# falling back to x64 which is what the official Windows release packages use.
arch = os.environ.get("VSCMD_ARG_TGT_ARCH", "x64")
spectre_dir = Path(vctools_dir) / "lib" / "spectre" / arch

Check warning on line 346 in tools/ci_build/build.py

View workflow job for this annotation

GitHub Actions / Optional Lint

[misspell] reported by reviewdog 🐶 "spectre" is a misspelling of "specter" Raw Output: ./tools/ci_build/build.py:346:47: "spectre" is a misspelling of "specter"

Check warning on line 346 in tools/ci_build/build.py

View workflow job for this annotation

GitHub Actions / Optional Lint

[misspell] reported by reviewdog 🐶 "spectre" is a misspelling of "specter" Raw Output: ./tools/ci_build/build.py:346:4: "spectre" is a misspelling of "specter"
if spectre_dir.is_dir():

Check warning on line 347 in tools/ci_build/build.py

View workflow job for this annotation

GitHub Actions / Optional Lint

[misspell] reported by reviewdog 🐶 "spectre" is a misspelling of "specter" Raw Output: ./tools/ci_build/build.py:347:7: "spectre" is a misspelling of "specter"
return str(spectre_dir)

Check warning on line 348 in tools/ci_build/build.py

View workflow job for this annotation

GitHub Actions / Optional Lint

[misspell] reported by reviewdog 🐶 "spectre" is a misspelling of "specter" Raw Output: ./tools/ci_build/build.py:348:19: "spectre" is a misspelling of "specter"
# Some toolsets do not ship a dedicated arm64ec folder; those reuse the arm64 Spectre libraries.

Check warning on line 349 in tools/ci_build/build.py

View workflow job for this annotation

GitHub Actions / Optional Lint

[misspell] reported by reviewdog 🐶 "Spectre" is a misspelling of "Specter" Raw Output: ./tools/ci_build/build.py:349:82: "Spectre" is a misspelling of "Specter"
if args.arm64ec:
fallback = Path(vctools_dir) / "lib" / "spectre" / "arm64"

Check warning on line 351 in tools/ci_build/build.py

View workflow job for this annotation

GitHub Actions / Optional Lint

[misspell] reported by reviewdog 🐶 "spectre" is a misspelling of "specter" Raw Output: ./tools/ci_build/build.py:351:48: "spectre" is a misspelling of "specter"
if fallback.is_dir():
return str(fallback)
return None


def generate_build_tree(
cmake_path,
source_dir,
Expand Down Expand Up @@ -1137,6 +1171,22 @@
# Address Sanitizer libs do not have a Qspectre version. So they two cannot be both enabled.
if not args.enable_address_sanitizer:
cflags += ["/Qspectre"]
# /Qspectre only mitigates ONNX Runtime's own object files. The prebuilt MSVC
# CRT/STL static libraries (libcmt.lib, libcpmt.lib, libvcruntime.lib) that are
# linked into the binaries also have to be the Spectre-mitigated variants,
# otherwise BinSkim BA2024 (EnableSpectreMitigations) still fails. Prepend the
# Spectre lib directory to the linker search path so those libraries are
# resolved ahead of the default (non-mitigated) CRT libraries.
spectre_lib_dir = get_msvc_spectre_lib_dir(args)
if spectre_lib_dir is not None:
ldflags += [f'/LIBPATH:"{spectre_lib_dir}"']
else:
log.warning(
"Could not locate the MSVC Spectre-mitigated CRT/STL libraries. The "
"resulting binaries may fail BinSkim BA2024 (EnableSpectreMitigations). "
"Install the 'C++ Spectre-mitigated libs' component from the Visual "
"Studio installer and build from a Developer Command Prompt."
)
if config == "Release":
cflags += ["/O2", "/Ob2", "/DNDEBUG"]
elif config == "RelWithDebInfo":
Expand Down
Loading