crt: Add a UCRT import library suitable for UWP use
This adds libucrtapp.a, which is the same as libucrt.a, but excluding
libapi-ms-win-crt-private-l1-1-0.a, and with a few statically
linked functions added that otherwise normally are linked from
libapi-ms-win-crt-private-l1-1-0.a.
Linking against the private dll (and ucrtbase.dll) is prohibited when
targeting UWP. An app built and packaged with MSVC would link against
these functions from vcruntime140_app.dll, which ends up bundled with
the app itself. However, the goal of this patch is to make it possible
to build a UWP app with mingw tools and redistribute it without bundling
vcruntime140_app.dll or similar ones from MSVC.
By using a separate copy of libucrt*.a, without the forbidden bits, it
gives a clear linker error if an app requires linking against other
functions that aren't implemented yet, instead of silently ending up
depending on the forbidden api-ms-win-crt-private-l1-1-0.dll.
The functions from this DLL, that end up linked in a mingw build,
are primarily one of the these four areas:
- __C_specific_handler
The implementation so far is a dummy; wine should have a suitable
proper implementation for reference. This shouldn't matter much, except
potentially for turning unhandled exceptions into signals (but that
might also be handled via a different mechanism).
- setjmp/longjmp
The implementation should be ok, but doesn't do a SEH unwind (yet) but
just a plain longjmp. A full implementation should be doable, but is
not really needed for mingw code.
- string functions: memcpy and memmove
Added minimal wrappers that just call memcpy_s and memmove_s from
api-ms-win-crt-string-l1-1-0.dll, as that one should have implementations
with good performance.
- string functions: memchr, memcmp, strchr, strrchr, strstr, wcschr, wcsrchr, wcsstr
These are copied from musl (with minor modifications to make them
compile in mingw-w64, and with an added copyright header).
By naming the library libucrtapp.a, clang users can choose to link
against this by passing -lucrtapp (which makes clang omit the default
-lmsvcrt, which would be equal to libucrt.a in such a case).
Signed-off-by: Martin Storsjö <martin@martin.st>
17 files changed