Skip to content

Windows 95, 98, ME, NT and 2000/XP

clang builds 32-bit programs for Windows 95, 98 and ME with a Windows version in the target triple and a sysroot made from mingw-w64.

Windows Triple Default CPU
95 (and NT 4.0) i386-pc-windows4.0-gnu 80386
98 i486-pc-windows4.10-gnu 80486
ME i586-pc-windows4.90-gnu Pentium

The version in the triple is the oldest Windows the program runs on. clang then:

  • targets the CPU of the arch name (i386, i486, i586 for a Pentium, i686 for a Pentium Pro) instead of a Pentium 4, so no SSE. Windows 95 and NT 4.0 do not save SSE registers. -march still overrides it.
  • tells the linker to write that subsystem and OS version. Windows 9x refuses programs that ask for Windows 5.0 or later, and LLD's default is 6.0. -Wl,--subsystem,console:4.0 and the like still override it.

Building the sysroot

LLVM_SRC=~/llvm MINGW_SRC=~/mingw-w64 BIN=~/llvm/build/bin \
  SYSROOT=~/win9x-sysroot sh scripts/build-win9x.sh

Use llvm-dlltool, lld and clang from the same new build. LLVM 18's llvm-dlltool turns renamed imports in mingw-w64's .def files into weak aliases, so atexit calls itself and programs hang at startup; a new llvm-dlltool with LLVM 18's lld imports functions by ordinal 0.

It needs a recent mingw-w64 (current master works): recent mingw-w64 calls newer Windows functions only through GetProcAddress with fallbacks, and its own test suite runs on Windows 9x. The sysroot holds:

  • mingw-w64 headers with _WIN32_WINNT defaulting to 0x0400, so APIs newer than Windows 95 and NT 4.0 are hidden unless a program asks for them;
  • the mingw-w64 CRT and import libraries, linked against the msvcrt.dll that ships with Windows (libmsvcrt.a is libmsvcrt-os.a);
  • compiler-rt builtins, as libgcc.a so clang links them by default, and empty libgcc_eh.a, crtbegin.o and crtend.o, which C does not need.

Everything is compiled for an 80386 (CPU=i386), which Windows 95 and NT run on. An 80386 has no BSWAP, XADD or CMPXCHG. For -march=i386 clang-dos/llvm swaps bytes with shifts and makes atomic writes calls to __sync_* functions in compiler-rt's builtins (libgcc.a). On an 80486 or later those use LOCK XADD and LOCK CMPXCHG; on an 80386 they take a lock, which costs a Sleep only when two threads write atomics at once. Atomic loads stay plain moves. CPU=i486 builds libraries that need a 486.

Building programs

clang --target=i386-pc-windows4.0-gnu --sysroot=$SYSROOT -fuse-ld=lld \
  hello.c -o hello.exe
clang --target=i386-pc-windows4.0-gnu --sysroot=$SYSROOT -fuse-ld=lld \
  -mwindows gui.c -o gui.exe

The C runtime DLL

Programs import msvcrt.dll. Windows 98 and ME ship it; Windows 95 has it only when something installed it (Internet Explorer 4, Office, many other programs). For a bare Windows 95, ship Microsoft's redistributable msvcrt.dll 6.0 with the program, or build a second sysroot with CRT=crtdll, whose programs import crtdll.dll, which every Windows 95 has.

Native ANSI builds

Windows 9x programs are native ANSI builds: they call the A functions directly, with no unicows layer. Windows 95, 98 and ME implement only a few W functions (MessageBoxW, TextOutW, lstrlenW, MultiByteToWideChar and a handful more); the others exist only as stubs that fail with ERROR_CALL_NOT_IMPLEMENTED.

  • Generic-text code (TCHAR, _T(), CreateFile, _tmain) compiles to the A functions, because nothing defines UNICODE or _UNICODE. Don't pass -municode or -DUNICODE for a 9x program, unless it is a Unicode build with unicows (below).
  • The sysroot's own startup code and C library import no W functions; check-imports.py confirms it for every test program.
  • check-imports.py fails a build that imports a W stub. A program that checks the Windows version and picks W functions only on NT can pass --allow-unicode to see those as warnings instead.
  • Text is in the system's ANSI code page (GetACP()), as in any ANSI program.

Unicode builds with unicows

A Unicode program (-municode, wmain, CreateFileW) runs on 9x through Microsoft's Layer for Unicode, unicows.dll, which turns W calls into A calls. Native ANSI builds remain the default; this is for code that is Unicode already.

LIBUNICOWS_SRC=~/libunicows-1.1.2 BIN=~/llvm/build/bin \
  SYSROOT=~/win9x-sysroot sh scripts/build-unicows.sh
clang --target=i386-pc-windows4.0-gnu --sysroot=$SYSROOT -fuse-ld=lld \
  -municode prog.c -lunicows -o prog.exe

build-unicows.sh builds libunicows (MIT license; it needs nasm) into the sysroot. The program then imports no W functions. At its first W call, libunicows loads unicows.dll on 9x or the system DLLs on NT, so one exe runs on both.

  • Ship unicows.dll with the program. Microsoft's MSLU redistributable (unicows.exe) has it; it is not in this repository. Without it, the program stops at its first W call with a message box naming the missing DLL.
  • clang-retro/unicows (AGPL) is an open-source unicows.dll with all 506 of MSLU's functions, built with this toolchain. It also builds as opencow.dll, which libunicows loads when unicows.dll is absent. A program that ships it has to offer its source under the AGPL.
  • unicows covers the program's own Win32 calls, not the C library's. The 9x msvcrt.dll calls W stubs directly in about 50 wide functions: _wfopen, _wopen, _wstat, _wfindfirst, _waccess, _wremove, _wrename, _wmkdir, _wgetcwd, _wfullpath, _wsystem, _wspawn*, _wexec* and the like. They fail on 9x with or without unicows, and check-imports.py reports them. Use CreateFileW and the other Win32 functions for files instead. wmain's arguments, _wgetenv and the wide string, character and formatting functions work, because msvcrt falls back to the A functions there.
  • A crtdll.dll sysroot has no wide C library, so it can't build -municode programs.