Use gcc's function attribute naked which omits any prologue or epilogue
sequences and for x86 is supported by gcc since version 8.0.0. It is also
supported by clang. For older gcc versions use existing code.

This change fixes compile warning:

stdio/_scprintf.c:32:20: warning: ‘init_scprintf’ used but never defined
 static int __cdecl init_scprintf(const char * __restrict__ format, ...);
                    ^~~~~~~~~~~~~

Note that function init_scprintf has to be declared with static keyword,
otherwise its symbol would be marked as global and exported from the
compiled object file (which can conflicts with some application function).
gcc for non-static declaration emits ".def" with ".scl 2" which has same
effect as ".globl". So init_scprintf function must be declared with static
despite the compiler warning.
---
 mingw-w64-crt/stdio/_scprintf.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/mingw-w64-crt/stdio/_scprintf.c b/mingw-w64-crt/stdio/_scprintf.c
index 42f2e5f231a4..2322dec0b8c0 100644
--- a/mingw-w64-crt/stdio/_scprintf.c
+++ b/mingw-w64-crt/stdio/_scprintf.c
@@ -51,9 +51,18 @@ static void resolve_scprintf(void)
 /* gcc does not provide an easy way to call another variadic function with 
reusing current arguments
  * this source file is used only on i386, so do this function redirect via 
inline i386 assembly */
 #define ASM_SYM(sym) __MINGW64_STRINGIFY(__MINGW_USYMBOL(sym))
+
+/* gcc supports attribute naked for x86 since version 8.0.0, for previous 
versions use asm(".def") */
+#if (defined(__GNUC__) && __GNUC__ >= 8) || defined(__clang__)
+ __attribute__((naked))
+static int __cdecl init_scprintf(const char * __restrict__ 
__UNUSED_PARAM(format), ...)
+{
+asm (
+#else
 asm (
 ".def\t" ASM_SYM(init_scprintf) ";\t.scl\t3;\t.type\t32;\t.endef\n"
 ASM_SYM(init_scprintf) ":\n\t"
+#endif
     "pushal\n\t"
     "call\t" ASM_SYM(resolve_scprintf) "\n\t"
     "popal\n\t"
@@ -63,5 +72,9 @@ ASM_SYM(init_scprintf) ":\n\t"
 ASM_SYM(_scprintf) ":\n\t"
     "jmp\t*" ASM_SYM(__MINGW_IMP_SYMBOL(_scprintf))
 );
+#if (defined(__GNUC__) && __GNUC__ >= 8) || defined(__clang__)
+__builtin_unreachable();
+}
+#endif
 
 #endif
-- 
2.20.1



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

Reply via email to