Re: Wrong unconditional dependency on nanl
Corinna Vinschen <[email protected]>
| Newsgroups | gmane.comp.lib.newlib |
|---|---|
| Message-ID | <[email protected]> |
On Oct 10 15:48, Christophe Lyon wrote: > On Wed, 10 Oct 2018 at 11:41, Corinna Vinschen <[email protected]> wrote: > > > > On Oct 8 15:06, Christophe Lyon wrote: > > > Hello, > > > > > > On aarch64 I've notice that a simple hello.c fails to link against > > > current newlib master: > > > .../aarch64-elf/libc/usr/lib/libc.a(lib_a-strtorx.o): In function `ULtox': > > > .../newlib/libc/stdlib/strtorx.c:92: undefined reference to `nanl' > > > > > > It seems to me that an unconditional dependency on nanl() was > > > introduced by commit > > > 6c212a8b7873703c4f98c6b68579b234918be83a > > > Author: Masamichi Hosoda <[email protected]> > > > Date: Thu Aug 16 09:18:50 2018 +0900 > > > Fix strtod ("nan") and strtold ("nan") returns wrong negative NaN > > > > > > but I'm not sure how to fix this as I did not follow the discussion > > > around this patch. > > > > > > It seems to me that nanl() is only defined if _LDBL_EQ_DBL > > > (newlib/libm/common/nanl.c), but the patch above introduces a call to > > > nanl() in a code path where !defined (_LDBL_EQ_DBL) > > > > > > This I suspect the problem is present on other targets, too ? > > > > Cygwin has it's own nanl implemented in winsup/cygwin/math/nanl.c. > > > > However, dropping it there and using a patch like this: > > > > diff --git a/newlib/libm/common/nanl.c b/newlib/libm/common/nanl.c > > index 40f898109edd..b8ae63ea7539 100644 > > --- a/newlib/libm/common/nanl.c > > +++ b/newlib/libm/common/nanl.c > > @@ -38,5 +38,11 @@ nanl (const char *tagp) > > { > > return nan(tagp); > > } > > +#elif __GNUC_PREREQ (3, 3) > > +long double > > +nanl (const char *tagp) > > +{ > > + return __builtin_nanl(""); > > +} > > #endif > > > > should help along all targets, right? Is there any target still using > > a pre-3.3 GCC? > > > > It does help on aarch64-elf, but a change to rdimon.specs is required > because libc now depends on libm: this can be seen when compiling a > C++ hello.cpp. Hmm, that's an interesting point. What I don't understand is why this dependency wasn't already visible before. strtod.c and wcstod.c call nan() and nanf(), vfprintf.c and vfwprintf.c call nanf(). Why is a call to nanl() different? Please note that this is not visible on Cygwin where libc and libm are just link libs while all of their code is in cygwin1.dll anyway. > In addition, there's still a warning: > newlib/libc/stdlib/strtorx.c:92:24: warning: implicit declaration of > function ‘nanl’ That's an easy one after making sure why the above occurs. As for a solution; provided we can rely on GCC 3.3 or later, we could define internal macros __nan, __nanf and __nanl like this: #ifdef _COMPILING_NEWLIB #define __nan(_x) __builtin_nan(_x) #define __nanf(_x) __builtin_nanf(_x) #define __nanl(_x) __builtin_nanl(_x) #endif and use them within libc throughout. Corinna -- Corinna Vinschen Cygwin Maintainer Red Hat
signature.asc
(application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEoVYPmneWZnwT6kwF9TYGna5ET6AFAlu+EjQACgkQ9TYGna5E T6CigQ/9GQ/oXXH2JNwe1O+E1bc2+AQ0GfEkiBx7IYl7IOIGtQY/ipYGRrtyNqJo 0LOfmNnvitr/jPWi5tkbaZ0n0cNQqs/fYEql/kLQu/mgYjHXjaQ2w4oBK/MvbK3+ uieWvkC2NQ+26280+a2w10ub8Zx7KZnH+z7j1CRsVpGiQn78Ya1LG3a0mya6P5QF NxSt/kv+JSTEWNxkiBd9dzIbPoIYSpFViMjKpzaJ+9jyAUArwJ2oNdrIcgR/5Wvt /keDzX6wJv6FeIfIRDYDpbrm573CUby455J6ZQ0bx/Tc36yXDWdStscMPTZf0JTm Y1T45ho0xJXQx3jYvdXyQMiIKwQjJtZmZ1QKg41A7cExpFNxJABPbhvueziw1H83 GbfHDBHZgp7LYDPl3ERamzAcLY1Z5jPXL3A83OOv4QAjSL8kFGq3MDm07o8BALLp y+u/n+IfIT5D9HKhM06jXlC89Q1z7mIsI14E1ZhvB7bKRt/PYxYuFNFql1SwpSCa bSHDeEW+l+3jMkm08JFIP/PTO1YsDaJ3jt3lwY4vhunjGbvjb77S/Wc3q2rdt7Mp 0efg3qDGWy1/s6pKFYMK1KI9UvqrLwZks6NecLc1F/up1w6GVlPUb4jUo3S+dliU QroqsmO93ybe7rz0kiF0VoqD65CC86Fi1vqPwrFc6KuhXNrldNY= =+TuS -----END PGP SIGNATURE-----