[PATCH] x86: Fix x86_64 build failure with -Os (BZ 33367)

Adhemerval Zanella adhemerval.zanella@linaro.org
Tue Dec 23 17:30:45 GMT 2025


The 13cfd77bf5 change broke the b5d88fa6c3 fix by removing the symbol
to __symbol redirections.  Although it works for -O2 with both gcc
and clang, with -Os without the redirection, the libcall might still
be issued.

This patch reinstates the b5d88fa6c3 fix, with a modification that
allows each ifunc variant to control which trunc to issue.  This is
required for clang, which defines HAVE_X86_INLINE_TRUNC to 1 (meaning
that trunc will always be lowered to the instruction on -Os).

Checked on x86_64-linux-gnu with -O2 and -Os with gcc-15 and clang-18.
---
 sysdeps/ieee754/dbl-64/s_modf.c               | 5 ++++-
 sysdeps/ieee754/flt-32/s_modff.c              | 5 ++++-
 sysdeps/x86_64/fpu/multiarch/s_modf-avx.c     | 1 +
 sysdeps/x86_64/fpu/multiarch/s_modf-sse4_1.c  | 1 +
 sysdeps/x86_64/fpu/multiarch/s_modff-avx.c    | 1 +
 sysdeps/x86_64/fpu/multiarch/s_modff-sse4_1.c | 1 +
 6 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/sysdeps/ieee754/dbl-64/s_modf.c b/sysdeps/ieee754/dbl-64/s_modf.c
index 77e0226be9..2462529db5 100644
--- a/sysdeps/ieee754/dbl-64/s_modf.c
+++ b/sysdeps/ieee754/dbl-64/s_modf.c
@@ -25,12 +25,15 @@ __modf (double x, double *iptr)
 {
   uint64_t t = asuint64 (x);
 #if USE_TRUNC_BUILTIN
+# ifndef TRUNC
+#  define TRUNC trunc
+# endif
   if (is_inf (t))
     {
       *iptr = x;
       return copysign (0.0, x);
     }
-  *iptr = trunc (x);
+  *iptr = TRUNC (x);
   return copysign (x - *iptr, x);
 #else
   int e = get_exponent (t);
diff --git a/sysdeps/ieee754/flt-32/s_modff.c b/sysdeps/ieee754/flt-32/s_modff.c
index b5dac7521d..4ae14832c4 100644
--- a/sysdeps/ieee754/flt-32/s_modff.c
+++ b/sysdeps/ieee754/flt-32/s_modff.c
@@ -25,12 +25,15 @@ __modff (float x, float *iptr)
 {
   uint32_t t = asuint (x);
 #if USE_TRUNCF_BUILTIN
+# ifndef TRUNCF
+#  define TRUNCF truncf
+# endif
   if (is_inf (t))
     {
       *iptr = x;
       return copysignf (0.0, x);
     }
-  *iptr = truncf (x);
+  *iptr = TRUNCF (x);
   return copysignf (x - *iptr, x);
 #else
   int e = get_exponent (t);
diff --git a/sysdeps/x86_64/fpu/multiarch/s_modf-avx.c b/sysdeps/x86_64/fpu/multiarch/s_modf-avx.c
index 9b8b951a97..76e7896277 100644
--- a/sysdeps/x86_64/fpu/multiarch/s_modf-avx.c
+++ b/sysdeps/x86_64/fpu/multiarch/s_modf-avx.c
@@ -1,2 +1,3 @@
 #define __modf __modf_avx
+#define TRUNC __trunc
 #include <sysdeps/ieee754/dbl-64/s_modf.c>
diff --git a/sysdeps/x86_64/fpu/multiarch/s_modf-sse4_1.c b/sysdeps/x86_64/fpu/multiarch/s_modf-sse4_1.c
index 1f77386336..49fa4f0b97 100644
--- a/sysdeps/x86_64/fpu/multiarch/s_modf-sse4_1.c
+++ b/sysdeps/x86_64/fpu/multiarch/s_modf-sse4_1.c
@@ -1,2 +1,3 @@
 #define __modf __modf_sse41
+#define TRUNC __trunc
 #include <sysdeps/ieee754/dbl-64/s_modf.c>
diff --git a/sysdeps/x86_64/fpu/multiarch/s_modff-avx.c b/sysdeps/x86_64/fpu/multiarch/s_modff-avx.c
index 488f93700c..3b00c364b1 100644
--- a/sysdeps/x86_64/fpu/multiarch/s_modff-avx.c
+++ b/sysdeps/x86_64/fpu/multiarch/s_modff-avx.c
@@ -1,2 +1,3 @@
 #define __modff __modff_avx
+#define TRUNCF __truncf
 #include <sysdeps/ieee754/flt-32/s_modff.c>
diff --git a/sysdeps/x86_64/fpu/multiarch/s_modff-sse4_1.c b/sysdeps/x86_64/fpu/multiarch/s_modff-sse4_1.c
index 8e49970ffc..58d46582bd 100644
--- a/sysdeps/x86_64/fpu/multiarch/s_modff-sse4_1.c
+++ b/sysdeps/x86_64/fpu/multiarch/s_modff-sse4_1.c
@@ -1,2 +1,3 @@
 #define __modff __modff_sse41
+#define TRUNCF __truncf
 #include <sysdeps/ieee754/flt-32/s_modff.c>
-- 
2.43.0



More information about the Libc-alpha mailing list