Re: [Mingw-w64-public] [PATCH v2] crt: Add a UCRT import library suitable for UWP use

2020-06-08 Thread Jacek Caban

Hi Martin,

The idea of a separated crt library for UWP seems reasonable to be. It 
could also potentially help with some other UWP compatibility problems.


Having to implement a number of string functions is not really optimal, 
but it looks like we need it. Long term, as we discussed lately, we may 
have a possibility to use Wine for that. Once Wine has proper msvcrt 
implementation in a PE file, it should be possible to extract that and 
provide a static msvcrt/ucrt library.


Anyway, I'm fine with the patch.

Thanks,
Jacek

On 05.06.2020 14:59, Martin Storsjö wrote:

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ö 
---
  mingw-w64-crt/Makefile.am|  53 ++-
  mingw-w64-crt/crt/__C_specific_handler.c |  34 +
  mingw-w64-crt/lib-common/ucrtapp.mri |  19 +++
  mingw-w64-crt/misc/longjmp.S |  97 +
  mingw-w64-crt/misc/setjmp.S  | 115 +++
  mingw-w64-crt/string/memchr.c|  50 +++
  mingw-w64-crt/string/memcmp.c|  31 
  mingw-w64-crt/string/memcpy.c|  12 ++
  mingw-w64-crt/string/memmove.c   |  12 ++
  mingw-w64-crt/string/memrchr.c   |  34 +
  mingw-w64-crt/string/strchr.c|  32 
  mingw-w64-crt/string/strchrnul.c |  51 +++
  mingw-w64-crt/string/strrchr.c   |  31 
  mingw-w64-crt/string/strstr.c| 177 +++
  mingw-w64-crt/string/wcschr.c|  31 
  mingw-w64-crt/string/wcsrchr.c   |  31 
  mingw-w64-crt/string/wcsstr.c| 128 
  17 files changed, 930 insertions(+), 8 deletions(-)
  create mode 100644 mingw-w64-crt/crt/__C_specific_handler.c
  create mode 100644 mingw-w64-crt/lib-common/ucrtapp.mri
  create mode 100644 mingw-w64-crt/misc/longjmp.S
  create mode 100644 mingw-w64-crt/misc/setjmp.S
  create mode 100644 mingw-w64-crt/string/memchr.c
  create mode 100644 mingw-w64-crt/string/memcmp.c
  create mode 100644 mingw-w64-crt/string/memcpy.c
  create mode 100644 mingw-w64-crt/string/memmove.c
  create mode 100644 mingw-w64-crt/string/memrchr.c
  create mode 100644 mingw-w64-crt/string/strchr.c
  create mode 100644 mingw-w64-crt/string/strchrnul.c
  create mode 100644 mingw-w64-crt/string/strrchr.c
  create mode 100644 mingw-w64-crt/string/strstr.c
  create mode 100644 mingw-w64-crt/string/wcschr.c
  create mode 100644 mingw-w64-crt/string/wcsrchr.c
  create mode 100644 mingw-w64-crt/string/wcsstr.c

diff --git a/mingw-w64-crt/Makefile.am b/mingw-w64-crt/Makefile.am
index c30e22cce..b104da3a1 100644
--- a/mingw-w64-crt/Makefile.am
+++ b/mingw-w64-crt/Makefile.am
@@ -241,6 +241,23 @@ src_ucrtbase=\
stdio/ucrt_vsnprintf.c \
stdio/ucrt_vsprintf.c
  
+src_ucrtapp=\

+  crt/__C_specific_handler.c \
+  misc/longjmp.S \
+  misc/setjmp.S \
+  string/memchr.c \
+  

Re: [Mingw-w64-public] [PATCH 1/2] crt: Use corecrt_stdio_config.h instead of local UCRTBASE_* defines.

2020-06-08 Thread Martin Storsjö

On Sun, 7 Jun 2020, Jacek Caban wrote:


Signed-off-by: Jacek Caban 
---
mingw-w64-crt/crt/ucrtbase_compat.c| 2 +-
mingw-w64-crt/stdio/ucrt__vscprintf.c  | 2 +-
mingw-w64-crt/stdio/ucrt__vsnprintf.c  | 2 +-
mingw-w64-crt/stdio/ucrt__vsnwprintf.c | 2 +-
mingw-w64-crt/stdio/ucrt_snprintf.c| 2 +-
mingw-w64-crt/stdio/ucrt_sprintf.c | 2 +-
mingw-w64-crt/stdio/ucrt_vsnprintf.c   | 2 +-
mingw-w64-crt/stdio/ucrt_vsprintf.c| 2 +-
8 files changed, 8 insertions(+), 8 deletions(-)


LGTM

// Martin



___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] [PATCH 2/2] headers: Use corecrt_stdio_config.h instead of local UCRTBASE_* defines.

2020-06-08 Thread Martin Storsjö

On Sun, 7 Jun 2020, Jacek Caban wrote:


Signed-off-by: Jacek Caban 
---
mingw-w64-headers/crt/conio.h   | 37 +++--
mingw-w64-headers/crt/sec_api/stdio_s.h | 26 -
mingw-w64-headers/crt/sec_api/wchar_s.h | 12 ++--
mingw-w64-headers/crt/stdio.h   | 59 ++--
mingw-w64-headers/crt/wchar.h   | 74 +
5 files changed, 70 insertions(+), 138 deletions(-)


Looks sensible, although I didn't proofread it in detail. Thanks!

// Martin



___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public