Re: [Mingw-w64-public] [PATCH] crt: Implement the __stpcpy_chk function
On Fri, 14 Oct 2022, LIU Hao wrote: 在 2022/10/14 19:38, Martin Storsjö 写道: Initially, it may seem like this function might not be needed in any form, since mingw-w64 lacks the main stpcpy function. However, third party projects may contain their own implementation of the stpcpy function. When GCC sees a declaration of the stpcpy function, it assumes that it is legal to do optimizations on strcpy+strlen into stpcpy. When strcpy is wrapped with fortification wrappers, so that strcpy ends up calling __builtin___strcpy_chk (which then calls __strcpy_chk), GCC can also transform this into __builtin___stpcpy_chk, which can generate a call to __stpcpy_chk. GCC's libssp does provide an implementation of __stpcpy_chk, even if the platform itself lacks stpcpy. Therefore, mingw-w64-crt's implementation of the ssp routines also does need an implementation of __stpcpy_chk, even if it is hard to practically produce calls to it. This should fix one issue discussed at https://github.com/msys2/MINGW-packages/issues/5803#issuecomment-1276812143. Signed-off-by: Martin Storsjö --- mingw-w64-crt/Makefile.am | 2 +- mingw-w64-crt/ssp/stpcpy_chk.c | 19 +++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 mingw-w64-crt/ssp/stpcpy_chk.c LGTM. Thanks. 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] crt: Implement the __stpcpy_chk function
Thanks! Am Fr., 14. Okt. 2022 um 15:24 Uhr schrieb Martin Storsjö : > > On Fri, 14 Oct 2022, Kai Tietz wrote: > > > Yes, look good to me. Wouldn't it make sense to add __mingww64_stpcpy > > function, so we could provide this function in an more compatible way? > > I don't see the direct need for it; mingw-w64 doesn't have it general, and > this status quo works for most projects (if they use it, they probe for > its existence and provide a replacement), so I don't see the potential > gain from optionally providing it. This seemed to be the general consensus > in https://github.com/msys2/MINGW-packages/issues/5803 too, FWIW. > > // 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] crt: Implement the __stpcpy_chk function
Yes, look good to me. Wouldn't it make sense to add __mingww64_stpcpy function, so we could provide this function in an more compatible way? Thanks, Kai Am Fr., 14. Okt. 2022 um 14:16 Uhr schrieb LIU Hao : > > 在 2022/10/14 19:38, Martin Storsjö 写道: > > Initially, it may seem like this function might not be needed in any > > form, since mingw-w64 lacks the main stpcpy function. > > > > However, third party projects may contain their own implementation of > > the stpcpy function. When GCC sees a declaration of the stpcpy function, > > it assumes that it is legal to do optimizations on strcpy+strlen into > > stpcpy. > > > > When strcpy is wrapped with fortification wrappers, so that strcpy > > ends up calling __builtin___strcpy_chk (which then calls __strcpy_chk), > > GCC can also transform this into __builtin___stpcpy_chk, which can > > generate a call to __stpcpy_chk. > > > > GCC's libssp does provide an implementation of __stpcpy_chk, even if > > the platform itself lacks stpcpy. > > > > Therefore, mingw-w64-crt's implementation of the ssp routines also > > does need an implementation of __stpcpy_chk, even if it is hard > > to practically produce calls to it. > > > > This should fix one issue discussed at > > https://github.com/msys2/MINGW-packages/issues/5803#issuecomment-1276812143. > > > > Signed-off-by: Martin Storsjö > > --- > > mingw-w64-crt/Makefile.am | 2 +- > > mingw-w64-crt/ssp/stpcpy_chk.c | 19 +++ > > 2 files changed, 20 insertions(+), 1 deletion(-) > > create mode 100644 mingw-w64-crt/ssp/stpcpy_chk.c > > > > LGTM. Thanks. > > > -- > Best regards, > LIU Hao > ___ > Mingw-w64-public mailing list > Mingw-w64-public@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/mingw-w64-public ___ 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] crt: Implement the __stpcpy_chk function
On Fri, 14 Oct 2022, Kai Tietz wrote: Yes, look good to me. Wouldn't it make sense to add __mingww64_stpcpy function, so we could provide this function in an more compatible way? I don't see the direct need for it; mingw-w64 doesn't have it general, and this status quo works for most projects (if they use it, they probe for its existence and provide a replacement), so I don't see the potential gain from optionally providing it. This seemed to be the general consensus in https://github.com/msys2/MINGW-packages/issues/5803 too, FWIW. // 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] crt: Implement the __stpcpy_chk function
在 2022/10/14 19:38, Martin Storsjö 写道: Initially, it may seem like this function might not be needed in any form, since mingw-w64 lacks the main stpcpy function. However, third party projects may contain their own implementation of the stpcpy function. When GCC sees a declaration of the stpcpy function, it assumes that it is legal to do optimizations on strcpy+strlen into stpcpy. When strcpy is wrapped with fortification wrappers, so that strcpy ends up calling __builtin___strcpy_chk (which then calls __strcpy_chk), GCC can also transform this into __builtin___stpcpy_chk, which can generate a call to __stpcpy_chk. GCC's libssp does provide an implementation of __stpcpy_chk, even if the platform itself lacks stpcpy. Therefore, mingw-w64-crt's implementation of the ssp routines also does need an implementation of __stpcpy_chk, even if it is hard to practically produce calls to it. This should fix one issue discussed at https://github.com/msys2/MINGW-packages/issues/5803#issuecomment-1276812143. Signed-off-by: Martin Storsjö --- mingw-w64-crt/Makefile.am | 2 +- mingw-w64-crt/ssp/stpcpy_chk.c | 19 +++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 mingw-w64-crt/ssp/stpcpy_chk.c LGTM. Thanks. -- Best regards, LIU Hao OpenPGP_signature Description: OpenPGP digital signature ___ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
[Mingw-w64-public] [PATCH] crt: Implement the __stpcpy_chk function
Initially, it may seem like this function might not be needed in any form, since mingw-w64 lacks the main stpcpy function. However, third party projects may contain their own implementation of the stpcpy function. When GCC sees a declaration of the stpcpy function, it assumes that it is legal to do optimizations on strcpy+strlen into stpcpy. When strcpy is wrapped with fortification wrappers, so that strcpy ends up calling __builtin___strcpy_chk (which then calls __strcpy_chk), GCC can also transform this into __builtin___stpcpy_chk, which can generate a call to __stpcpy_chk. GCC's libssp does provide an implementation of __stpcpy_chk, even if the platform itself lacks stpcpy. Therefore, mingw-w64-crt's implementation of the ssp routines also does need an implementation of __stpcpy_chk, even if it is hard to practically produce calls to it. This should fix one issue discussed at https://github.com/msys2/MINGW-packages/issues/5803#issuecomment-1276812143. Signed-off-by: Martin Storsjö --- mingw-w64-crt/Makefile.am | 2 +- mingw-w64-crt/ssp/stpcpy_chk.c | 19 +++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 mingw-w64-crt/ssp/stpcpy_chk.c diff --git a/mingw-w64-crt/Makefile.am b/mingw-w64-crt/Makefile.am index 053eab3cf..1dff68409 100644 --- a/mingw-w64-crt/Makefile.am +++ b/mingw-w64-crt/Makefile.am @@ -566,7 +566,7 @@ src_libmingwex=\ \ ssp/chk_fail.c ssp/memcpy_chk.c ssp/memmove_chk.c ssp/mempcpy_chk.c \ ssp/memset_chk.c ssp/stack_chk_fail.c ssp/stack_chk_guard.c ssp/strcat_chk.c \ - ssp/strcpy_chk.c ssp/strncat_chk.c ssp/strncpy_chk.c \ + ssp/stpcpy_chk.c ssp/strcpy_chk.c ssp/strncat_chk.c ssp/strncpy_chk.c \ \ stdio/mingw_pformat.h\ stdio/scanf2-argcount-char.c stdio/scanf2-argcount-wchar.c \ diff --git a/mingw-w64-crt/ssp/stpcpy_chk.c b/mingw-w64-crt/ssp/stpcpy_chk.c new file mode 100644 index 0..aaa387680 --- /dev/null +++ b/mingw-w64-crt/ssp/stpcpy_chk.c @@ -0,0 +1,19 @@ +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the mingw-w64 runtime package. + * No warranty is given; refer to the file DISCLAIMER.PD within this package. + */ + +#include + +void __cdecl __chk_fail(void) __attribute__((__noreturn__)); + +char *__cdecl __stpcpy_chk(char *dst, const char *src, size_t bufsize); + +char *__cdecl __stpcpy_chk(char *dst, const char *src, size_t bufsize) +{ + size_t n = strlen(src); + if (n >= bufsize) +__chk_fail(); + return memcpy(dst, src, n + 1) + n; +} -- 2.25.1 ___ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public