1
0
mirror of https://git.code.sf.net/p/mingw-w64/mingw-w64 synced 2025-04-18 17:44:18 +03:00

crt: Use naked functions for ARM64 assembly functions.

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.

Signed-off-by: Jacek Caban <jacek@codeweavers.com>
This commit is contained in:
Jacek Caban 2025-04-02 23:02:09 +02:00
parent 85c48a0bf4
commit 6355a96915
6 changed files with 19 additions and 6 deletions

View File

@ -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 doesnt support them on ARM targets and
* has broken behavior on x86_64 by emitting .seh_endprologue. */
#ifndef __clang__
#define __ASM_NAKED_FUNC(rettype, name, args, code) \
asm(".text\n\t" \
".p2align 2\n\t" \
".globl " __MINGW64_STRINGIFY(__MINGW_USYMBOL(name)) "\n\t" \
@ -295,6 +299,15 @@ static inline unsigned int __mingw_statusfp(void)
__MINGW64_STRINGIFY(__MINGW_USYMBOL(name)) ":\n\t" \
code "\n\t");
#else
#define __ASM_NAKED_FUNC(rettype, name, args, code) \
rettype __attribute__((naked)) name args { \
asm(code "\n\t"); \
}
#endif
#ifdef __cplusplus
}
#endif

View File

@ -7,7 +7,7 @@
#include <math.h>
#include <internal.h>
__ASM_NAKED_FUNC(nearbyint,
__ASM_NAKED_FUNC(double, nearbyint, (double x),
"mrs x1, fpcr\n\t"
"frintx d0, d0\n\t"
"msr fpcr, x1\n\t"

View File

@ -7,7 +7,7 @@
#include <math.h>
#include <internal.h>
__ASM_NAKED_FUNC(nearbyintf,
__ASM_NAKED_FUNC(float, nearbyintf, (float x),
"mrs x1, fpcr\n\t"
"frintx s0, s0\n\t"
"msr fpcr, x1\n\t"

View File

@ -7,7 +7,7 @@
#include <math.h>
#include <internal.h>
__ASM_NAKED_FUNC(nearbyintl,
__ASM_NAKED_FUNC(long double, nearbyintl, (long double x),
"mrs x1, fpcr\n\t"
"frintx d0, d0\n\t"
"msr fpcr, x1\n\t"

View File

@ -7,6 +7,6 @@
#include <math.h>
#include <internal.h>
__ASM_NAKED_FUNC(trunc,
__ASM_NAKED_FUNC(double, trunc, (double x),
"frintz d0, d0\n\t"
"ret")

View File

@ -7,6 +7,6 @@
#include <math.h>
#include <internal.h>
__ASM_NAKED_FUNC(truncf,
__ASM_NAKED_FUNC(float, truncf, (float x),
"frintz s0, s0\n\t"
"ret")