Before:
flowchart TB
classDef default text-align:left
direction TB
STDNode("<b>Rust</b>
The Rust standard library")
subgraph VCRuntimeSubgraph["VCRuntime (Requires Visual Studio licence at build time)"]
direction TB
VCStartupNode("<b>VCStartup</b>
Provides the entry point (<code>mainCRTstartup</code>), global
variable initialisation, the buffer security cookie etc.
In msvcrt.lib and libcmt.lib, always statically linked into
your binary.")
VCRuntimeNode("<b>VCRuntime (Requires VC++ Redist at runtime)</b>
Provides memory primitives such as <code>memcpy</code> and <code>memmove</code>,
plus C++ Structured Exception Handling functions pulled in
by LLVM (e.g. <code>_CxxThrowException</code>)
Linked dynamically by vcruntime.lib or statically by libvcruntime.lib.
Pulled in by msvcrt.lib or libcmt.lib through linker directives (
<code>/defaultlib:vcruntime.lib</code> in msvcrt.lib or
<code>/defaultlib:libvcruntime.lib</code> in libcmt.lib).
")
end
subgraph WindowsSDKSubgraph["Windows SDK (not part of VS)"]
UniversalCRTNode("<b>Universal CRT</b>
Functions to interact with the operating system.
Linked dynamically by ucrt.lib or statically by
libucrt.lib
")
Win32API("<b>Win32 API</b>
Functions to interact with the operating system.
Linked dynamically by various .lib files
")
end
STDNode ==> VCRuntimeSubgraph & WindowsSDKSubgraph
VCStartupNode ==> VCRuntimeNode ==> WindowsSDKSubgraph
Steps:
- Use lld instead of link.exe (already possible)
- Use mem* functions from compiler-builtins crate. (already possible) We still need vcruntime.lib after this for exception handling functions.
- Write our own entry point and remove, or if we have to, reimplement C Runtime startup/teardown code.
- Either ditch Structured Exception Handling completely and write our own unwinding, or clean-room reimplement the SEH functions.
After:
flowchart TB
classDef default text-align:left
direction TB
STDNode("<b>Rust</b>
The Rust standard library")
subgraph WindowsSDKSubgraph["Windows SDK (not part of VS)"]
UniversalCRTNode("<b>Universal CRT</b>
Functions to interact with the operating system.
Linked dynamically by ucrt.lib or statically by
libucrt.lib
")
Win32API("<b>Win32 API</b>
Functions to interact with the operating system.
Linked dynamically by various .lib files
")
end
STDNode ==> WindowsSDKSubgraph