在 2022/11/4 14:42, Martin Storsjö 写道:
But I think this still is kinda safe. After my revert-patch, Clang shouldn't see any of the functions with __asm__ renames at all.GCC needs these renamings, to allow using gnu_inline, to fix issues with __builtin_va_arg_pack(). Strictly speaking, only the functions that use __builtin_va_arg_pack() need this change. (Ideally we'd do it for others as well, but we practically can't really do it for all of them yet.)Clang doesn't support __builtin_va_arg_pack(), so none of the function wrappers that use __builtin_va_arg_pack() should be visible to Clang right now.So with that, I think we are safe - but we can't apply the same pattern on other functions even if that would be ideal. (We can hide it behind ifdefs if we wanted to, but that makes for even more complicated code.)If Clang gains support for __builtin_va_arg_pack() in the future, let's hope that all these cases of infinite recursion have been resolved by then, before we unlock the __builtin_va_arg_pack() codepaths for it.
Attached is the squashed patch. There are only four functions that get asm aliases; all of them are defined within `#if __MINGW_FORTIFY_VA_ARG ... #endif` blocks. Does this look good to you?
-- Best regards, LIU Hao
From ed7221035897a7919bb0fe6f6bd36589f0cfbe23 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 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. Revised-by: Martin Storsjö <[email protected]> Signed-off-by: LIU Hao <[email protected]> --- mingw-w64-headers/crt/stdio.h | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/mingw-w64-headers/crt/stdio.h b/mingw-w64-headers/crt/stdio.h index 76fffa177..5042409a2 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, ...) { @@ -436,7 +438,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, ...) { @@ -864,7 +868,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 +1109,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, ...) { -- 2.34.1
OpenPGP_signature
Description: OpenPGP digital signature
_______________________________________________ Mingw-w64-public mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
