stdio: Move include of bits/stdio-ldbl.h before bits/stdio.h

Message ID 20210322111530.3215018-1-glaubitz@physik.fu-berlin.de
State Changes Requested, archived
Delegated to: Adhemerval Zanella Netto
Headers
Series stdio: Move include of bits/stdio-ldbl.h before bits/stdio.h |

Commit Message

John Paul Adrian Glaubitz March 22, 2021, 11:15 a.m. UTC
  On targets where long double math is optional and the architecture
does not support support long double, glibc defines a number of
redirection macros which alias "foo" with "__nldbl_foo" while
applying an __asm__ label.

As a result, the __asm__ label gets applied after vfprintf() has
already been used which is not allowed. Moving bits/stdio-ldbl.h
bits/stdio.h in libio/stdio.h avoids this problem.

Fixes bug 27558.
---
 libio/stdio.h | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
  

Comments

Adhemerval Zanella Netto March 23, 2021, 5:59 p.m. UTC | #1
On 22/03/2021 08:15, John Paul Adrian Glaubitz wrote:
> On targets where long double math is optional and the architecture
> does not support support long double, glibc defines a number of
> redirection macros which alias "foo" with "__nldbl_foo" while
> applying an __asm__ label.
> 
> As a result, the __asm__ label gets applied after vfprintf() has
> already been used which is not allowed. Moving bits/stdio-ldbl.h
> bits/stdio.h in libio/stdio.h avoids this problem.
> 
> Fixes bug 27558.
> ---
>   libio/stdio.h | 10 +++++-----
>   1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/libio/stdio.h b/libio/stdio.h
> index 144137cf67..ae5337e855 100644
> --- a/libio/stdio.h
> +++ b/libio/stdio.h
> @@ -857,6 +857,11 @@ extern void funlockfile (FILE *__stream) __THROW;
>   extern int __uflow (FILE *);
>   extern int __overflow (FILE *, int);
>   
> +#include <bits/floatn.h>
> +#if defined __LDBL_COMPAT || __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
> +# include <bits/stdio-ldbl.h>
> +#endif
> +
>   /* If we are compiling with optimizing read this file.  It contains
>      several optimizing inline functions and macros.  */
>   #ifdef __USE_EXTERN_INLINES
> @@ -866,11 +871,6 @@ extern int __overflow (FILE *, int);
>   # include <bits/stdio2.h>
>   #endif
>   
> -#include <bits/floatn.h>
> -#if defined __LDBL_COMPAT || __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
> -# include <bits/stdio-ldbl.h>
> -#endif
> -
>   __END_DECLS
>   
>   #endif /* <stdio.h> included.  */
> 

I am not sure if this is the correct approach, I am seeing it building 
for powerpc64le with gcc version 10.2.1 20210126:

| powerpc64le-glibc-linux-gnu-gcc nscd.c -c [...]
| In file included from ../include/sys/cdefs.h:3,
|                  from ../include/features.h:484,
|                  from ../sysdeps/powerpc/bits/floatn.h:22,
|                  from ../include/stdio.h:7,
|                  from ../argp/argp.h:23,
|                  from ../include/argp.h:2,
|                  from nscd.c:20:
| ../misc/sys/cdefs.h:503:20: error: ‘__dprintf_chk’ undeclared here 
(not in a function); did you mean ‘__sprintf_chk’?
|   503 |   extern __typeof (__##name) __##name \
       |                    ^~
| ../libio/bits/stdio-ldbl.h:98:1: note: in expansion of macro 
‘__LDBL_REDIR2_DECL’
|    98 | __LDBL_REDIR2_DECL (dprintf_chk)
|       | ^~~~~~~~~~~~~~~~~~
| [...]

The postprocessor output shows:

| [...]
|  2820 extern __typeof (__dprintf_chk) __dprintf_chk __asm ("" "__" 
"dprintf_chk" "ieee128");
| [...]
|  3067 extern int __dprintf_chk (int __fd, int __flag, const char 
*__restrict __fmt,
| 3068      ...) __attribute__ ((__format__ (__printf__, 3, 4)));

Meaning we are not using __typeof *before* the function prototype
is define.

I think to proper handle this LLVM limitation we will need to fully
rework how __LDBL_REDIR2_DECL does the redirect by something similar
to what __REDIRECT does by defining something like:

| #if __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
| # ifdef __REDIRECT
|
| /* Alias name defined automatically.  */
| #  define __LDBL_REDIR(name, proto) \
|  extern name proto __asm__ (__ASMNAME ("__" #name "ieee128")); 

|
| /* Alias name defined automatically, with leading underscores.  */ 

| #  define __LDBL_REDIR2_DECL(name) \
|    extern __##name proto __asm__ (__ASMNAME ("__" #name "ieee128")); 
 

|
| /* Alias name defined manually.  */
| #  define __LDBL_REDIR1(name, proto, alias) \
|  extern name proto __asm__ (__ASMNAME (alias)); 


And replace __LDBL_REDIR_DECL with __LDBL_REDIR and __LDBL_REDIR1_DECL
with __LDBL_REDIR1 (while adding the require argument prototype).  It
will allow to move the stdio-ldbl.h definitions to stdio and remove the
header.
  
John Paul Adrian Glaubitz Aug. 16, 2021, 12:24 p.m. UTC | #2
Hi Adhemerval!

On 3/23/21 6:59 PM, Adhemerval Zanella wrote:
> I think to proper handle this LLVM limitation we will need to fully
> rework how __LDBL_REDIR2_DECL does the redirect by something similar
> to what __REDIRECT does by defining something like:
> 
> | #if __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
> | # ifdef __REDIRECT
> |
> | /* Alias name defined automatically.  */
> | #  define __LDBL_REDIR(name, proto) \
> |  extern name proto __asm__ (__ASMNAME ("__" #name "ieee128"));
> |
> | /* Alias name defined automatically, with leading underscores.  */
> | #  define __LDBL_REDIR2_DECL(name) \
> |    extern __##name proto __asm__ (__ASMNAME ("__" #name "ieee128"));
> 
> |
> | /* Alias name defined manually.  */
> | #  define __LDBL_REDIR1(name, proto, alias) \
> |  extern name proto __asm__ (__ASMNAME (alias));
> 
> And replace __LDBL_REDIR_DECL with __LDBL_REDIR and __LDBL_REDIR1_DECL
> with __LDBL_REDIR1 (while adding the require argument prototype).  It
> will allow to move the stdio-ldbl.h definitions to stdio and remove the
> header.

Apologies for the very late reply, this somehow fell off the table.

Could you post a patch to the mailing list, I will then give it a try.

Would be great if we could get this issue fixed as it's rather annoying.

Thanks,
Adrian
  
John Paul Adrian Glaubitz Jan. 22, 2022, 10:39 a.m. UTC | #3
Hi Adhemerval!

On 3/23/21 18:59, Adhemerval Zanella wrote:
> I am not sure if this is the correct approach, I am seeing it building for powerpc64le with gcc version 10.2.1 20210126:
> 
> | powerpc64le-glibc-linux-gnu-gcc nscd.c -c [...]
> | In file included from ../include/sys/cdefs.h:3,
> |                  from ../include/features.h:484,
> |                  from ../sysdeps/powerpc/bits/floatn.h:22,
> |                  from ../include/stdio.h:7,
> |                  from ../argp/argp.h:23,
> |                  from ../include/argp.h:2,
> |                  from nscd.c:20:
> | ../misc/sys/cdefs.h:503:20: error: ‘__dprintf_chk’ undeclared here (not in a function); did you mean ‘__sprintf_chk’?
> |   503 |   extern __typeof (__##name) __##name \
>       |                    ^~
> | ../libio/bits/stdio-ldbl.h:98:1: note: in expansion of macro ‘__LDBL_REDIR2_DECL’
> |    98 | __LDBL_REDIR2_DECL (dprintf_chk)
> |       | ^~~~~~~~~~~~~~~~~~
> | [...]
> 
> The postprocessor output shows:
> 
> | [...]
> |  2820 extern __typeof (__dprintf_chk) __dprintf_chk __asm ("" "__" "dprintf_chk" "ieee128");
> | [...]
> |  3067 extern int __dprintf_chk (int __fd, int __flag, const char *__restrict __fmt,
> | 3068      ...) __attribute__ ((__format__ (__printf__, 3, 4)));
> 
> Meaning we are not using __typeof *before* the function prototype
> is define.
> 
> I think to proper handle this LLVM limitation we will need to fully
> rework how __LDBL_REDIR2_DECL does the redirect by something similar
> to what __REDIRECT does by defining something like:
> 
> | #if __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
> | # ifdef __REDIRECT
> |
> | /* Alias name defined automatically.  */
> | #  define __LDBL_REDIR(name, proto) \
> |  extern name proto __asm__ (__ASMNAME ("__" #name "ieee128"));
> |
> | /* Alias name defined automatically, with leading underscores.  */
> | #  define __LDBL_REDIR2_DECL(name) \
> |    extern __##name proto __asm__ (__ASMNAME ("__" #name "ieee128"));
> 
> |
> | /* Alias name defined manually.  */
> | #  define __LDBL_REDIR1(name, proto, alias) \
> |  extern name proto __asm__ (__ASMNAME (alias));
> 
> And replace __LDBL_REDIR_DECL with __LDBL_REDIR and __LDBL_REDIR1_DECL
> with __LDBL_REDIR1 (while adding the require argument prototype).  It
> will allow to move the stdio-ldbl.h definitions to stdio and remove the
> header.

Do you think you could create a patch for me to test? I think you would be
faster in getting it right. The sparc64 porterbox gcc202 is available for
testing.

The underlying bug [1] is still present in glibc 2.33. I just ran into it
again.

Adrian

> [1] https://sourceware.org/bugzilla/show_bug.cgi?id=27558
  
John Paul Adrian Glaubitz Feb. 23, 2022, 8:51 p.m. UTC | #4
Hi Adhemerval!

On 3/23/21 18:59, Adhemerval Zanella wrote:
> I am not sure if this is the correct approach, I am seeing it building for powerpc64le with gcc version 10.2.1 20210126:
> 
> | powerpc64le-glibc-linux-gnu-gcc nscd.c -c [...]
> | In file included from ../include/sys/cdefs.h:3,
> |                  from ../include/features.h:484,
> |                  from ../sysdeps/powerpc/bits/floatn.h:22,
> |                  from ../include/stdio.h:7,
> |                  from ../argp/argp.h:23,
> |                  from ../include/argp.h:2,
> |                  from nscd.c:20:
> | ../misc/sys/cdefs.h:503:20: error: ‘__dprintf_chk’ undeclared here (not in a function); did you mean ‘__sprintf_chk’?
> |   503 |   extern __typeof (__##name) __##name \
>       |                    ^~
> | ../libio/bits/stdio-ldbl.h:98:1: note: in expansion of macro ‘__LDBL_REDIR2_DECL’
> |    98 | __LDBL_REDIR2_DECL (dprintf_chk)
> |       | ^~~~~~~~~~~~~~~~~~
> | [...]
> 
> The postprocessor output shows:
> 
> | [...]
> |  2820 extern __typeof (__dprintf_chk) __dprintf_chk __asm ("" "__" "dprintf_chk" "ieee128");
> | [...]
> |  3067 extern int __dprintf_chk (int __fd, int __flag, const char *__restrict __fmt,
> | 3068      ...) __attribute__ ((__format__ (__printf__, 3, 4)));
> 
> Meaning we are not using __typeof *before* the function prototype
> is define.
> 
> I think to proper handle this LLVM limitation we will need to fully
> rework how __LDBL_REDIR2_DECL does the redirect by something similar
> to what __REDIRECT does by defining something like:
> 
> | #if __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
> | # ifdef __REDIRECT
> |
> | /* Alias name defined automatically.  */
> | #  define __LDBL_REDIR(name, proto) \
> |  extern name proto __asm__ (__ASMNAME ("__" #name "ieee128"));
> |
> | /* Alias name defined automatically, with leading underscores.  */
> | #  define __LDBL_REDIR2_DECL(name) \
> |    extern __##name proto __asm__ (__ASMNAME ("__" #name "ieee128"));
> 
> |
> | /* Alias name defined manually.  */
> | #  define __LDBL_REDIR1(name, proto, alias) \
> |  extern name proto __asm__ (__ASMNAME (alias));
> 
> And replace __LDBL_REDIR_DECL with __LDBL_REDIR and __LDBL_REDIR1_DECL
> with __LDBL_REDIR1 (while adding the require argument prototype).  It
> will allow to move the stdio-ldbl.h definitions to stdio and remove the
> header.

I don't fully understand how to implement this but I would like to fix this because
this the main remaining issue with glibc that keeps LLVM from successfully building
on sparc64.

Could you maybe help me come up with a patch to fix this issue?

Thanks,
Adrian
  
Adhemerval Zanella Netto Feb. 24, 2022, 5:10 p.m. UTC | #5
On 23/02/2022 17:51, John Paul Adrian Glaubitz wrote:
> Hi Adhemerval!
> 
> On 3/23/21 18:59, Adhemerval Zanella wrote:
>> I am not sure if this is the correct approach, I am seeing it building for powerpc64le with gcc version 10.2.1 20210126:
>>
>> | powerpc64le-glibc-linux-gnu-gcc nscd.c -c [...]
>> | In file included from ../include/sys/cdefs.h:3,
>> |                  from ../include/features.h:484,
>> |                  from ../sysdeps/powerpc/bits/floatn.h:22,
>> |                  from ../include/stdio.h:7,
>> |                  from ../argp/argp.h:23,
>> |                  from ../include/argp.h:2,
>> |                  from nscd.c:20:
>> | ../misc/sys/cdefs.h:503:20: error: ‘__dprintf_chk’ undeclared here (not in a function); did you mean ‘__sprintf_chk’?
>> |   503 |   extern __typeof (__##name) __##name \
>>       |                    ^~
>> | ../libio/bits/stdio-ldbl.h:98:1: note: in expansion of macro ‘__LDBL_REDIR2_DECL’
>> |    98 | __LDBL_REDIR2_DECL (dprintf_chk)
>> |       | ^~~~~~~~~~~~~~~~~~
>> | [...]
>>
>> The postprocessor output shows:
>>
>> | [...]
>> |  2820 extern __typeof (__dprintf_chk) __dprintf_chk __asm ("" "__" "dprintf_chk" "ieee128");
>> | [...]
>> |  3067 extern int __dprintf_chk (int __fd, int __flag, const char *__restrict __fmt,
>> | 3068      ...) __attribute__ ((__format__ (__printf__, 3, 4)));
>>
>> Meaning we are not using __typeof *before* the function prototype
>> is define.
>>
>> I think to proper handle this LLVM limitation we will need to fully
>> rework how __LDBL_REDIR2_DECL does the redirect by something similar
>> to what __REDIRECT does by defining something like:
>>
>> | #if __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
>> | # ifdef __REDIRECT
>> |
>> | /* Alias name defined automatically.  */
>> | #  define __LDBL_REDIR(name, proto) \
>> |  extern name proto __asm__ (__ASMNAME ("__" #name "ieee128"));
>> |
>> | /* Alias name defined automatically, with leading underscores.  */
>> | #  define __LDBL_REDIR2_DECL(name) \
>> |    extern __##name proto __asm__ (__ASMNAME ("__" #name "ieee128"));
>>
>> |
>> | /* Alias name defined manually.  */
>> | #  define __LDBL_REDIR1(name, proto, alias) \
>> |  extern name proto __asm__ (__ASMNAME (alias));
>>
>> And replace __LDBL_REDIR_DECL with __LDBL_REDIR and __LDBL_REDIR1_DECL
>> with __LDBL_REDIR1 (while adding the require argument prototype).  It
>> will allow to move the stdio-ldbl.h definitions to stdio and remove the
>> header.
> 
> I don't fully understand how to implement this but I would like to fix this because
> this the main remaining issue with glibc that keeps LLVM from successfully building
> on sparc64.
> 
> Could you maybe help me come up with a patch to fix this issue?

The idea is to refactor the way we define both the external alias and the
internal ones to remove the libc_hidden_ldbl_proto, __LDBL_REDIR_DECL, and
associate macros.

We will have only one definition, we glibc will define all the expected aliase
(for float128 or nldbl if the case), instead of redefine the function prototype
after the initial prototype (as bits/stdio-ldbl.h).  Afaik this is essentially
what clang does not support and most likely won't.

Below is a very hacking and incomplete patch that does it *only* for fprintf. 
The internal usage change to use a proper internal symbol.  Our current pratice
is not do it for symbols defined in standard C (such as memcpy), but I don't
see who we won't accomplish it since the currenct pratice is doing exactly
what clang does not support so we can use the default symbol name internally
on glibc.

diff --git a/argp/argp-parse.c b/argp/argp-parse.c
index 68dc45417b..2bfbb2d928 100644
--- a/argp/argp-parse.c
+++ b/argp/argp-parse.c
@@ -177,7 +177,7 @@ argp_version_parser (int key, char *arg, struct argp_state *state)
       if (argp_program_version_hook)
 	(*argp_program_version_hook) (state->out_stream, state);
       else if (argp_program_version)
-	fprintf (state->out_stream, "%s\n", argp_program_version);
+	__fprintf (state->out_stream, "%s\n", argp_program_version);
       else
 	__argp_error (state, dgettext (state->root_argp->argp_domain,
 				       "(PROGRAM ERROR) No version known!?"));
@@ -618,7 +618,7 @@ parser_finalize (struct parser *parser,
 	{
 	  if (!(parser->state.flags & ARGP_NO_ERRS)
 	      && parser->state.err_stream)
-	    fprintf (parser->state.err_stream,
+	    __fprintf (parser->state.err_stream,
 		     dgettext (parser->argp->argp_domain,
 			       "%s: Too many arguments\n"),
 		     parser->state.name);
diff --git a/grp/putgrent.c b/grp/putgrent.c
index 966ba2a763..305ff44359 100644
--- a/grp/putgrent.c
+++ b/grp/putgrent.c
@@ -45,10 +45,10 @@ putgrent (const struct group *gr, FILE *stream)
   flockfile (stream);
 
   if (gr->gr_name[0] == '+' || gr->gr_name[0] == '-')
-    retval = fprintf (stream, "%s:%s::",
+    retval = __fprintf (stream, "%s:%s::",
 		      gr->gr_name, _S (gr->gr_passwd));
   else
-    retval = fprintf (stream, "%s:%s:%lu:",
+    retval = __fprintf (stream, "%s:%s:%lu:",
 		      gr->gr_name, _S (gr->gr_passwd),
 		      (unsigned long int) gr->gr_gid);
   if (__builtin_expect (retval, 0) < 0)
@@ -60,7 +60,7 @@ putgrent (const struct group *gr, FILE *stream)
   if (gr->gr_mem != NULL)
     {
       for (size_t i = 0; gr->gr_mem[i] != NULL; i++)
-	if (fprintf (stream, i == 0 ? "%s" : ",%s", gr->gr_mem[i]) < 0)
+	if (__fprintf (stream, i == 0 ? "%s" : ",%s", gr->gr_mem[i]) < 0)
 	  {
 	    /* What else can we do?  */
 	    funlockfile (stream);
diff --git a/gshadow/putsgent.c b/gshadow/putsgent.c
index 9e2dca7eaf..870438de6d 100644
--- a/gshadow/putsgent.c
+++ b/gshadow/putsgent.c
@@ -42,7 +42,7 @@ putsgent (const struct sgrp *g, FILE *stream)
 
   _IO_flockfile (stream);
 
-  if (fprintf (stream, "%s:%s:", g->sg_namp, _S (g->sg_passwd)) < 0)
+  if (__fprintf (stream, "%s:%s:", g->sg_namp, _S (g->sg_passwd)) < 0)
     ++errors;
 
   bool first = true;
@@ -50,7 +50,7 @@ putsgent (const struct sgrp *g, FILE *stream)
   if (sp != NULL)
     while (*sp != NULL)
       {
-	if (fprintf (stream, "%s%s", first ? "" : ",", *sp++) < 0)
+	if (__fprintf (stream, "%s%s", first ? "" : ",", *sp++) < 0)
 	  {
 	    ++errors;
 	    break;
@@ -65,7 +65,7 @@ putsgent (const struct sgrp *g, FILE *stream)
   if (sp != NULL)
     while (*sp != NULL)
       {
-	if (fprintf (stream, "%s%s", first ? "" : ",", *sp++) < 0)
+	if (__fprintf (stream, "%s%s", first ? "" : ",", *sp++) < 0)
 	  {
 	    ++errors;
 	    break;
diff --git a/include/stdio.h b/include/stdio.h
index 23b7fd288c..ffdeabba91 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -209,7 +209,16 @@ extern __typeof (dprintf) __dprintf
      __attribute__ ((__format__ (__printf__, 2, 3)));
 stdio_hidden_ldbl_proto (__, dprintf)
 libc_hidden_ldbl_proto (dprintf)
-libc_hidden_ldbl_proto (fprintf)
+//libc_hidden_ldbl_proto (fprintf)
+#if __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1 && IS_IN (libc) && defined SHARED
+extern __typeof (fprintf) __fprintfieee128;
+libc_hidden_proto (__fprintfieee128);
+extern __typeof (fprintf) __fprintf __asm__ ("__GI___fprintfieee128") __attribute__ ((visibility ("hidden")));
+#else
+extern __typeof (fprintf) __fprintf;
+libc_hidden_proto (__fprintf);
+#endif
+//libc_hidden_proto (fprintf);
 libc_hidden_ldbl_proto (vfprintf)
 libc_hidden_ldbl_proto (sprintf)
 libc_hidden_proto (ungetc)
diff --git a/libio/stdio.h b/libio/stdio.h
index e6425341ce..d5ffb840fd 100644
--- a/libio/stdio.h
+++ b/libio/stdio.h
@@ -347,8 +347,27 @@ extern void setlinebuf (FILE *__stream) __THROW;
 
    This function is a possible cancellation point and therefore not
    marked with __THROW.  */
+#if __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
+# ifdef __REDIRECT_LDBL
+extern int __REDIRECT_LDBL (fprintf, (FILE *__restrict __stream,
+				      const char *__restrict __format, ...),
+			    __fprintfieee128);
+# else
+#  define fprintf ___fprintfieee128
+# endif
+#elif defined __LONG_DOUBLE_MATH_OPTIONAL && defined __NO_LONG_DOUBLE_MATH
+# ifdef __REDIRECT_LDBL
+extern int __REDIRECT_LDBL (fprintf, (FILE *__restrict __stream,
+				      const char *__restrict __format, ...),
+			    __nldbl_fprintf);
+# else
+#  define fprintf __nldbl_fprintf
+# endif
+#else
 extern int fprintf (FILE *__restrict __stream,
 		    const char *__restrict __format, ...);
+#endif
+
 /* Write formatted output to stdout.
 
    This function is a possible cancellation point and therefore not
@@ -895,9 +914,11 @@ extern int __overflow (FILE *, int);
 #endif
 
 #include <bits/floatn.h>
+#if 0
 #if defined __LDBL_COMPAT || __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
 # include <bits/stdio-ldbl.h>
 #endif
+#endif
 
 __END_DECLS
 
diff --git a/malloc/malloc-check.c b/malloc/malloc-check.c
index 0299fe99a7..e1f68bddfb 100644
--- a/malloc/malloc-check.c
+++ b/malloc/malloc-check.c
@@ -17,6 +17,7 @@
    not, see <https://www.gnu.org/licenses/>.  */
 
 #define __mremap mremap
+#define __fprintf fprintf
 #include "malloc.c"
 
 /* When memory is tagged, the checking data is stored in the user part
diff --git a/malloc/malloc.c b/malloc/malloc.c
index 1a1ac1d8f0..f5a6d87160 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -5279,9 +5279,9 @@ __malloc_stats (void)
       memset (&mi, 0, sizeof (mi));
       __libc_lock_lock (ar_ptr->mutex);
       int_mallinfo (ar_ptr, &mi);
-      fprintf (stderr, "Arena %d:\n", i);
-      fprintf (stderr, "system bytes     = %10u\n", (unsigned int) mi.arena);
-      fprintf (stderr, "in use bytes     = %10u\n", (unsigned int) mi.uordblks);
+      __fprintf (stderr, "Arena %d:\n", i);
+      __fprintf (stderr, "system bytes     = %10u\n", (unsigned int) mi.arena);
+      __fprintf (stderr, "in use bytes     = %10u\n", (unsigned int) mi.uordblks);
 #if MALLOC_DEBUG > 1
       if (i > 0)
         dump_heap (heap_for_ptr (top (ar_ptr)));
@@ -5293,12 +5293,12 @@ __malloc_stats (void)
       if (ar_ptr == &main_arena)
         break;
     }
-  fprintf (stderr, "Total (incl. mmap):\n");
-  fprintf (stderr, "system bytes     = %10u\n", system_b);
-  fprintf (stderr, "in use bytes     = %10u\n", in_use_b);
-  fprintf (stderr, "max mmap regions = %10u\n", (unsigned int) mp_.max_n_mmaps);
-  fprintf (stderr, "max mmap bytes   = %10lu\n",
-           (unsigned long) mp_.max_mmapped_mem);
+  __fprintf (stderr, "Total (incl. mmap):\n");
+  __fprintf (stderr, "system bytes     = %10u\n", system_b);
+  __fprintf (stderr, "in use bytes     = %10u\n", in_use_b);
+  __fprintf (stderr, "max mmap regions = %10u\n", (unsigned int) mp_.max_n_mmaps);
+  __fprintf (stderr, "max mmap bytes   = %10lu\n",
+	     (unsigned long) mp_.max_mmapped_mem);
   stderr->_flags2 = old_flags2;
   _IO_funlockfile (stderr);
 }
@@ -5729,7 +5729,7 @@ __malloc_info (int options, FILE *fp)
   mstate ar_ptr = &main_arena;
   do
     {
-      fprintf (fp, "<heap nr=\"%d\">\n<sizes>\n", n++);
+      __fprintf (fp, "<heap nr=\"%d\">\n<sizes>\n", n++);
 
       size_t nblocks = 0;
       size_t nfastblocks = 0;
@@ -5840,12 +5840,12 @@ __malloc_info (int options, FILE *fp)
 
       for (size_t i = 0; i < nsizes; ++i)
 	if (sizes[i].count != 0 && i != NFASTBINS)
-	  fprintf (fp, "\
+	  __fprintf (fp, "\
   <size from=\"%zu\" to=\"%zu\" total=\"%zu\" count=\"%zu\"/>\n",
 		   sizes[i].from, sizes[i].to, sizes[i].total, sizes[i].count);
 
       if (sizes[NFASTBINS].count != 0)
-	fprintf (fp, "\
+	__fprintf (fp, "\
   <unsorted from=\"%zu\" to=\"%zu\" total=\"%zu\" count=\"%zu\"/>\n",
 		 sizes[NFASTBINS].from, sizes[NFASTBINS].to,
 		 sizes[NFASTBINS].total, sizes[NFASTBINS].count);
@@ -5853,7 +5853,7 @@ __malloc_info (int options, FILE *fp)
       total_system += ar_ptr->system_mem;
       total_max_system += ar_ptr->max_system_mem;
 
-      fprintf (fp,
+      __fprintf (fp,
 	       "</sizes>\n<total type=\"fast\" count=\"%zu\" size=\"%zu\"/>\n"
 	       "<total type=\"rest\" count=\"%zu\" size=\"%zu\"/>\n"
 	       "<system type=\"current\" size=\"%zu\"/>\n"
@@ -5863,7 +5863,7 @@ __malloc_info (int options, FILE *fp)
 
       if (ar_ptr != &main_arena)
 	{
-	  fprintf (fp,
+	  __fprintf (fp,
 		   "<aspace type=\"total\" size=\"%zu\"/>\n"
 		   "<aspace type=\"mprotect\" size=\"%zu\"/>\n"
 		   "<aspace type=\"subheaps\" size=\"%zu\"/>\n",
@@ -5873,7 +5873,7 @@ __malloc_info (int options, FILE *fp)
 	}
       else
 	{
-	  fprintf (fp,
+	  __fprintf (fp,
 		   "<aspace type=\"total\" size=\"%zu\"/>\n"
 		   "<aspace type=\"mprotect\" size=\"%zu\"/>\n",
 		   ar_ptr->system_mem, ar_ptr->system_mem);
@@ -5886,7 +5886,7 @@ __malloc_info (int options, FILE *fp)
     }
   while (ar_ptr != &main_arena);
 
-  fprintf (fp,
+  __fprintf (fp,
 	   "<total type=\"fast\" count=\"%zu\" size=\"%zu\"/>\n"
 	   "<total type=\"rest\" count=\"%zu\" size=\"%zu\"/>\n"
 	   "<total type=\"mmap\" count=\"%d\" size=\"%zu\"/>\n"
diff --git a/misc/mntent_r.c b/misc/mntent_r.c
index 3311ba0b50..65f29b97e9 100644
--- a/misc/mntent_r.c
+++ b/misc/mntent_r.c
@@ -251,7 +251,7 @@ __addmntent (FILE *stream, const struct mntent *mnt)
   write_string (stream, mnt->mnt_dir);
   write_string (stream, mnt->mnt_type);
   write_string (stream, mnt->mnt_opts);
-  fprintf (stream, "%d %d\n", mnt->mnt_freq, mnt->mnt_passno);
+  __fprintf (stream, "%d %d\n", mnt->mnt_freq, mnt->mnt_passno);
 
   ret = __ferror_unlocked (stream) != 0 || fflush (stream) != 0;
 
diff --git a/misc/sys/cdefs.h b/misc/sys/cdefs.h
index 44d3826bca..4904d28383 100644
--- a/misc/sys/cdefs.h
+++ b/misc/sys/cdefs.h
@@ -560,6 +560,28 @@
 # include <bits/long-double.h>
 #endif
 
+#if (defined __GNUC__ && __GNUC__ >= 2) || (__clang_major__ >= 4)
+# if __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
+#  define __REDIRECT_LDBL(name, proto, alias) \
+      name proto __asm__ (__ASMNAME (#alias))
+#  ifdef __cplusplus
+#   define __REDIRECT_LDBL_NTH(name, proto, alias) \
+      name proto __THROW __asm__ (__ASMNAME (#alias))
+#   define __REDIRECT_LDBL_NTHNL(name, proto, alias) \
+      name proto __THROWNL __asm__ (__ASMNAME (#alias))
+#  else
+#   define __REDIRECT_LDBL_NTH(name, proto, alias) \
+      name proto __asm__ (__ASMNAME (#alias)) __THROW
+#   define __REDIRECT_LDBL_NTHNL(name, proto, alias) \
+      name proto __asm__ (__ASMNAME (#alias)) __THROWNL
+#  endif
+# else
+#  define __REDIRECT_LDBL(name, proto, alias) name proto
+#  define __REDIRECT_LDBL_NTH(name, proto, alias) name proto
+#  define __REDIRECT_LDBL_NTHNL(name, proto, alias) name proto
+# endif
+#endif
+
 #if __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
 # ifdef __REDIRECT
 
@@ -583,9 +605,11 @@
 #  define __REDIRECT_NTH_LDBL(name, proto, alias) \
   __LDBL_REDIR1_NTH (name, proto, __##alias##ieee128)
 
+#if 0
 /* Unused.  */
 #  define __REDIRECT_LDBL(name, proto, alias) ... unused__redirect_ldbl
 #  define __LDBL_REDIR_NTH(name, proto) ... unused__ldbl_redir_nth
+#endif
 
 # else
 _Static_assert (0, "IEEE 128-bits long double requires redirection on this platform");
@@ -605,12 +629,15 @@ _Static_assert (0, "IEEE 128-bits long double requires redirection on this platf
   extern __typeof (name) name __asm (__ASMNAME (#alias));
 #  define __LDBL_REDIR_DECL(name) \
   extern __typeof (name) name __asm (__ASMNAME ("__nldbl_" #name));
+#if 0
 #  define __REDIRECT_LDBL(name, proto, alias) \
   __LDBL_REDIR1 (name, proto, __nldbl_##alias)
 #  define __REDIRECT_NTH_LDBL(name, proto, alias) \
   __LDBL_REDIR1_NTH (name, proto, __nldbl_##alias)
+#endif
 # endif
 #endif
+#if 0
 #if (!defined __LDBL_COMPAT && __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 0) \
     || !defined __REDIRECT
 # define __LDBL_REDIR1(name, proto, alias) name proto
@@ -625,6 +652,7 @@ _Static_assert (0, "IEEE 128-bits long double requires redirection on this platf
   __REDIRECT_NTH (name, proto, alias)
 # endif
 #endif
+#endif
 
 /* __glibc_macro_warning (MESSAGE) issues warning MESSAGE.  This is
    intended for use in preprocessor macros.
diff --git a/misc/syslog.c b/misc/syslog.c
index ee83b1bb76..0076361f6c 100644
--- a/misc/syslog.c
+++ b/misc/syslog.c
@@ -200,7 +200,7 @@ __vsyslog_internal(int pri, const char *fmt, va_list ap,
 	else
 	  {
 	    __fsetlocking (f, FSETLOCKING_BYCALLER);
-	    fprintf (f, "<%d>", pri);
+	    __fprintf (f, "<%d>", pri);
 	    now = time_now ();
 	    f->_IO_write_ptr += __strftime_l (f->_IO_write_ptr,
 					      f->_IO_write_end
@@ -214,7 +214,7 @@ __vsyslog_internal(int pri, const char *fmt, va_list ap,
 	    if (LogTag != NULL)
 	      __fputs_unlocked (LogTag, f);
 	    if (LogStat & LOG_PID)
-	      fprintf (f, "[%d]", (int) __getpid ());
+	      __fprintf (f, "[%d]", (int) __getpid ());
 	    if (LogTag != NULL)
 	      {
 		__putc_unlocked (':', f);
diff --git a/pwd/putpwent.c b/pwd/putpwent.c
index e3f2f4e09e..480dd59813 100644
--- a/pwd/putpwent.c
+++ b/pwd/putpwent.c
@@ -48,11 +48,11 @@ putpwent (const struct passwd *p, FILE *stream)
     return -1;
 
   if (p->pw_name[0] == '+' || p->pw_name[0] == '-')
-      ret = fprintf (stream, "%s:%s:::%s:%s:%s\n",
+      ret = __fprintf (stream, "%s:%s:::%s:%s:%s\n",
 		     p->pw_name, _S (p->pw_passwd),
 		     gecos, _S (p->pw_dir), _S (p->pw_shell));
   else
-      ret = fprintf (stream, "%s:%s:%lu:%lu:%s:%s:%s\n",
+      ret = __fprintf (stream, "%s:%s:%lu:%lu:%s:%s:%s\n",
 		     p->pw_name, _S (p->pw_passwd),
 		     (unsigned long int) p->pw_uid,
 		     (unsigned long int) p->pw_gid,
diff --git a/shadow/putspent.c b/shadow/putspent.c
index cbbb840d5b..d675e28210 100644
--- a/shadow/putspent.c
+++ b/shadow/putspent.c
@@ -42,47 +42,47 @@ putspent (const struct spwd *p, FILE *stream)
 
   flockfile (stream);
 
-  if (fprintf (stream, "%s:%s:", p->sp_namp, _S (p->sp_pwdp)) < 0)
+  if (__fprintf (stream, "%s:%s:", p->sp_namp, _S (p->sp_pwdp)) < 0)
     ++errors;
 
   if ((p->sp_lstchg != (long int) -1
-       && fprintf (stream, "%ld:", p->sp_lstchg) < 0)
+       && __fprintf (stream, "%ld:", p->sp_lstchg) < 0)
       || (p->sp_lstchg == (long int) -1
 	  && putc_unlocked (':', stream) == EOF))
     ++errors;
 
   if ((p->sp_min != (long int) -1
-       && fprintf (stream, "%ld:", p->sp_min) < 0)
+       && __fprintf (stream, "%ld:", p->sp_min) < 0)
       || (p->sp_min == (long int) -1
 	  && putc_unlocked (':', stream) == EOF))
     ++errors;
 
   if ((p->sp_max != (long int) -1
-       && fprintf (stream, "%ld:", p->sp_max) < 0)
+       && __fprintf (stream, "%ld:", p->sp_max) < 0)
       || (p->sp_max == (long int) -1
 	  && putc_unlocked (':', stream) == EOF))
     ++errors;
 
   if ((p->sp_warn != (long int) -1
-       && fprintf (stream, "%ld:", p->sp_warn) < 0)
+       && __fprintf (stream, "%ld:", p->sp_warn) < 0)
       || (p->sp_warn == (long int) -1
 	  && putc_unlocked (':', stream) == EOF))
     ++errors;
 
   if ((p->sp_inact != (long int) -1
-       && fprintf (stream, "%ld:", p->sp_inact) < 0)
+       && __fprintf (stream, "%ld:", p->sp_inact) < 0)
       || (p->sp_inact == (long int) -1
 	  && putc_unlocked (':', stream) == EOF))
     ++errors;
 
   if ((p->sp_expire != (long int) -1
-       && fprintf (stream, "%ld:", p->sp_expire) < 0)
+       && __fprintf (stream, "%ld:", p->sp_expire) < 0)
       || (p->sp_expire == (long int) -1
 	  && putc_unlocked (':', stream) == EOF))
     ++errors;
 
   if (p->sp_flag != ~0ul
-      && fprintf (stream, "%ld", p->sp_flag) < 0)
+      && __fprintf (stream, "%ld", p->sp_flag) < 0)
     ++errors;
 
   if (putc_unlocked ('\n', stream) == EOF)
diff --git a/stdio-common/fprintf.c b/stdio-common/fprintf.c
index 8d2cd37433..fcfc791a7d 100644
--- a/stdio-common/fprintf.c
+++ b/stdio-common/fprintf.c
@@ -34,8 +34,10 @@ __fprintf (FILE *stream, const char *format, ...)
 
   return done;
 }
-ldbl_hidden_def (__fprintf, fprintf)
-ldbl_strong_alias (__fprintf, fprintf)
+//ldbl_hidden_def (__fprintf, fprintf)
+//ldbl_strong_alias (__fprintf, fprintf)
+hidden_def (__fprintf)
+strong_alias (__fprintf, fprintf)
 
 /* We define the function with the real name here.  But deep down in
    libio the original function _IO_fprintf is also needed.  So make
diff --git a/stdio-common/psiginfo.c b/stdio-common/psiginfo.c
index adf3b71b77..f99c51da17 100644
--- a/stdio-common/psiginfo.c
+++ b/stdio-common/psiginfo.c
@@ -76,7 +76,7 @@ psiginfo (const siginfo_t *pinfo, const char *s)
     }
 
   if (s != NULL && *s != '\0')
-    fprintf (fp, "%s: ", s);
+    __fprintf (fp, "%s: ", s);
 
   const char *desc;
   if (pinfo->si_signo >= 0 && pinfo->si_signo < NSIG
@@ -92,21 +92,21 @@ psiginfo (const siginfo_t *pinfo, const char *s)
 	  if (pinfo->si_signo - SIGRTMIN < SIGRTMAX - pinfo->si_signo)
 	    {
 	      if (pinfo->si_signo == SIGRTMIN)
-		fprintf (fp, "SIGRTMIN (");
+		__fprintf (fp, "SIGRTMIN (");
 	      else
-		fprintf (fp, "SIGRTMIN+%d (", pinfo->si_signo - SIGRTMIN);
+		__fprintf (fp, "SIGRTMIN+%d (", pinfo->si_signo - SIGRTMIN);
 	    }
 	  else
 	    {
 	      if (pinfo->si_signo == SIGRTMAX)
-		fprintf (fp, "SIGRTMAX (");
+		__fprintf (fp, "SIGRTMAX (");
 	      else
-		fprintf (fp, "SIGRTMAX-%d (", SIGRTMAX - pinfo->si_signo);
+		__fprintf (fp, "SIGRTMAX-%d (", SIGRTMAX - pinfo->si_signo);
 	    }
 	}
       else
 #endif
-	fprintf (fp, "%s (", _(desc));
+	__fprintf (fp, "%s (", _(desc));
 
       const char *base = NULL;
       const uint8_t *offarr = NULL;
@@ -178,25 +178,25 @@ Signal generated by the completion of an I/O request");
 	  }
 
       if (str != NULL)
-	fprintf (fp, "%s ", _(str));
+	__fprintf (fp, "%s ", _(str));
       else
-	fprintf (fp, "%d ", pinfo->si_code);
+	__fprintf (fp, "%d ", pinfo->si_code);
 
       if (pinfo->si_signo == SIGILL || pinfo->si_signo == SIGFPE
 	  || pinfo->si_signo == SIGSEGV || pinfo->si_signo == SIGBUS)
-	fprintf (fp, "[%p])\n", pinfo->si_addr);
+	__fprintf (fp, "[%p])\n", pinfo->si_addr);
       else if (pinfo->si_signo == SIGCHLD)
-	fprintf (fp, "%ld %d %ld)\n",
-		 (long int) pinfo->si_pid, pinfo->si_status,
-		 (long int) pinfo->si_uid);
+	__fprintf (fp, "%ld %d %ld)\n",
+		   (long int) pinfo->si_pid, pinfo->si_status,
+		   (long int) pinfo->si_uid);
       else if (pinfo->si_signo == SIGPOLL)
-	fprintf (fp, "%ld)\n", (long int) pinfo->si_band);
+	__fprintf (fp, "%ld)\n", (long int) pinfo->si_band);
       else
-	fprintf (fp, "%ld %ld)\n",
-		 (long int) pinfo->si_pid, (long int) pinfo->si_uid);
+	__fprintf (fp, "%ld %ld)\n",
+		   (long int) pinfo->si_pid, (long int) pinfo->si_uid);
     }
   else
-    fprintf (fp, _("Unknown signal %d\n"),  pinfo->si_signo);
+    __fprintf (fp, _("Unknown signal %d\n"),  pinfo->si_signo);
 
   fclose (fp);
 
diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-fprintf.c b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-fprintf.c
index 4462588675..9892eac1d1 100644
--- a/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-fprintf.c
+++ b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-fprintf.c
@@ -19,8 +19,8 @@
 #include <stdarg.h>
 #include <libio/libioP.h>
 
-extern int
-___ieee128_fprintf (FILE *fp, const char *format, ...)
+int
+__fprintfieee128 (FILE *fp, const char *format, ...)
 {
   va_list ap;
   int done;
@@ -31,5 +31,4 @@ ___ieee128_fprintf (FILE *fp, const char *format, ...)
 
   return done;
 }
-strong_alias (___ieee128_fprintf, __fprintfieee128)
-hidden_def (___ieee128_fprintf)
+hidden_def (__fprintfieee128)
diff --git a/wcsmbs/bits/wchar2.h b/wcsmbs/bits/wchar2.h
index 0e017f458b..055d77eaa9 100644
--- a/wcsmbs/bits/wchar2.h
+++ b/wcsmbs/bits/wchar2.h
@@ -233,6 +233,7 @@ extern int __swprintf_chk (wchar_t *__restrict __s, size_t __n,
 			   const wchar_t *__restrict __format, ...)
      __THROW /* __attribute__ ((__format__ (__wprintf__, 5, 6))) */;
 
+#if 0
 extern int __REDIRECT_NTH_LDBL (__swprintf_alias,
 				(wchar_t *__restrict __s, size_t __n,
 				 const wchar_t *__restrict __fmt, ...),
@@ -249,6 +250,7 @@ __NTH (swprintf (wchar_t *__restrict __s, size_t __n,
 			   sz / sizeof (wchar_t), __fmt, __va_arg_pack ());
   return __swprintf_alias (__s, __n, __fmt, __va_arg_pack ());
 }
+#endif
 #elif !defined __cplusplus
 /* XXX We might want to have support in gcc for swprintf.  */
 # define swprintf(s, n, ...) \
@@ -264,6 +266,7 @@ extern int __vswprintf_chk (wchar_t *__restrict __s, size_t __n,
 			    __gnuc_va_list __arg)
      __THROW /* __attribute__ ((__format__ (__wprintf__, 5, 0))) */;
 
+#if 0
 extern int __REDIRECT_NTH_LDBL (__vswprintf_alias,
 				(wchar_t *__restrict __s, size_t __n,
 				 const wchar_t *__restrict __fmt,
@@ -279,6 +282,7 @@ __NTH (vswprintf (wchar_t *__restrict __s, size_t __n,
 			    sz / sizeof (wchar_t), __fmt, __ap);
   return __vswprintf_alias (__s, __n, __fmt, __ap);
 }
+#endif
 
 
 #if __USE_FORTIFY_LEVEL > 1
  
Adhemerval Zanella Netto March 3, 2022, 7:25 p.m. UTC | #6
On 24/02/2022 14:10, Adhemerval Zanella wrote:
> 
> 
> On 23/02/2022 17:51, John Paul Adrian Glaubitz wrote:
>> Hi Adhemerval!
>>
>> On 3/23/21 18:59, Adhemerval Zanella wrote:
>>> I am not sure if this is the correct approach, I am seeing it building for powerpc64le with gcc version 10.2.1 20210126:
>>>
>>> | powerpc64le-glibc-linux-gnu-gcc nscd.c -c [...]
>>> | In file included from ../include/sys/cdefs.h:3,
>>> |                  from ../include/features.h:484,
>>> |                  from ../sysdeps/powerpc/bits/floatn.h:22,
>>> |                  from ../include/stdio.h:7,
>>> |                  from ../argp/argp.h:23,
>>> |                  from ../include/argp.h:2,
>>> |                  from nscd.c:20:
>>> | ../misc/sys/cdefs.h:503:20: error: ‘__dprintf_chk’ undeclared here (not in a function); did you mean ‘__sprintf_chk’?
>>> |   503 |   extern __typeof (__##name) __##name \
>>>       |                    ^~
>>> | ../libio/bits/stdio-ldbl.h:98:1: note: in expansion of macro ‘__LDBL_REDIR2_DECL’
>>> |    98 | __LDBL_REDIR2_DECL (dprintf_chk)
>>> |       | ^~~~~~~~~~~~~~~~~~
>>> | [...]
>>>
>>> The postprocessor output shows:
>>>
>>> | [...]
>>> |  2820 extern __typeof (__dprintf_chk) __dprintf_chk __asm ("" "__" "dprintf_chk" "ieee128");
>>> | [...]
>>> |  3067 extern int __dprintf_chk (int __fd, int __flag, const char *__restrict __fmt,
>>> | 3068      ...) __attribute__ ((__format__ (__printf__, 3, 4)));
>>>
>>> Meaning we are not using __typeof *before* the function prototype
>>> is define.
>>>
>>> I think to proper handle this LLVM limitation we will need to fully
>>> rework how __LDBL_REDIR2_DECL does the redirect by something similar
>>> to what __REDIRECT does by defining something like:
>>>
>>> | #if __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
>>> | # ifdef __REDIRECT
>>> |
>>> | /* Alias name defined automatically.  */
>>> | #  define __LDBL_REDIR(name, proto) \
>>> |  extern name proto __asm__ (__ASMNAME ("__" #name "ieee128"));
>>> |
>>> | /* Alias name defined automatically, with leading underscores.  */
>>> | #  define __LDBL_REDIR2_DECL(name) \
>>> |    extern __##name proto __asm__ (__ASMNAME ("__" #name "ieee128"));
>>>
>>> |
>>> | /* Alias name defined manually.  */
>>> | #  define __LDBL_REDIR1(name, proto, alias) \
>>> |  extern name proto __asm__ (__ASMNAME (alias));
>>>
>>> And replace __LDBL_REDIR_DECL with __LDBL_REDIR and __LDBL_REDIR1_DECL
>>> with __LDBL_REDIR1 (while adding the require argument prototype).  It
>>> will allow to move the stdio-ldbl.h definitions to stdio and remove the
>>> header.
>>
>> I don't fully understand how to implement this but I would like to fix this because
>> this the main remaining issue with glibc that keeps LLVM from successfully building
>> on sparc64.
>>
>> Could you maybe help me come up with a patch to fix this issue?
> 
> The idea is to refactor the way we define both the external alias and the
> internal ones to remove the libc_hidden_ldbl_proto, __LDBL_REDIR_DECL, and
> associate macros.
> 
> We will have only one definition, we glibc will define all the expected aliase
> (for float128 or nldbl if the case), instead of redefine the function prototype
> after the initial prototype (as bits/stdio-ldbl.h).  Afaik this is essentially
> what clang does not support and most likely won't.

Could you check if this WIP patches help in our case [1]? It essentially removes
all the *-ldbl.h headers and move the alias redirection on the function prototype
itself.

I am still polishing and checking if this breaks something, so if you find any
issue let me know.

https://sourceware.org/git/?p=glibc.git;a=shortlog;h=refs/heads/azanella/redir-refactor
  
John Paul Adrian Glaubitz March 8, 2022, 10:34 a.m. UTC | #7
Hi Adhemverval!

On 3/3/22 20:25, Adhemerval Zanella wrote: 
> Could you check if this WIP patches help in our case [1]? It essentially removes
> all the *-ldbl.h headers and move the alias redirection on the function prototype
> itself.
> 
> I am still polishing and checking if this breaks something, so if you find any
> issue let me know.
> 
> https://sourceware.org/git/?p=glibc.git;a=shortlog;h=refs/heads/azanella/redir-refactor

I just saw this now, sorry. I have a holiday today and I will give it a try now.

Adrian
  

Patch

diff --git a/libio/stdio.h b/libio/stdio.h
index 144137cf67..ae5337e855 100644
--- a/libio/stdio.h
+++ b/libio/stdio.h
@@ -857,6 +857,11 @@  extern void funlockfile (FILE *__stream) __THROW;
 extern int __uflow (FILE *);
 extern int __overflow (FILE *, int);
 
+#include <bits/floatn.h>
+#if defined __LDBL_COMPAT || __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
+# include <bits/stdio-ldbl.h>
+#endif
+
 /* If we are compiling with optimizing read this file.  It contains
    several optimizing inline functions and macros.  */
 #ifdef __USE_EXTERN_INLINES
@@ -866,11 +871,6 @@  extern int __overflow (FILE *, int);
 # include <bits/stdio2.h>
 #endif
 
-#include <bits/floatn.h>
-#if defined __LDBL_COMPAT || __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
-# include <bits/stdio-ldbl.h>
-#endif
-
 __END_DECLS
 
 #endif /* <stdio.h> included.  */