[2/6] Undefine redirections after long double definition on __LDBL_COMPAT [BZ #23294]

Message ID f8bf9fb21fc2b30673979e049155b1090b254279.1580757509.git.murphyp@linux.vnet.ibm.com
State Committed
Headers

Commit Message

Paul E. Murphy Feb. 3, 2020, 9:10 p.m. UTC
  From: Tulio Magno Quites Machado Filho <tuliom@linux.ibm.com>

After defining the long double redirections to double, __MATHDECL_1 has
to be redefined to its previous state in order to avoid redirecting all
subsequent types.
---
 math/complex.h                                | 10 ++-
 math/math.h                                   | 18 ++--
 sysdeps/ieee754/ldbl-opt/Makefile             |  4 +-
 .../ldbl-opt/test-redirection-ldbl-64.c       | 87 +++++++++++++++++++
 4 files changed, 112 insertions(+), 7 deletions(-)
 create mode 100644 sysdeps/ieee754/ldbl-opt/test-redirection-ldbl-64.c
  

Comments

Paul E Murphy Feb. 17, 2020, 3:08 p.m. UTC | #1
Ping.

On 2/3/20 3:10 PM, Paul E. Murphy wrote:
> From: Tulio Magno Quites Machado Filho <tuliom@linux.ibm.com>
> 
> After defining the long double redirections to double, __MATHDECL_1 has
> to be redefined to its previous state in order to avoid redirecting all
> subsequent types.
> ---
>   math/complex.h                                | 10 ++-
>   math/math.h                                   | 18 ++--
>   sysdeps/ieee754/ldbl-opt/Makefile             |  4 +-
>   .../ldbl-opt/test-redirection-ldbl-64.c       | 87 +++++++++++++++++++
>   4 files changed, 112 insertions(+), 7 deletions(-)
>   create mode 100644 sysdeps/ieee754/ldbl-opt/test-redirection-ldbl-64.c
  
Paul E Murphy Feb. 18, 2020, 3:15 p.m. UTC | #2
My only contribution to this patch is to fix the merge conflict in the 
Makefile while rebasing.

Note, this does address the feedback from Joseph [1] about adding a test 
which will fail without this change.  I Have verified the test does fail 
without the change.

If there are no further requests or objections for this patch, I would 
like to commit it friday.  It is necessary to for functional redirection 
support in ldbl-128ibm-compat.

[1] https://sourceware.org/ml/libc-alpha/2018-06/msg00600.html


Reviewed-by: Paul E. Murphy <murphyp@linux.vnet.ibm.com>

On 2/17/20 9:08 AM, Paul E Murphy wrote:
> Ping.
> 
> On 2/3/20 3:10 PM, Paul E. Murphy wrote:
>> From: Tulio Magno Quites Machado Filho <tuliom@linux.ibm.com>
>>
>> After defining the long double redirections to double, __MATHDECL_1 has
>> to be redefined to its previous state in order to avoid redirecting all
>> subsequent types.
>> ---
>>   math/complex.h                                | 10 ++-
>>   math/math.h                                   | 18 ++--
>>   sysdeps/ieee754/ldbl-opt/Makefile             |  4 +-
>>   .../ldbl-opt/test-redirection-ldbl-64.c       | 87 +++++++++++++++++++
>>   4 files changed, 112 insertions(+), 7 deletions(-)
>>   create mode 100644 sysdeps/ieee754/ldbl-opt/test-redirection-ldbl-64.c
  
Paul E Murphy Feb. 21, 2020, 2:31 p.m. UTC | #3
Pushed after verification against all build-many-glibcs.py targets.

On 2/18/20 9:15 AM, Paul E Murphy wrote:
> My only contribution to this patch is to fix the merge conflict in the 
> Makefile while rebasing.
> 
> Note, this does address the feedback from Joseph [1] about adding a test 
> which will fail without this change.  I Have verified the test does fail 
> without the change.
> 
> If there are no further requests or objections for this patch, I would 
> like to commit it friday.  It is necessary to for functional redirection 
> support in ldbl-128ibm-compat.
> 
> [1] https://sourceware.org/ml/libc-alpha/2018-06/msg00600.html
> 
> 
> Reviewed-by: Paul E. Murphy <murphyp@linux.vnet.ibm.com>
> 
> On 2/17/20 9:08 AM, Paul E Murphy wrote:
>> Ping.
>>
>> On 2/3/20 3:10 PM, Paul E. Murphy wrote:
>>> From: Tulio Magno Quites Machado Filho <tuliom@linux.ibm.com>
>>>
>>> After defining the long double redirections to double, __MATHDECL_1 has
>>> to be redefined to its previous state in order to avoid redirecting all
>>> subsequent types.
>>> ---
>>>   math/complex.h                                | 10 ++-
>>>   math/math.h                                   | 18 ++--
>>>   sysdeps/ieee754/ldbl-opt/Makefile             |  4 +-
>>>   .../ldbl-opt/test-redirection-ldbl-64.c       | 87 +++++++++++++++++++
>>>   4 files changed, 112 insertions(+), 7 deletions(-)
>>>   create mode 100644 sysdeps/ieee754/ldbl-opt/test-redirection-ldbl-64.c
  

Patch

diff --git a/math/complex.h b/math/complex.h
index d63005bec6..42f3fd7517 100644
--- a/math/complex.h
+++ b/math/complex.h
@@ -98,8 +98,10 @@  __BEGIN_DECLS
 #define __MATHDECL(type, function, args) \
   __MATHDECL_1(type, function, args); \
   __MATHDECL_1(type, __CONCAT(__,function), args)
-#define __MATHDECL_1(type, function, args) \
+#define __MATHDECL_1_IMPL(type, function, args) \
   extern type __MATH_PRECNAME(function) args __THROW
+#define __MATHDECL_1(type, function, args) \
+  __MATHDECL_1_IMPL(type, function, args)
 
 #define _Mdouble_ 		double
 #define __MATH_PRECNAME(name)	name
@@ -127,6 +129,11 @@  __BEGIN_DECLS
 # define _Mdouble_ 		long double
 # define __MATH_PRECNAME(name)	name##l
 # include <bits/cmathcalls.h>
+# if defined __LDBL_COMPAT
+#  undef __MATHDECL_1
+#  define __MATHDECL_1(type, function, args) \
+  __MATHDECL_1_IMPL(type, function, args)
+# endif
 #endif
 #undef	_Mdouble_
 #undef	__MATH_PRECNAME
@@ -215,6 +222,7 @@  __BEGIN_DECLS
 # undef _Mdouble_complex_
 #endif
 
+#undef	__MATHDECL_1_IMPL
 #undef	__MATHDECL_1
 #undef	__MATHDECL
 #undef	__MATHCALL
diff --git a/math/math.h b/math/math.h
index fb211bb00b..e13b3f3a29 100644
--- a/math/math.h
+++ b/math/math.h
@@ -279,8 +279,13 @@  enum
 #define __MATHDECLX(type, function,suffix, args, attrib) \
   __MATHDECL_1(type, function,suffix, args) __attribute__ (attrib); \
   __MATHDECL_1(type, __CONCAT(__,function),suffix, args) __attribute__ (attrib)
-#define __MATHDECL_1(type, function,suffix, args) \
+#define __MATHDECL_1_IMPL(type, function, suffix, args) \
   extern type __MATH_PRECNAME(function,suffix) args __THROW
+#define __MATHDECL_1(type, function, suffix, args) \
+  __MATHDECL_1_IMPL(type, function, suffix, args)
+
+#define __MATHREDIR(type, function, suffix, args, to) \
+  extern type __REDIRECT_NTH (__MATH_PRECNAME (function, suffix), args, to)
 
 #define _Mdouble_		double
 #define __MATH_PRECNAME(name,r)	__CONCAT(name,r)
@@ -331,11 +336,8 @@  extern long double __REDIRECT_NTH (nexttowardl,
 #   endif
 
 #   undef __MATHDECL_1
-#   define __MATHDECL_2(type, function,suffix, args, alias) \
-  extern type __REDIRECT_NTH(__MATH_PRECNAME(function,suffix), \
-			     args, alias)
 #   define __MATHDECL_1(type, function,suffix, args) \
-  __MATHDECL_2(type, function,suffix, args, __CONCAT(function,suffix))
+  __MATHREDIR(type, function, suffix, args, __CONCAT(function,suffix))
 #  endif
 
 /* Include the file of declarations again, this time using `long double'
@@ -353,6 +355,11 @@  extern long double __REDIRECT_NTH (nexttowardl,
 #  undef __MATH_DECLARING_DOUBLE
 #  undef __MATH_DECLARING_FLOATN
 
+#  if defined __LDBL_COMPAT
+#   undef __MATHDECL_1
+#   define __MATHDECL_1(type, function, suffix, args) \
+  __MATHDECL_1_IMPL(type, function, suffix, args)
+#  endif
 # endif /* !(__NO_LONG_DOUBLE_MATH && _LIBC) || __LDBL_COMPAT */
 
 #endif	/* Use ISO C99.  */
@@ -479,6 +486,7 @@  extern long double __REDIRECT_NTH (nexttowardl,
 # undef __MATH_DECLARING_FLOATN
 #endif /* __HAVE_DISTINCT_FLOAT128X || (__HAVE_FLOAT128X && !_LIBC).  */
 
+#undef	__MATHDECL_1_IMPL
 #undef	__MATHDECL_1
 #undef	__MATHDECL
 #undef	__MATHCALL
diff --git a/sysdeps/ieee754/ldbl-opt/Makefile b/sysdeps/ieee754/ldbl-opt/Makefile
index 791a5eabd2..4e41a27e80 100644
--- a/sysdeps/ieee754/ldbl-opt/Makefile
+++ b/sysdeps/ieee754/ldbl-opt/Makefile
@@ -172,9 +172,11 @@  CFLAGS-nldbl-y0.c = -fno-builtin-y0l
 CFLAGS-nldbl-y1.c = -fno-builtin-y1l
 CFLAGS-nldbl-yn.c = -fno-builtin-ynl
 
-tests += test-narrow-macros-ldbl-64 test-nldbl-redirect
+tests += test-narrow-macros-ldbl-64 test-nldbl-redirect \
+	 test-redirection-ldbl-64
 CFLAGS-test-narrow-macros-ldbl-64.c += -mlong-double-64
 CFLAGS-test-nldbl-redirect.c += -mlong-double-64
+CFLAGS-test-redirection-ldbl-64.c += -mlong-double-64
 
 $(objpfx)test-nldbl-redirect: $(objpfx)libnldbl_nonshared.a
 
diff --git a/sysdeps/ieee754/ldbl-opt/test-redirection-ldbl-64.c b/sysdeps/ieee754/ldbl-opt/test-redirection-ldbl-64.c
new file mode 100644
index 0000000000..cc683596a0
--- /dev/null
+++ b/sysdeps/ieee754/ldbl-opt/test-redirection-ldbl-64.c
@@ -0,0 +1,87 @@ 
+/* Test if __LDBL_COMPAT redirections conflict with other types.
+   Copyright (C) 2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* Redirecting functions twice may lead to -Werror=pragmas errors.
+   In a __LDBL_COMPAT environment, only long double functions should be
+   redirected.  This test redirects math functions to a dummy function in
+   order to validate if they have not been redirected before.  */
+
+#include <math.h>
+#include <complex.h>
+
+#if defined __FINITE_MATH_ONLY__ && __FINITE_MATH_ONLY__ > 0
+# error "This test should never request finite functions"
+#endif
+
+#define MATH_REDIRX(function, to) \
+  extern typeof (function) function __asm__ ("" # to);
+#define MATH_REDIR(function) MATH_REDIRX (function, __ ## function)
+
+#if __HAVE_FLOAT32
+# define MATH_F32(function) MATH_REDIR(function ## f32)
+#else
+# define MATH_F32(function)
+#endif
+
+#if __HAVE_FLOAT32X
+# define MATH_F32X(function) MATH_REDIR(function ## f32x)
+#else
+# define MATH_F32X(function)
+#endif
+
+#if __HAVE_FLOAT64
+# define MATH_F64(function) MATH_REDIR(function ## f64)
+#else
+# define MATH_F64(function)
+#endif
+
+#if __HAVE_FLOAT64X
+# define MATH_F64X(function) MATH_REDIR(function ## f64x)
+#else
+# define MATH_F64X(function)
+#endif
+
+#define MATH_FUNCTION(function) \
+  MATH_REDIR(function); \
+  MATH_REDIR(function ## f); \
+  MATH_F32(function); \
+  MATH_F32X(function); \
+  MATH_F64(function); \
+  MATH_F64X(function);
+
+MATH_FUNCTION (acos);
+MATH_FUNCTION (asin);
+MATH_FUNCTION (exp);
+MATH_FUNCTION (floor);
+MATH_FUNCTION (ldexp);
+MATH_FUNCTION (log);
+MATH_FUNCTION (sin);
+MATH_FUNCTION (cabs);
+MATH_FUNCTION (cacos);
+MATH_FUNCTION (casin);
+MATH_FUNCTION (clog);
+MATH_FUNCTION (csin);
+
+static int
+do_test (void)
+{
+  /* This is a compilation test.  */
+  return 0;
+}
+
+#include <support/test-driver.c>