Skip to content

Microsoft's SDKs and DDKs

The sysroots above are made from mingw-w64. tools/import-ms-sdk.py makes sysroots from Microsoft's own Win32 SDKs and DDKs instead, with their headers, import libraries and C runtime, for code written against them. Microsoft's kits can't be redistributed, so neither this repository nor the toolchain package has any of their files: run the script once on your own copies to add them to an unpacked toolchain package.

python3 tools/import-ms-sdk.py --sdks /path/to/WindowsSDKs ~/clang-dos
clang --config=ms-nt351.cfg -O2 hello.c -o hello.exe

--sdks is a folder holding the kits under the folder names below (an installed tree or the unpacked CD; --kit-dir KIT=FOLDER gives one kit's folder instead), and every kit found there is imported. Each one becomes sysroots/ms-KIT and bin/ms-KIT.cfg in the package.

Kit Folder Triple From
nt31 3.1 SDK DDK i386-pc-windows3.10-msvc Win32 SDK for NT 3.1 (MSDN, October 1994)
nt351 3.51 SDK i386-pc-windows3.51-msvc Win32 SDK, June 1995, with NT 3.1's C runtime
nt40 4.0 W95 SDK (expanded) i486-pc-windows4.0-msvc Win32 SDK for NT 4.0 and 95, August 1996, with NT 3.1's C runtime
w2k 5.2.3970.1830 DDK (unpacked) i586-pc-windows5.0-msvc Server 2003 SP1 DDK, Windows 2000 headers and libraries
xp 5.2.3970.1830 DDK (unpacked) i586-pc-windows5.1-msvc Server 2003 SP1 DDK, XP headers and libraries
ws03 5.2.3970.1830 DDK (unpacked) i586-pc-windows5.2-msvc Server 2003 SP1 DDK
ws03-x64 5.2.3970.1830 DDK (unpacked) x86_64-pc-windows5.2-msvc Server 2003 SP1 DDK, x64
nt31-ddk 3.1 SDK DDK i386-pc-windows3.10-msvc NT 3.1 DDK (MSDN, October 1994), kernel-mode drivers
nt40-ddk 4.0 DDK i386-pc-windows4.0-msvc NT 4.0 DDK (4.0.1381), drivers, with the headers of nt40 and nt31
w2k-ddk 5.2.3970.1830 DDK (unpacked) i586-pc-windows5.0-msvc Server 2003 SP1 DDK, Windows 2000 drivers
xp-ddk 5.2.3970.1830 DDK (unpacked) i586-pc-windows5.1-msvc Server 2003 SP1 DDK, XP drivers
ws03-ddk 5.2.3970.1830 DDK (unpacked) i586-pc-windows5.2-msvc Server 2003 SP1 DDK, drivers
ws03-x64-ddk 5.2.3970.1830 DDK (unpacked) x86_64-pc-windows5.2-msvc Server 2003 SP1 DDK, x64 drivers
w95-vxd 4.0 W95 DDK i386-pc-windows4.0-msvc Windows 95 DDK, VxDs
w98-vxd 4.10 DDK (unpacked) i386-pc-windows4.10-msvc Windows 98 DDK, VxDs
me-vxd 4.90 DDK (unpacked) i386-pc-windows4.90-msvc Windows ME DDK, VxDs
w31-vxd 3.1 DDK (win31-vxd.cfg's) Windows 3.1 DDK, VxDs: C headers made from its MASM ones
w98-wdm 4.10 DDK (unpacked) i386-pc-windows4.0-msvc Windows 98 DDK, WDM drivers for 98, ME and 2000
  • The kits are used as Microsoft shipped them, so the 1996 SDK's compressed .LI_ files must be expanded first (expand -r) and the DDKs' CABs unpacked into the tree their setup installs (WINDDK\). For the 98 and ME DDKs, tools/unpack-ms-ddk.py 98DDK.RAR "4.10 DDK (unpacked)" (or WMEDDK.ZIP and "4.90 DDK (unpacked)") does that; it needs 7z. The Aug 1996 SDK and the June 1995 one have no i386 C runtime library, so they take the NT 3.1 SDK's, which also runs on 95 and NT 4.0.
  • The triples are MSVC ones, so programs use Microsoft's ABI and C runtime (statically, libcmt.lib or libc.lib, whichever the kit has), not mingw-w64's. As with the MinGW triples, the Windows version in the triple sets the default CPU and, with LLD, the subsystem and OS version the linker writes, and for NT 3.x a writable .rdata.
  • The config file sets -fms-compatibility-version to the compiler the kit came with, defines _X86_ (or _AMD64_), which early headers want from the makefile, and links the kit's C runtime instead of clang's default libcmt and oldnames.
  • On a case-sensitive file system the headers and libraries are copied with lower-case names, and vfs.yaml, a case-insensitive overlay the config file passes with -vfsoverlay, lets #include <Windows.h> and a library's /DEFAULTLIB:LIBC find them, as on Windows.
  • The libraries of the 1993 to 1996 kits need fixing for LLD, which ms_oldlib.py does to the sysroot's copies (with the package's llvm-lib, or --llvm-lib): their archive headers are padded with NULs; their objects give sections an address, with relocations relative to it, and leave out the sections' access bits; and their long-format import libraries (a whole object per import) make LLD build an import table with a DLL's terminator in the middle, so they are rebuilt as short-format ones and checked against the originals. NT 3.1's crtdll.lib stays as it is, since its data imports (_iob and the like) have no short-format equivalent: use libcmt, the default.
  • Those kits' C runtime predates __int64 and asks for neither kernel32 nor SafeSEH: their config files link kernel32, pass -safeseh:no and link ll64.lib, the 64-bit integer helpers (__alldiv and the like) taken from the Server 2003 DDK's libcmt.lib when that kit is imported too. Without it, 64-bit division doesn't link.
  • The XP and Server 2003 kits' C runtime is built with /GS, so their config files link bufferoverflowu. The Server 2003 winnt.h declares _interlockedbittestandset and the like without volatile, which clang rejects, so ms-ws03 and ms-ws03-x64 include ms-intrin-shim.h first. The DDK's inc/w2k and inc/wxp lack four headers windows.h includes, which come from inc/wnet.
  • C only: the kits' C++ libraries are for Microsoft's compilers of the time.
  • The -ddk kits build kernel-mode drivers (clang --config=ms-xp-ddk.cfg -O2 mydriver.c -o mydriver.sys), with the DDK's ntddk.h, wdm.h and the rest before its Windows headers, and its ntoskrnl.lib, hal.lib and kernel C library (libcntpr.lib, NT 3.1's libcnt.lib; with bufferoverflowk for the /GS ones) instead of a C runtime. Their config files define what the DDKs' build did for a driver (_X86_, i386, STD_CALL, CONDITION_HANDLING, _NT1X_, WINNT, _WIN32_WINNT and WINVER for the triple's version, ...) and pass -mrtd, since the DDKs built drivers with cl /Gz and declare dispatch routines and the like without a calling convention. They pass -fasync-exceptions for __try, as cl's is asynchronous. The NT 3.1 DDK's libcnt.lib has only cl 8.0's _except_handler2, so ms-nt31-ddk.cfg links the package's libntseh.a for clang's _except_handler3. The 386 kits (NT 3.1, NT 4.0, 98 WDM, the VxD ones) pass -fno-ms-volatile: with cl's volatile semantics, clang makes volatile accesses atomic ones, which for a 386 are calls to __sync_lock_test_and_set_4, a function no kit has. The linker makes a driver image: -driver, native subsystem of the triple's version, entry point DriverEntry, base 0x10000, checksum, the PAGE and INIT sections of alloc_text, with INIT discardable. A few mistakes in the DDKs' ntddk.h that cl accepted are fixed in the sysroot's copy (the 2000 and XP DDKs declare _InterlockedXor with a LONG for its pointer; NT 4.0 to XP read a byte of the KPCR in inline assembly without saying its size). The Windows Vista WDK and later are not supported yet.

  • The -vxd kits build VxDs the DDKs' way, with vmm.h, vxdwraps.h and the other headers of INC32 (inc/win98, inc/win_me) and VXDWRAPS.CLB: compile with clang --config=ms-w95-vxd.cfg -c and link with vxd-link.py --kit ms-w95-vxd, which links the kit's library before libvxd.a. The config does what the DDKs' makefiles did (cl -Zp -DIS_32: structures packed, -fpack-struct=1), defines the service sets the headers declare (WIN40SERVICES, and WIN403SERVICES and WIN41SERVICES for 98, WIN49SERVICES for ME), and allows Microsoft's inline assembly (-fasm-blocks). <vxd.h> is copied into the sysroot: with these configs it includes vmm.h and adds VXD_DEVICE for the DDB (the DDKs did it in assembly), VXD_CALLBACK, VXD_CALL (VxDCall is the DDK's) and the code and data kinds. The DDK's #pragma VxD_LOCKED_CODE_SEG and the like are macros that name the pragma, which clang expands with -fms-extensions as cl did. The sysroot's vmm.h and vxdwraps.h are changed for clang: the macros of the service tables take fewer arguments than cl allowed, VxDCall emits the service's number from <vxdsvc.h> (clang's _emit takes numbers, not the enum's constants), and PREPEND expands CURSEG() before pasting.

  • The Windows 3.1 DDK's VxD headers are MASM ones only. For w31-vxd, tools/inc2h.py makes a C header from each of them in the sysroot (vmm.h, vpicd.h, shell.h, ...). Each header has the file's numeric equates as #defines and its structures as packed structs (struct Client_Reg_Struc, struct VxD_Desc_Block, ...). It leaves out macros, text equates and offsets into structures. Compile with ms-w31-vxd.cfg, which is win31-vxd.cfg plus those headers, then include <vxd.h> and the headers you need, and link with vxd-link.py --win31. The vmda*.h headers are alternatives, one per display adapter, so include only one.
  • w98-wdm builds WDM drivers with the 98 DDK's wdm.h and wdm.lib (-DHELLO_WDM in the test), checked with check-imports.py --wdm 98.

tests/ms-sdk/run-test.sh tests the script with three small fake kits. tests/ms-sdk/kits-test.py PACKAGE --run builds and runs a program with each imported kit, for testing with the real ones: all seven user-mode ones built and ran on Windows 11 at -O0 and -O2. With --wine it runs them in Wine and also loads tests/ddk/hello.c built with each -ddk kit as a Wine service: the six of them work in Wine 9.0. vxd/run-tests.sh builds vxd/msddk.c, a VxD written with the DDKs' headers, with each -vxd kit it finds (vxd/msddk31.c with w31-vxd).

The 1993 to 1996 kits' import libraries, after llvm-lib rebuilds them, import stdcall functions by an EXPORTAS name. LLD before version 19 (a distribution's, as kits-test.py --stock-clang uses) reads that as an import by ordinal #0, so ms_oldlib.py makes them plain undecorated imports, which mean the same thing to every linker. kits-test.py checks each driver's imports with check-imports.py, which catches that.