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

2020-06-10 Thread Martin Storsjö

On Mon, 8 Jun 2020, Jacek Caban wrote:


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, pushed!

// 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 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 \
+  

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

2020-06-05 Thread Martin Storsjö
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 \
+  string/memcmp.c \
+  string/memcpy.c \
+  string/memmove.c \
+  string/memrchr.c \
+  string/strchr.c \
+  string/strchrnul.c \
+  string/strrchr.c \
+  string/strstr.c \
+  string/wcschr.c \
+  string/wcsrchr.c \
+  string/wcsstr.c
+
 src_msvcrt32=\
   $(src_msvcrt) \
   math/x86/_copysignf.c \
@@ -862,10 +879,12 @@ lib32_libucrtbase_a_AR = $(DTDEF32) lib32/ucrtbase.def && 
$(AR) $(ARFLAGS)
 lib32_libucrtbase_a_CPPFLAGS=$(CPPFLAGS32) -D__LIBMSVCRT__ $(extra_include) 
$(sysincludes)
 EXTRA_lib32_libucrtbase_a_DEPENDENCIES=lib32/ucrtbase.def
 
-lib32_DATA += lib32/libucrt.a
-noinst_LIBRARIES += lib32/libucrt_extra.a
+lib32_DATA +=