On 4.04.2025 13:35, Martin Storsjö wrote:
On Thu, 3 Apr 2025, Jacek Caban wrote:

On 3.04.2025 14:32, Martin Storsjö wrote:
On Wed, 2 Apr 2025, Jacek Caban wrote:

On ARM64EC, function declarations have additional nuances:
- Function names are mangled by prefixing them with "#"
- An unmangled symbol is defined as a weak anti-dependency alias to the mangled
 symbol
- An entry thunk is generated to convert from the x86_64 calling convention to
 the ARM64EC calling convention, used by the emulator
- A .hybmp section entry is generated to associate the function with its entry
 thunk

The compiler can handle all of this if provided with the necessary information.
Naked functions are the most convenient way to achieve this.

Use naked functions only on Clang. GCC doesn’t support them on ARM targets and
has broken behavior on x86_64 by emitting .seh_endprologue.
---
mingw-w64-crt/include/internal.h      | 15 ++++++++++++++-
mingw-w64-crt/math/arm64/nearbyint.c  |  2 +-
mingw-w64-crt/math/arm64/nearbyintf.c |  2 +-
mingw-w64-crt/math/arm64/nearbyintl.c |  2 +-
mingw-w64-crt/math/arm64/trunc.c      |  2 +-
mingw-w64-crt/math/arm64/truncf.c     |  2 +-
6 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/mingw-w64-crt/include/internal.h b/mingw-w64-crt/include/internal.h
index 0d75d63e3..0c0106ab2 100644
--- a/mingw-w64-crt/include/internal.h
+++ b/mingw-w64-crt/include/internal.h
@@ -287,7 +287,11 @@ static inline unsigned int __mingw_statusfp(void)
    return flags;
}

-#define __ASM_NAKED_FUNC(name,code)  \
+/* Use naked functions only on Clang. GCC doesn’t support them on ARM targets and
+ * has broken behavior on x86_64 by emitting .seh_endprologue. */
+#ifndef __clang__
+
+#define __ASM_NAKED_FUNC(name, rettype, args, code) \
    asm(".text\n\t" \
        ".p2align 2\n\t" \
        ".globl " __MINGW64_STRINGIFY(__MINGW_USYMBOL(name)) "\n\t" \

I'm a little undecided about the naming of the macro; as this can be either a naked function or a global asm function, the macro name feels a bit misleading. But I don't have a different good suggestion either.


Wine uses __ASM_GLOBAL_FUNC and __ASM_DEFINE_FUNC. Does that sound better (I'm undecided myself)?

Sorry I'm a little late to reply here... Either of them probably is fine, I don't have a strong preference between them. (I see that the main difference is that __ASM_GLOBAL_FUNC applies name mangling to the function name?)


In Wine, __ASM_DEFINE_FUNC is used by both __ASM_GLOBAL_FUNC and __ASM_STDCALL_FUNC, which have different mangling. I don't expect the need for stdcall functions in mingw-w64-crt as CRT uses cdecl.


I think either of them would feel more natural - unless we explicitly want to point out "asm function which _may_ potentially be a naked function". Currently I don't foresee that we want to point out such a distinction.

I saw that this already was pushed - but I wonder if we'd still want to rename this to e.g. __ASM_DEFINE_FUNC? That name feels a bit more natural than __ASM_GLOBAL_FUNC, but I think __ASM_GLOBAL_FUNC is a closer match to how it is used in Wine, so I guess that one could be fine as well, to increase consistency where relevant.


Renaming sounds good to me, I will do it.


Thanks,

Jacek



_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to