Submitted by:            Xi Ruoyao <xry111@xry111.site>
Date:                    2026-08-06
Initial Package Version: 2.44
Upstream Status:         Committed for master (master and 2.44 branch).
Origin:                  Upstream repository (see the "From" line for
                         revision)
Description:             Fix an issue causing tanh to crash on "old"
                         x86_64 processors (without FMA).

From 0b58f5d80d24cf83cfde9d8381aafb11fef0e152 Mon Sep 17 00:00:00 2001
From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Thu, 30 Jul 2026 08:55:54 -0300
Subject: [PATCH] math: Fix x86_64 tanh _FloatN aliases binding to the FMA
 variant [BZ 34465]

The generic implementation emits libm_alias_double unconditionally, so
tanhf32x and tanhf64 bind directly to __tanh_fma.

Guard the alias with '#ifndef __tanh' and emit it from the dispatcher,
as sin.  Also remove the stale __expm1 defines, unused since tanh moved
to CORE-MATH.

Checked on x86_64-linux-gnu, and with 'qemu-x86_64 -cpu Nehalem'.

Reported-by: Michael Brunnbauer <brunni@netestate.de>

(cherry picked from commit b01abba04a954cbd6b2834c0643a08685a915fe5)
---
 NEWS                                      | 1 +
 sysdeps/ieee754/dbl-64/s_tanh.c           | 2 ++
 sysdeps/x86_64/fpu/multiarch/s_tanh-fma.c | 6 ------
 sysdeps/x86_64/fpu/multiarch/s_tanh.c     | 5 ++---
 4 files changed, 5 insertions(+), 9 deletions(-)

diff --git a/NEWS b/NEWS
index fe2b1d7f79..43667c1963 100644
--- a/NEWS
+++ b/NEWS
@@ -11,6 +11,7 @@ The following bugs are resolved with this release:
 
   [34441] math: math: sinh() returns wrong results for some inputs with
     |x| > 36.736801
+  [34465] math: math: x86_64 tanh ifunc selection wrong
 
 Version 2.44
 
diff --git a/sysdeps/ieee754/dbl-64/s_tanh.c b/sysdeps/ieee754/dbl-64/s_tanh.c
index 2029de8fa5..ef80b9edb6 100644
--- a/sysdeps/ieee754/dbl-64/s_tanh.c
+++ b/sysdeps/ieee754/dbl-64/s_tanh.c
@@ -283,4 +283,6 @@ __tanh (double x)
     return as_tanh_database (x, res);
   return res;
 }
+#ifndef __tanh
 libm_alias_double (__tanh, tanh)
+#endif
diff --git a/sysdeps/x86_64/fpu/multiarch/s_tanh-fma.c b/sysdeps/x86_64/fpu/multiarch/s_tanh-fma.c
index 1b808b1227..1e6b33740a 100644
--- a/sysdeps/x86_64/fpu/multiarch/s_tanh-fma.c
+++ b/sysdeps/x86_64/fpu/multiarch/s_tanh-fma.c
@@ -1,10 +1,4 @@
 #define __tanh __tanh_fma
-#define __expm1 __expm1_fma
-
-/* NB: __expm1 may be expanded to __expm1_fma in the following
-   prototypes.  */
-extern long double __expm1l (long double);
-extern long double __expm1f128 (long double);
 
 #define SECTION __attribute__ ((section (".text.fma")))
 
diff --git a/sysdeps/x86_64/fpu/multiarch/s_tanh.c b/sysdeps/x86_64/fpu/multiarch/s_tanh.c
index ec8826f634..9048c977c1 100644
--- a/sysdeps/x86_64/fpu/multiarch/s_tanh.c
+++ b/sysdeps/x86_64/fpu/multiarch/s_tanh.c
@@ -25,10 +25,9 @@ extern double __redirect_tanh (double);
 # define SYMBOL_NAME tanh
 # include "ifunc-fma.h"
 
-libc_ifunc_redirected (__redirect_tanh, tanh, IFUNC_SELECTOR ());
+libc_ifunc_redirected (__redirect_tanh, __tanh, IFUNC_SELECTOR ());
+libm_alias_double (__tanh, tanh)
 
 # define __tanh __tanh_sse2
-# undef libm_alias_double
-# define libm_alias_double(a, b)
 #endif
 #include <sysdeps/ieee754/dbl-64/s_tanh.c>
-- 
2.55.0

