diff mbox

Add D demangling support to libiberty

Message ID 20141014141244.GA17173@adacore.com
State New
Headers show

Commit Message

Joel Brobecker Oct. 14, 2014, 2:12 p.m. UTC
Hello Ian,

> libiberty/ChangeLog
> 2014-08-05  Iain Buclaw  <ibuclaw@gdcproject.org>
> 
>     * Makefile.in (CFILES): Add d-demangle.c.
>     (REQUIRED_OFILES): Add d-demangle.o.
>     * cplus-dem.c (libiberty_demanglers): Add dlang_demangling case.
>     (cplus_demangle): Likewise.
>     * d-demangle.c: New file.
>     * testsuite/Makefile.in (really-check): Add check-d-demangle.
>     * testsuite/d-demangle-expected: New file.

As hinted on gdb-patches, this patch causes a GDB build failure
on Solaris 2.9, because it uses strtold which is not available.
According to gnulib's documentation, it should also break on
the following systems:

        NetBSD 3.0, OpenBSD 3.8, Minix 3.1.8, IRIX 6.5, OSF/1 4.0,
        Solaris 9, Cygwin, MSVC 9, Interix 3.5, BeOS.

This patch attempts to fix the issue by adding a configure check
for strtold and adjusts the code to use strtod if strtold does not
exist.

Does this look OK to you? If yes, can one of the GCC maintainers
please review?

libiberty/ChangeLog:

        * configure.ac: Add check for strtold's availability.
        * configure, config.in: Regenerate.
        * d-demangle.c [!HAVE_STRTOLD]: #define strtold to strtod.

Thank you!

Comments

Ian Lance Taylor Oct. 14, 2014, 2:28 p.m. UTC | #1
On Tue, Oct 14, 2014 at 7:12 AM, Joel Brobecker <brobecker@adacore.com> wrote:
>
>> libiberty/ChangeLog
>> 2014-08-05  Iain Buclaw  <ibuclaw@gdcproject.org>
>>
>>     * Makefile.in (CFILES): Add d-demangle.c.
>>     (REQUIRED_OFILES): Add d-demangle.o.
>>     * cplus-dem.c (libiberty_demanglers): Add dlang_demangling case.
>>     (cplus_demangle): Likewise.
>>     * d-demangle.c: New file.
>>     * testsuite/Makefile.in (really-check): Add check-d-demangle.
>>     * testsuite/d-demangle-expected: New file.
>
> As hinted on gdb-patches, this patch causes a GDB build failure
> on Solaris 2.9, because it uses strtold which is not available.
> According to gnulib's documentation, it should also break on
> the following systems:
>
>         NetBSD 3.0, OpenBSD 3.8, Minix 3.1.8, IRIX 6.5, OSF/1 4.0,
>         Solaris 9, Cygwin, MSVC 9, Interix 3.5, BeOS.
>
> This patch attempts to fix the issue by adding a configure check
> for strtold and adjusts the code to use strtod if strtold does not
> exist.
>
> Does this look OK to you? If yes, can one of the GCC maintainers
> please review?

It doesn't make sense to me to use strtod if strtold is required.  And
if strtold is not required, then it seems to me that we should always
use strtod.  It seems to me that the right options are either 1) use
strtod unconditionally; 2) add strtold to libiberty

Since option 1 is simpler, what bad things would happen if we use
strtod unconditionally?

Ian
Iain Buclaw Oct. 14, 2014, 4:33 p.m. UTC | #2
On 14 October 2014 15:28, Ian Lance Taylor <iant@google.com> wrote:
> On Tue, Oct 14, 2014 at 7:12 AM, Joel Brobecker <brobecker@adacore.com> wrote:
>>
>>> libiberty/ChangeLog
>>> 2014-08-05  Iain Buclaw  <ibuclaw@gdcproject.org>
>>>
>>>     * Makefile.in (CFILES): Add d-demangle.c.
>>>     (REQUIRED_OFILES): Add d-demangle.o.
>>>     * cplus-dem.c (libiberty_demanglers): Add dlang_demangling case.
>>>     (cplus_demangle): Likewise.
>>>     * d-demangle.c: New file.
>>>     * testsuite/Makefile.in (really-check): Add check-d-demangle.
>>>     * testsuite/d-demangle-expected: New file.
>>
>> As hinted on gdb-patches, this patch causes a GDB build failure
>> on Solaris 2.9, because it uses strtold which is not available.
>> According to gnulib's documentation, it should also break on
>> the following systems:
>>
>>         NetBSD 3.0, OpenBSD 3.8, Minix 3.1.8, IRIX 6.5, OSF/1 4.0,
>>         Solaris 9, Cygwin, MSVC 9, Interix 3.5, BeOS.
>>
>> This patch attempts to fix the issue by adding a configure check
>> for strtold and adjusts the code to use strtod if strtold does not
>> exist.
>>
>> Does this look OK to you? If yes, can one of the GCC maintainers
>> please review?
>
> It doesn't make sense to me to use strtod if strtold is required.  And
> if strtold is not required, then it seems to me that we should always
> use strtod.  It seems to me that the right options are either 1) use
> strtod unconditionally; 2) add strtold to libiberty
>
> Since option 1 is simpler, what bad things would happen if we use
> strtod unconditionally?
>
> Ian

I've just seen this, so I'll repeat what I've said in gdb patches too.

The call to strtold is only needed to decode templates which have a
floating point value encoded inside. This value may or may not have a
greater than double precision.

Replacing long double with double will be fine with me.  I'll accept
that I didn't consider legacy in hindsight, and in reality it would be
rather rare to stumble upon the need for strtold.

Regards
Iain
diff mbox

Patch

From 9e4d74607075ef857dfa4e118f43641494aaff90 Mon Sep 17 00:00:00 2001
From: Joel Brobecker <brobecker@adacore.com>
Date: Tue, 14 Oct 2014 09:54:05 -0400
Subject: [PATCH] libiberty: fallback on strtod if strtold is not available.

This patch fixes a build failurer on Solaris 2.9, and all other
systems that do not provide strtold.

libiberty/ChangeLog:

        * configure.ac: Add check for strtold's availability.
        * configure, config.in: Regenerate.
        * d-demangle.c [!HAVE_STRTOLD]: #define strtold to strtod.
---
 libiberty/config.in    | 3 +++
 libiberty/configure    | 2 +-
 libiberty/configure.ac | 2 +-
 libiberty/d-demangle.c | 3 +++
 4 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/libiberty/configure.ac b/libiberty/configure.ac
index 3380819..da20a5f 100644
--- a/libiberty/configure.ac
+++ b/libiberty/configure.ac
@@ -401,7 +401,7 @@  if test "x" = "y"; then
     sbrk setenv setproctitle setrlimit sigsetmask snprintf spawnve spawnvpe \
      stpcpy stpncpy strcasecmp strchr strdup \
      strerror strncasecmp strndup strnlen strrchr strsignal strstr strtod \
-     strtol strtoul strverscmp sysconf sysctl sysmp \
+     strtol strtold strtoul strverscmp sysconf sysctl sysmp \
     table times tmpnam \
     vasprintf vfprintf vprintf vsprintf \
     wait3 wait4 waitpid)
diff --git a/libiberty/d-demangle.c b/libiberty/d-demangle.c
index d31bf94..59de083 100644
--- a/libiberty/d-demangle.c
+++ b/libiberty/d-demangle.c
@@ -46,6 +46,9 @@  If not, see <http://www.gnu.org/licenses/>.  */
 extern long strtol (const char *nptr, char **endptr, int base);
 extern long double strtold (const char *nptr, char **endptr);
 #endif
+#if !defined(HAVE_STRTOLD)
+#define strtold strtod
+#endif
 
 #include <demangle.h>
 #include "libiberty.h"
diff --git a/libiberty/config.in b/libiberty/config.in
index 1cf9c11..8c5f0b6 100644
--- a/libiberty/config.in
+++ b/libiberty/config.in
@@ -280,6 +280,9 @@ 
 /* Define to 1 if you have the `strtol' function. */
 #undef HAVE_STRTOL
 
+/* Define to 1 if you have the `strtold' function. */
+#undef HAVE_STRTOLD
+
 /* Define to 1 if you have the `strtoul' function. */
 #undef HAVE_STRTOUL
 
diff --git a/libiberty/configure b/libiberty/configure
index 96feaed..072b03b 100755
--- a/libiberty/configure
+++ b/libiberty/configure
@@ -5423,7 +5423,7 @@  if test "x" = "y"; then
     sbrk setenv setproctitle setrlimit sigsetmask snprintf spawnve spawnvpe \
      stpcpy stpncpy strcasecmp strchr strdup \
      strerror strncasecmp strndup strnlen strrchr strsignal strstr strtod \
-     strtol strtoul strverscmp sysconf sysctl sysmp \
+     strtol strtold strtoul strverscmp sysconf sysctl sysmp \
     table times tmpnam \
     vasprintf vfprintf vprintf vsprintf \
     wait3 wait4 waitpid
-- 
1.9.1