32-bit Windows¶
This directory lets picolibc stand in for msvcrt.dll or crtdll.dll as the
C library of 32-bit Windows programs. It goes into libc.a, and a program
linked with it imports only kernel32.dll, so it runs on Windows 95, 98
and ME, and Windows NT 3.1 and later, with
nothing to install. It is built for the i386-pc-windows*-gnu targets of
the clang-dos LLVM toolchain, and
libc++ builds on it with RUNTIMES_USE_LIBC=picolibc.
Building¶
With clang, llvm-ar and the other LLVM tools on PATH:
meson setup build-win32 \
--cross-file scripts/cross-clang-i386-windows.txt \
-Dos-win32=true -Denable-malloc=false -Dinitfini-array=false \
-Dmultilib=false -Dpicocrt=false -Dsemihost=false -Dtests=false \
-Dspecsdir=none -Dposix-console=true -Dmb-capable=true \
-Dio-wchar=true -Dio-pos-args=true -Dio-long-double=true \
--prefix=$PWD/install-win32
ninja -C build-win32 install
The headers go over the mingw-w64 API headers (windows.h and the rest)
with mingw-w64's C library headers taken out; the win32-sdk repository's
build script puts such a sysroot together. Programs link with
-nostartfiles -nodefaultlibs and then -lc -lclang_rt.builtins-i386
-lkernel32, and are compiled with -fno-emulated-tls.
What it does¶
start.chas the entry points the linker looks for,mainCRTStartupandWinMainCRTStartup. It splits the command line with the Microsoft C rules, copies the environment, runs the constructors (ctors.c, from clang's__maincall) and callsmainorWinMain.dllstart.cis the entry point of DLLs,DllMainCRTStartup. Each DLL has its own copy of the library; it runs the DLL's constructors beforeDllMainand its atexit functions and destructors when it is unloaded.tlssup.cis the TLS directory, so__threadvariables (errno among them) are native TLS, set up by Windows for every thread.cxa_thread_atexit.cruns C++thread_localdestructors when a thread ends, andkeydtor.cruns destructors forTlsAllockeys, which libc++ uses on Windows before Server 2003.- Descriptors (
fd.c) are a table of Win32 handles. Files open in text mode unlessO_BINARY,_fmodeorsetmodesay otherwise:readturns CR LF into LF and stops at Ctrl-Z, andwriteturns LF into CR LF. Consoles, pipes and files all go throughReadFileandWriteFile._wopenand_wfopenopen files by wide name, withCreateFileWon Windows NT and the ANSI name on Windows 9x. mallocuses the process heap (HeapAlloc);lock.cmakes picolibc's locks critical sections, so the library is thread safe.- Time comes from
GetSystemTime(there is noGetSystemTimeAsFileTimeon Windows NT 3.1), and the monotonic clock fromQueryPerformanceCounter, orGetTickCountwhere there is none. _beginthreadexand the rest of<process.h>start threads withCreateThread.<io.h>has_get_osfhandleand_open_osfhandle.- Error codes from
GetLastErrorbecome errno values inerror.c.
link and symlink fail with ENOSYS, and there are no signals beyond
raise.
The library's thread-local variables are native TLS. Windows before Vista
sets that up only for the program and the DLLs it loads at startup, not
for a DLL loaded later with LoadLibrary, so on those versions such a DLL
should not be linked with this library.