This makes GDB build again in MSYS2.

--
Best regards,
LIU Hao
From c7ecb4b7efd4a5c841ce62afaf66c2391b6615a4 Mon Sep 17 00:00:00 2001
From: LIU Hao <[email protected]>
Date: Fri, 28 Oct 2022 22:52:54 +0800
Subject: [PATCH] headers/stdio: Don't attempt to perform buffer overflow
 checks when inlining is impossible

We have this in 'gdb/opcodes/z80-dis.c':

   info->fprintf_func = (fprintf_ftype) &sprintf;

This attempts to take the address of `sprintf()` and assign it to a variable,
making it unsuitable for inlining.

With `-D_FORTIFY_SOURCE=2` we could get errors like:

   C:/MSYS2/mingw32/include/stdio.h:389:10: error: invalid use of 
'__builtin_va_arg_pack ()'
   return __mingw_sprintf( __stream, __format, __builtin_va_arg_pack() );
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Therefore, it is not safe to make these functions `static inline`. They have
to be `extern inline __attribute__((__gnu_inline__))` instead, to prevent the
inline body from being instantiated where inappropriate. The macro
`__mingw_bos_ovr` is no longer necessary and can be removed.

Signed-off-by: LIU Hao <[email protected]>
---
 mingw-w64-headers/crt/_mingw_mac.h | 12 ++++-------
 mingw-w64-headers/crt/stdio.h      | 32 ++++++++++++++++++++++--------
 2 files changed, 28 insertions(+), 16 deletions(-)

diff --git a/mingw-w64-headers/crt/_mingw_mac.h 
b/mingw-w64-headers/crt/_mingw_mac.h
index 4fd2fdd8a..1aa34c96e 100644
--- a/mingw-w64-headers/crt/_mingw_mac.h
+++ b/mingw-w64-headers/crt/_mingw_mac.h
@@ -333,16 +333,12 @@
 #  define __mingw_bos_ptr_chk_warn(p, n, maxtype) \
      (__mingw_bos_known(p) && __builtin_constant_p((n)) && __mingw_bos(p, 
maxtype) < (size_t)(n) \
      ? __mingw_chk_fail_warn() : __mingw_bos_ptr_chk(p, n, maxtype))
-#  define __mingw_bos_ovr __mingw_ovr \
-     __attribute__((__always_inline__)) \
-     __mingw_attribute_artificial
-#  define __mingw_bos_extern_ovr extern __inline__ __cdecl \
-     __attribute__((__always_inline__, __gnu_inline__)) \
-     __mingw_attribute_artificial
-#else
-#  define __mingw_bos_ovr __mingw_ovr
 #endif /* __MINGW_FORTIFY_LEVEL > 0 */
 
+#define __mingw_bos_extern_ovr extern __inline__ __cdecl \
+   __attribute__((__always_inline__, __gnu_inline__)) \
+   __mingw_attribute_artificial
+
 /* If _FORTIFY_SOURCE is enabled, some inline functions may use
    __builtin_va_arg_pack().  GCC may report an error if the address
    of such a function is used.  Set _FORTIFY_VA_ARG=0 in this case.  */
diff --git a/mingw-w64-headers/crt/stdio.h b/mingw-w64-headers/crt/stdio.h
index 76fffa177..c08b45e6d 100644
--- a/mingw-w64-headers/crt/stdio.h
+++ b/mingw-w64-headers/crt/stdio.h
@@ -376,7 +376,9 @@ int printf (const char *__format, ...)
 
 #if __MINGW_FORTIFY_VA_ARG
 
-__mingw_bos_ovr
+int sprintf (char *__stream, const char *__format, ...) 
__MINGW_ASM_CALL(__mingw_sprintf);
+
+__mingw_bos_extern_ovr
 __attribute__((__format__ (gnu_printf, 2, 3))) __MINGW_ATTRIB_NONNULL(2)
 int sprintf (char *__stream, const char *__format, ...)
 {
@@ -418,7 +420,9 @@ int vprintf (const char *__format, __builtin_va_list 
__local_argv)
   return __mingw_vfprintf( stdout, __format, __local_argv );
 }
 
-__mingw_bos_ovr
+int vsprintf (char *__stream, const char *__format, __builtin_va_list 
__local_argv) __MINGW_ASM_CALL(__mingw_vsprintf);
+
+__mingw_bos_extern_ovr
 __attribute__((__format__ (gnu_printf, 2, 0))) __MINGW_ATTRIB_NONNULL(2)
 int vsprintf (char *__stream, const char *__format, __builtin_va_list 
__local_argv)
 {
@@ -436,7 +440,9 @@ int vsprintf (char *__stream, const char *__format, 
__builtin_va_list __local_ar
 
 #if __MINGW_FORTIFY_VA_ARG
 
-__mingw_bos_ovr
+int snprintf (char *__stream, size_t __n, const char *__format, ...) 
__MINGW_ASM_CALL(__mingw_snprintf);
+
+__mingw_bos_extern_ovr
 __attribute__((__format__ (gnu_printf, 3, 4))) __MINGW_ATTRIB_NONNULL(3)
 int snprintf (char *__stream, size_t __n, const char *__format, ...)
 {
@@ -459,7 +465,9 @@ int snprintf (char *__stream, size_t __n, const char 
*__format, ...)
 
 #endif /* __MINGW_FORTIFY_VA_ARG */
 
-__mingw_bos_ovr
+int vsnprintf (char *__stream, size_t __n, const char *__format, 
__builtin_va_list __local_argv) __MINGW_ASM_CALL(__mingw_vsnprintf);
+
+__mingw_bos_extern_ovr
 __attribute__((__format__ (gnu_printf, 3, 0))) __MINGW_ATTRIB_NONNULL(3)
 int vsnprintf (char *__stream, size_t __n, const char *__format, 
__builtin_va_list __local_argv)
 {
@@ -846,7 +854,9 @@ char * tmpnam(char * __dst)
   int __cdecl __ms_vsnprintf(char * __restrict__ d,size_t n,const char * 
__restrict__ format,va_list arg)
     __MINGW_ATTRIB_DEPRECATED_MSVC2005 __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
 
-  __mingw_bos_ovr
+  int vsnprintf (char * __restrict__ __stream, size_t __n, const char * 
__restrict__ __format, va_list __local_argv) __MINGW_ASM_CALL(__ms_vsnprintf);
+
+  __mingw_bos_extern_ovr
   __attribute__((__format__ (ms_printf, 3, 0))) __MINGW_ATTRIB_NONNULL(3)
   int vsnprintf (char * __restrict__ __stream, size_t __n, const char * 
__restrict__ __format, va_list __local_argv)
   {
@@ -864,7 +874,9 @@ char * tmpnam(char * __dst)
 #ifndef __NO_ISOCEXT
 #if __MINGW_FORTIFY_VA_ARG
 
-__mingw_bos_ovr
+int snprintf (char * __restrict__ __stream, size_t __n, const char * 
__restrict__ __format, ...) __MINGW_ASM_CALL(__ms_snprintf);
+
+__mingw_bos_extern_ovr
 __attribute__((__format__ (ms_printf, 3, 4))) __MINGW_ATTRIB_NONNULL(3)
 int snprintf (char * __restrict__ __stream, size_t __n, const char * 
__restrict__ __format, ...)
 {
@@ -1103,7 +1115,9 @@ int vwprintf (const wchar_t *__format, __builtin_va_list 
__local_argv)
 
 #if __MINGW_FORTIFY_VA_ARG
 
-__mingw_bos_ovr
+int snwprintf (wchar_t *__stream, size_t __n, const wchar_t *__format, ...) 
__MINGW_ASM_CALL(__mingw_snwprintf);
+
+__mingw_bos_extern_ovr
 /* __attribute__((__format__ (gnu_wprintf, 3, 4))) */ __MINGW_ATTRIB_NONNULL(3)
 int snwprintf (wchar_t *__stream, size_t __n, const wchar_t *__format, ...)
 {
@@ -1126,7 +1140,9 @@ int snwprintf (wchar_t *__stream, size_t __n, const 
wchar_t *__format, ...)
 
 #endif /* __MINGW_FORTIFY_VA_ARG */
 
-__mingw_bos_ovr
+int vsnwprintf (wchar_t *__stream, size_t __n, const wchar_t *__format, 
__builtin_va_list __local_argv) __MINGW_ASM_CALL(__mingw_vsnwprintf);
+
+__mingw_bos_extern_ovr
 /* __attribute__((__format__ (gnu_wprintf, 3, 0))) */ __MINGW_ATTRIB_NONNULL(3)
 int vsnwprintf (wchar_t *__stream, size_t __n, const wchar_t *__format, 
__builtin_va_list __local_argv)
 {
-- 
2.38.1

Attachment: OpenPGP_signature
Description: OpenPGP digital signature

_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to