picolibc instead of the system C runtime¶
The win32-picolibc sysroot, built by scripts/build-picolibc.sh, has
picolibc (its libos/win32
layer) as the C library in place of msvcrt.dll and crtdll.dll, and
libc++ built on it. Programs link it statically and import only
kernel32.dll and the system DLLs they call themselves, so one program
runs on Windows 95, 98 and ME, Windows NT 3.1 and every later version
with nothing to install:
clang --config=win32-picolibc.cfg -O2 hello.c -o hello.exe
clang++ --config=win32-picolibc.cfg -O2 hello.cpp -o hello.exe
win32-picolibc.cfg is for Windows 95 and NT 4.0 and later.
nt31-picolibc.cfg marks programs for Windows NT 3.1 (subsystem version
3.10), which NT 3.x needs; they run on the later versions too, though 9x
and NT 4.0 then draw their windows in the Windows 3.x style.
What it adds over the system C runtime:
- C99 and C11
printfandscanf(%zu,%lld,%a,long double, positional arguments),long doublemath,<uchar.h>, a per-threaderrno, and POSIX functions (getline,asprintf,strndup,<dirent.h>,clock_gettime,nanosleep, ...). - For C++: the locale,
wchar_tandlong doublefunctions libc++ expects, sostd::format,std::print,<charconv>, iostreams and<filesystem>take the same paths as on other systems, with 64-bit file positions everywhere (crtdll.dll has 32-bit ones). time_tandoff_tare 64 bits.- Files open in text mode (CR LF) by default, as with the Microsoft C
library;
O_BINARY,"b",_fmodeandsetmodework as there._wfopenand_wopenuse the Unicode functions on NT and the ANSI code page on 9x.
The headers are mingw-w64's Windows API headers (windows.h and the
rest) with picolibc's C library headers in place of mingw-w64's.
Microsoft-only C runtime headers and functions (<tchar.h>, <conio.h>,
<direct.h>, _stricmp and the like) are not there; <io.h> and
<process.h> have the descriptor and thread functions (_get_osfhandle,
_open_osfhandle, _beginthreadex).
The config file passes -fno-emulated-tls: picolibc's errno and C++
thread_local variables are native TLS. DLLs that a program loads at
startup work on every version; a DLL loaded with LoadLibrary gets
native TLS only on Vista and later, so on earlier versions such a DLL
should use another sysroot. As elsewhere, TLS callbacks never run on 9x,
so there thread_local destructors do not run when a thread ends.