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)"(orWMEDDK.ZIPand"4.90 DDK (unpacked)") does that; it needs7z. 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.liborlibc.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-versionto 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 defaultlibcmtandoldnames. - 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:LIBCfind them, as on Windows. - The libraries of the 1993 to 1996 kits need fixing for LLD, which
ms_oldlib.pydoes to the sysroot's copies (with the package'sllvm-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'scrtdll.libstays as it is, since its data imports (_ioband the like) have no short-format equivalent: uselibcmt, the default. - Those kits' C runtime predates
__int64and asks for neither kernel32 nor SafeSEH: their config files linkkernel32, pass-safeseh:noand linkll64.lib, the 64-bit integer helpers (__alldivand the like) taken from the Server 2003 DDK'slibcmt.libwhen 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 linkbufferoverflowu. The Server 2003winnt.hdeclares_interlockedbittestandsetand the like withoutvolatile, which clang rejects, soms-ws03andms-ws03-x64includems-intrin-shim.hfirst. The DDK'sinc/w2kandinc/wxplack four headerswindows.hincludes, which come frominc/wnet. - C only: the kits' C++ libraries are for Microsoft's compilers of the time.
-
The
-ddkkits build kernel-mode drivers (clang --config=ms-xp-ddk.cfg -O2 mydriver.c -o mydriver.sys), with the DDK'sntddk.h,wdm.hand the rest before its Windows headers, and itsntoskrnl.lib,hal.liband kernel C library (libcntpr.lib, NT 3.1'slibcnt.lib; withbufferoverflowkfor the/GSones) instead of a C runtime. Their config files define what the DDKs'builddid for a driver (_X86_,i386,STD_CALL,CONDITION_HANDLING,_NT1X_,WINNT,_WIN32_WINNTandWINVERfor the triple's version, ...) and pass-mrtd, since the DDKs built drivers withcl /Gzand declare dispatch routines and the like without a calling convention. They pass-fasync-exceptionsfor__try, ascl's is asynchronous. The NT 3.1 DDK'slibcnt.libhas onlycl8.0's_except_handler2, soms-nt31-ddk.cfglinks the package'slibntseh.afor clang's_except_handler3. The 386 kits (NT 3.1, NT 4.0, 98 WDM, the VxD ones) pass-fno-ms-volatile: withcl'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 pointDriverEntry, base0x10000, checksum, thePAGEandINITsections ofalloc_text, withINITdiscardable. A few mistakes in the DDKs'ntddk.hthatclaccepted are fixed in the sysroot's copy (the 2000 and XP DDKs declare_InterlockedXorwith aLONGfor 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
-vxdkits build VxDs the DDKs' way, withvmm.h,vxdwraps.hand the other headers ofINC32(inc/win98,inc/win_me) andVXDWRAPS.CLB: compile withclang --config=ms-w95-vxd.cfg -cand link withvxd-link.py --kit ms-w95-vxd, which links the kit's library beforelibvxd.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, andWIN403SERVICESandWIN41SERVICESfor 98,WIN49SERVICESfor ME), and allows Microsoft's inline assembly (-fasm-blocks).<vxd.h>is copied into the sysroot: with these configs it includesvmm.hand addsVXD_DEVICEfor the DDB (the DDKs did it in assembly),VXD_CALLBACK,VXD_CALL(VxDCallis the DDK's) and the code and data kinds. The DDK's#pragma VxD_LOCKED_CODE_SEGand the like are macros that name the pragma, which clang expands with-fms-extensionsascldid. The sysroot'svmm.handvxdwraps.hare changed for clang: the macros of the service tables take fewer arguments thanclallowed,VxDCallemits the service's number from<vxdsvc.h>(clang's_emittakes numbers, not the enum's constants), andPREPENDexpandsCURSEG()before pasting. - The Windows 3.1 DDK's VxD headers are MASM ones only. For
w31-vxd,tools/inc2h.pymakes 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 packedstructs (struct Client_Reg_Struc,struct VxD_Desc_Block, ...). It leaves out macros, text equates and offsets into structures. Compile withms-w31-vxd.cfg, which iswin31-vxd.cfgplus those headers, then include<vxd.h>and the headers you need, and link withvxd-link.py --win31. Thevmda*.hheaders are alternatives, one per display adapter, so include only one. w98-wdmbuilds WDM drivers with the 98 DDK'swdm.handwdm.lib(-DHELLO_WDMin the test), checked withcheck-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.