When building for a pure windows environment, we build against a newer CRT which
does not provide direct access to __argc, __argv. They are hidden behind
macros which use a function call. Use the header (stdlib) to get access to
these rather than declaring them extern. This also makes the swift runtime more
portable across various Windows environments.
From stdlib.h in ucrt 10.0.10586.0:
#ifdef _CRT_DECLARE_GLOBAL_VARIABLES_DIRECTLY
extern int __argc;
extern char** __argv;
#else
#define __argc (*__p___argc())
#define __argv (*__p___argv())
#endif
The indirection is particularly nice on COFF where all module external variables
are indirectly addressed.
Provides a new fallback for Process arguments for those instances where we do
not own main (e.g. Frameworks, Objective-C owns main.m or main.c, etc.). This
includes a number of platform-specific specializations of argument grabbing
logic and a new thread-safe interface to Process.unsafeArgv.
main() | _NSGetArgc/_NSGetArgv | /proc/self/cmdline | __argc/__argv
--------|--------------------------|------------------------|---------------
Scripts | OS X, iOS, tvOS, watchOS | Linux, FreeBSD, Cygwin | Windows
For interpreted Swift where we must filter out the arguments we now do so by
loading the standard library and calling into new SPI to override the arguments
that would have been grabbed by the runtime. This implementation completely
subsumes the use of the entry point '_stdlib_didEnterMain' and it will be
removed in a future commit.