newlib: change static to __fenv_static for fe{enable,disable,get}except

Message ID DB9PR83MB0923514AAE8A36E896FBCBA99243A@DB9PR83MB0923.EURPRD83.prod.outlook.com
State New
Headers
Series newlib: change static to __fenv_static for fe{enable,disable,get}except |

Commit Message

Radek Barton July 3, 2025, 12:28 p.m. UTC
  Hello.

As a follow up of https://sourceware.org/pipermail/newlib/2025/021872.html, I am sending alternative approach how to fix the undefine references issue.

Radek

---
From 4218cbb3360fc45514569703ac9089f0cc2ad748 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Radek=20Barto=C5=88?= <radek.barton@microsoft.com>
Date: Thu, 3 Jul 2025 12:00:22 +0200
Subject: [PATCH] newlib: change static to __fenv_static for
 fe{enable,disable,get}except
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This fixes undefined references to those functions when building cygwin1.dll for AArch64.

Signed-off-by: Radek Bartoň <radek.barton@microsoft.com>
---
 newlib/libc/machine/aarch64/sys/fenv.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
  

Comments

Richard Earnshaw July 3, 2025, 2:40 p.m. UTC | #1
On 03/07/2025 13:28, Radek Barton wrote:
> Hello.
> 
> As a follow up of https://sourceware.org/pipermail/newlib/2025/021872.html, I am sending alternative approach how to fix the undefine references issue.
> 

This is getting closer, but it still changes the behaviour on non-cygwin platforms.  I think I'd introduce a new macro, perhaps something like 

#ifdef __CYGWIN__
#define __cygwin_fenv_static __fenv_static
#else
#define __cygwin_fenv_static static
#endif

then use __cygwin_fenv_static for the cases you want to change.

This should then keep the existing behaviour on elf systems.

> Radek
> 
> ---
> From 4218cbb3360fc45514569703ac9089f0cc2ad748 Mon Sep 17 00:00:00 2001
> From: =?UTF-8?q?Radek=20Barto=C5=88?= <radek.barton@microsoft.com>
> Date: Thu, 3 Jul 2025 12:00:22 +0200
> Subject: [PATCH] newlib: change static to __fenv_static for
>  fe{enable,disable,get}except
> MIME-Version: 1.0
> Content-Type: text/plain; charset=UTF-8
> Content-Transfer-Encoding: 8bit
> 
> This fixes undefined references to those functions when building cygwin1.dll for AArch64.
> 
> Signed-off-by: Radek Bartoň <radek.barton@microsoft.com>
> ---
>  newlib/libc/machine/aarch64/sys/fenv.h | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/newlib/libc/machine/aarch64/sys/fenv.h b/newlib/libc/machine/aarch64/sys/fenv.h
> index 6b0879269..212612725 100644
> --- a/newlib/libc/machine/aarch64/sys/fenv.h
> +++ b/newlib/libc/machine/aarch64/sys/fenv.h
> @@ -82,7 +82,7 @@ extern const fenv_t	*_fe_dfl_env;
>  
>  /* We currently provide no external definitions of the functions below. */

This comment will need updating as well to describe the requirements for cygwin.
>  
> -static inline int
> +__fenv_static inline int
>  feenableexcept(int __mask)
>  {
>  	fenv_t __old_r, __new_r;
> @@ -93,7 +93,7 @@ feenableexcept(int __mask)
>  	return ((__old_r >> _FPUSW_SHIFT) & FE_ALL_EXCEPT);
>  }
>  
> -static inline int
> +__fenv_static inline int
>  fedisableexcept(int __mask)
>  {
>  	fenv_t __old_r, __new_r;
> @@ -104,7 +104,7 @@ fedisableexcept(int __mask)
>  	return ((__old_r >> _FPUSW_SHIFT) & FE_ALL_EXCEPT);
>  }
>  
> -static inline int
> +__fenv_static inline int
>  fegetexcept(void)
>  {
>  	fenv_t __r;

R.
  
Radek Barton July 3, 2025, 2:48 p.m. UTC | #2
Hello.

Thank you for your suggestion.

BTW, what is the current semantics and use case for the __fenv_static macro?

Radek
  
Richard Earnshaw July 3, 2025, 3:20 p.m. UTC | #3
On 03/07/2025 15:48, Radek Barton wrote:
> Hello.
> 
> Thank you for your suggestion.
> 
> BTW, what is the current semantics and use case for the __fenv_static macro?
> 
> Radek

Outside of building newlib I think it's always expected to expand to 'static', so that users get a 'static inline' function (never creates a globally visible symbol, even if not inlined).  When building newlib (specifically libm/machine/*/fenv.c) it's defined to be empty so the functions are marked simply 'inline'; the lines in that file like 

extern inline int feclearexcept(int __excepts);

then cause a real function to be generated for export from the library.

The functions your working on remain static so never get a real instance within the library, so on ELF based platforms they simply do not exist unless _BSD_SOURCE has been defined.

R.
  

Patch

diff --git a/newlib/libc/machine/aarch64/sys/fenv.h b/newlib/libc/machine/aarch64/sys/fenv.h
index 6b0879269..212612725 100644
--- a/newlib/libc/machine/aarch64/sys/fenv.h
+++ b/newlib/libc/machine/aarch64/sys/fenv.h
@@ -82,7 +82,7 @@  extern const fenv_t	*_fe_dfl_env;
 
 /* We currently provide no external definitions of the functions below. */
 
-static inline int
+__fenv_static inline int
 feenableexcept(int __mask)
 {
 	fenv_t __old_r, __new_r;
@@ -93,7 +93,7 @@  feenableexcept(int __mask)
 	return ((__old_r >> _FPUSW_SHIFT) & FE_ALL_EXCEPT);
 }
 
-static inline int
+__fenv_static inline int
 fedisableexcept(int __mask)
 {
 	fenv_t __old_r, __new_r;
@@ -104,7 +104,7 @@  fedisableexcept(int __mask)
 	return ((__old_r >> _FPUSW_SHIFT) & FE_ALL_EXCEPT);
 }
 
-static inline int
+__fenv_static inline int
 fegetexcept(void)
 {
 	fenv_t __r;