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

Adhemerval Zanella adhemerval.zanella@linaro.org
Thu Mar 3 19:25:33 GMT 2022


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


More information about the Libc-alpha mailing list