public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
To: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>,
	libc-alpha@sourceware.org
Subject: Re: [PATCH] stdio: Move include of bits/stdio-ldbl.h before bits/stdio.h
Date: Tue, 23 Mar 2021 14:59:54 -0300	[thread overview]
Message-ID: <9dedf9b9-5af3-3f3b-e749-2c8e50ec5dc4@linaro.org> (raw)
In-Reply-To: <20210322111530.3215018-1-glaubitz@physik.fu-berlin.de>



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.

  reply	other threads:[~2021-03-23 17:59 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-22 11:15 John Paul Adrian Glaubitz
2021-03-23 17:59 ` Adhemerval Zanella [this message]
2021-08-16 12:24   ` John Paul Adrian Glaubitz
2022-01-22 10:39   ` John Paul Adrian Glaubitz
2022-02-23 20:51   ` John Paul Adrian Glaubitz
2022-02-24 17:10     ` Adhemerval Zanella
2022-03-03 19:25       ` Adhemerval Zanella
2022-03-08 10:34         ` John Paul Adrian Glaubitz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9dedf9b9-5af3-3f3b-e749-2c8e50ec5dc4@linaro.org \
    --to=adhemerval.zanella@linaro.org \
    --cc=glaubitz@physik.fu-berlin.de \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).