Skip to content

Windows Support

Hugo edited this page Sep 25, 2026 · 1 revision

Windows Support

cc builds and runs natively on Windows. The compiler side is the same compilerlib; the instrumentation runtime has a platform layer for the parts that cannot be shared with POSIX.

Building

powershell -ExecutionPolicy Bypass -File .\scripts\build-windows.ps1 `
  -LLVMDir "C:\LLVM\lib\cmake\llvm" `
  -LoggerSourceDir "C:\path\to\coretrace-log" `
  -Configuration Release

Useful parameters of the script: -BuildDir (default build-win), -InstallDir (default dist\windows), -Generator (default Ninja Multi-Config), -Arch (default x64), -Toolset, -BuildTests, -PackageZip.

The result is cc.exe under dist\windows\bin.

CI builds this on windows-2022 against a pinned LLVM 20.1.0 archive, installs it, then runs the smoke tests, the GoogleTest unit tests and the Python smoke tests.

What the platform layer replaces

CMakeLists.txt swaps four translation units on WIN32 (src/runtime/windows/):

File Replaces
ct_runtime_alloc.cpp Allocation interception against the MS CRT
ct_runtime_backtrace.cpp Backtraces through dbghelp instead of execinfo/dladdr
ct_runtime_env.cpp Environment reading
ct_runtime_vtable.cpp Vtable resolution through MSVC RTTI complete-object locators

The runtime links dbghelp on Windows, and the build forces a consistent MSVC runtime (coretrace_force_msvc_runtime) across the targets so instrumented programs and the runtime agree on the CRT.

Behavior differences worth knowing

  • Vtable diagnostics use the MSVC ABI: the runtime walks the complete-object locator rather than the Itanium vptr/typeinfo layout. The compiler-side pass is the same.
  • operator new/delete are rewritten under their Microsoft mangling (??2@…, ??3@…, ??_U@…, ??_V@…), scalar and array, plain, sized and nothrow.
  • Aligned operator delete is deliberately not rewritten on Windows. The Microsoft CRT allocates aligned blocks with _aligned_malloc, which only the aligned operator delete may release; rewriting it would hand the block to the wrong deallocator. On Itanium platforms, where aligned blocks come from aligned_alloc, it is rewritten.
  • Teardown goes through a dbghelp-aware shutdown path, so symbol handles are released in the right order at exit.
  • Trace names are resolved with the Windows symbol API, so instrumented functions print readable names rather than raw addresses.

Not covered on Windows

  • The runtime fixture suites (test/run_autofree_tests.sh, test/run_runtime_tests.sh) are shell runners and are exercised on Linux and macOS only.
  • Objective-C tracking is Apple-only, see Objective-C Support.

See also

Clone this wiki locally