Re: [PATCH 01/36] Create libiberty/libiberty.m4, have GDB and GDBserver use it

Pedro Alves
2015-02-27T16:23:07Z

On 02/09/2015 11:20 PM, Pedro Alves wrote:
> Converting GDB to be a C++ program, I stumbled on 'basename' issues,
> like:
>

...

> So I thought of adding a m4 file that projects that use libiberty can
> source to pull in the autoconf checks that libiberty needs done in
> order to use its public headers.
>
> Turns out that this has already happened. Since I first wrote this a
> few months back, libiberty gained more HAVE_DECL_FOO checks even, for
> the strtol & friends replacements.
>
> Are the libiberty changes OK?

I moved the libiberty.m4 patch to the gdb/ directory instead,
and pushed it, as below, in order to unblock the GDB C++ conversion
series, and make it easier for others to help with the
conversion as well.

I put a libiberty.m4 patch series here:

https://github.com/palves/gdb/tree/palves/libiberty_m4

that converts gas, gold, ld, gdb and libiberty/ itself to
use libiberty/libiberty.m4. If people think that's a good
idea, I can post it at some point.

----
From 07697489f4587e41f4f63aa526c1bd7d2fcd5494 Mon Sep 17 00:00:00 2001
From: Pedro Alves <palves@redhat.com>
Date: Fri, 27 Feb 2015 15:52:02 +0000
Subject: [PATCH] Create libiberty.m4, have GDB and GDBserver use it
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Converting GDB to be a C++ program, I stumbled on 'basename' issues,
like:

src/gdb/../include/ansidecl.h:169:64: error: new declaration ‘char* basename(const char*)’
/usr/include/string.h:597:26: error: ambiguates old declaration ‘const char* basename(const char*)’

which I believe led to this bit in gold's configure.ac:

dnl We have to check these in C, not C++, because autoconf generates
dnl tests which have no type information, and current glibc provides
dnl multiple declarations of functions like basename when compiling
dnl with C++.
AC_CHECK_DECLS([basename, ffs, asprintf, vasprintf, snprintf, vsnprintf, strverscmp])

These checks IIUC intend to generate all the HAVE_DECL_FOO symbols
that libiberty.h and ansidecl.h check.

GDB is missing these checks currently, which results in the conflict
shown above.

This adds an m4 file that both GDB and GDBserver's configury use to
pull in the autoconf checks that libiberty clients needs done in order
to use these libiberty.h/ansidecl.h.

gdb/ChangeLog:
2015-02-27 Pedro Alves <palves@redhat.com>

* libiberty.m4: New file.
* acinclude.m4: Include libiberty.m4.
* configure.ac: Call libiberty_INIT.
* config.in, configure: Regenerate.

gdb/gdbserver/
2015-02-27 Pedro Alves <palves@redhat.com>

* acinclude.m4: Include libiberty.m4.
* configure.ac: Call libiberty_INIT.
* config.in, configure: Regenerate.
---
gdb/ChangeLog | 7 +
gdb/gdbserver/ChangeLog | 6 +
gdb/acinclude.m4 | 3 +
gdb/config.in | 45 ++++++
gdb/configure | 269 +++++++++++++++++++++++++++--------
gdb/configure.ac | 2 +
gdb/gdbserver/acinclude.m4 | 3 +
gdb/gdbserver/config.in | 41 ++++++
gdb/gdbserver/configure | 339 +++++++++++++++++++++++++++++++++++++++++++++
gdb/gdbserver/configure.ac | 2 +
gdb/libiberty.m4 | 31 +++++
11 files changed, 694 insertions(+), 54 deletions(-)
create mode 100644 gdb/libiberty.m4

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 7d3b1ce..dfaad27 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,10 @@
+2015-02-27 Pedro Alves <palves@redhat.com>
+
+ * libiberty.m4: New file.
+ * acinclude.m4: Include libiberty.m4.
+ * configure.ac: Call libiberty_INIT.
+ * config.in, configure: Regenerate.
+
2015-02-27 Andreas Arnez <arnez@linux.vnet.ibm.com>

* s390-linux-tdep.c (s390_gcc_target_options): Not just handle
diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog
index 6bb8950..28b582f 100644
--- a/gdb/gdbserver/ChangeLog
+++ b/gdb/gdbserver/ChangeLog
@@ -1,3 +1,9 @@
+2015-02-27 Pedro Alves <palves@redhat.com>
+
+ * acinclude.m4: Include libiberty.m4.
+ * configure.ac: Call libiberty_INIT.
+ * config.in, configure: Regenerate.
+
2015-02-26 Pedro Alves <palves@redhat.com>

* linux-low.c (linux_wait_1): When incrementing the PC past a
diff --git a/gdb/acinclude.m4 b/gdb/acinclude.m4
index 1f0b574..0ad90e7 100644
--- a/gdb/acinclude.m4
+++ b/gdb/acinclude.m4
@@ -57,6 +57,9 @@ sinclude([../config/zlib.m4])

m4_include([common/common.m4])

+dnl For libiberty_INIT.
+m4_include(libiberty.m4)
+
## ----------------------------------------- ##
## ANSIfy the C compiler whenever possible. ##
## From Franc,ois Pinard ##
diff --git a/gdb/config.in b/gdb/config.in
index 806cbac..4aaadb5 100644
--- a/gdb/config.in
+++ b/gdb/config.in
@@ -85,6 +85,17 @@
you don't. */
#undef HAVE_DECL_ADDR_NO_RANDOMIZE

+/* Define to 1 if you have the declaration of `asprintf', and to 0 if you
+ don't. */
+#undef HAVE_DECL_ASPRINTF
+
+/* Define to 1 if you have the declaration of `basename(char *)', and to 0 if
+ you don't. */
+#undef HAVE_DECL_BASENAME
+
+/* Define to 1 if you have the declaration of `ffs', and to 0 if you don't. */
+#undef HAVE_DECL_FFS
+
/* Define to 1 if you have the declaration of `free', and to 0 if you don't.
*/
#undef HAVE_DECL_FREE
@@ -117,6 +128,34 @@
*/
#undef HAVE_DECL_STRSTR

+/* Define to 1 if you have the declaration of `strtol', and to 0 if you don't.
+ */
+#undef HAVE_DECL_STRTOL
+
+/* Define to 1 if you have the declaration of `strtoll', and to 0 if you
+ don't. */
+#undef HAVE_DECL_STRTOLL
+
+/* Define to 1 if you have the declaration of `strtoul', and to 0 if you
+ don't. */
+#undef HAVE_DECL_STRTOUL
+
+/* Define to 1 if you have the declaration of `strtoull', and to 0 if you
+ don't. */
+#undef HAVE_DECL_STRTOULL
+
+/* Define to 1 if you have the declaration of `strverscmp', and to 0 if you
+ don't. */
+#undef HAVE_DECL_STRVERSCMP
+
+/* Define to 1 if you have the declaration of `vasprintf', and to 0 if you
+ don't. */
+#undef HAVE_DECL_VASPRINTF
+
+/* Define to 1 if you have the declaration of `vsnprintf', and to 0 if you
+ don't. */
+#undef HAVE_DECL_VSNPRINTF
+
/* Define to 1 if you have the <dlfcn.h> header file. */
#undef HAVE_DLFCN_H

@@ -225,6 +264,9 @@
/* Define to 1 if the compiler supports long double. */
#undef HAVE_LONG_DOUBLE

+/* Define to 1 if the system has the type `long long'. */
+#undef HAVE_LONG_LONG
+
/* Define if <sys/procfs.h> has lwpid_t. */
#undef HAVE_LWPID_T

@@ -635,6 +677,9 @@
/* The size of `long', as computed by sizeof. */
#undef SIZEOF_LONG

+/* The size of `long long', as computed by sizeof. */
+#undef SIZEOF_LONG_LONG
+
/* The size of `unsigned long', as computed by sizeof. */
#undef SIZEOF_UNSIGNED_LONG

diff --git a/gdb/gdbserver/acinclude.m4 b/gdb/gdbserver/acinclude.m4
index 744871a..e5f4b76 100644
--- a/gdb/gdbserver/acinclude.m4
+++ b/gdb/gdbserver/acinclude.m4
@@ -20,6 +20,9 @@ dnl anything else in gdbserver.
m4_include(../../config/codeset.m4)
m4_include(../common/common.m4)

+dnl For libiberty_INIT.
+m4_include(../libiberty.m4)
+
dnl Check for existence of a type $1 in libthread_db.h
dnl Based on BFD_HAVE_SYS_PROCFS_TYPE in bfd/bfd.m4.

diff --git a/gdb/gdbserver/config.in b/gdb/gdbserver/config.in
index 8f68ed2..8114628 100644
--- a/gdb/gdbserver/config.in
+++ b/gdb/gdbserver/config.in
@@ -22,10 +22,25 @@
you don't. */
#undef HAVE_DECL_ADDR_NO_RANDOMIZE

+/* Define to 1 if you have the declaration of `asprintf', and to 0 if you
+ don't. */
+#undef HAVE_DECL_ASPRINTF
+
+/* Define to 1 if you have the declaration of `basename(char *)', and to 0 if
+ you don't. */
+#undef HAVE_DECL_BASENAME
+
+/* Define to 1 if you have the declaration of `ffs', and to 0 if you don't. */
+#undef HAVE_DECL_FFS
+
/* Define to 1 if you have the declaration of `perror', and to 0 if you don't.
*/
#undef HAVE_DECL_PERROR

+/* Define to 1 if you have the declaration of `snprintf', and to 0 if you
+ don't. */
+#undef HAVE_DECL_SNPRINTF
+
/* Define to 1 if you have the declaration of `strerror', and to 0 if you
don't. */
#undef HAVE_DECL_STRERROR
@@ -34,6 +49,26 @@
*/
#undef HAVE_DECL_STRSTR

+/* Define to 1 if you have the declaration of `strtol', and to 0 if you don't.
+ */
+#undef HAVE_DECL_STRTOL
+
+/* Define to 1 if you have the declaration of `strtoll', and to 0 if you
+ don't. */
+#undef HAVE_DECL_STRTOLL
+
+/* Define to 1 if you have the declaration of `strtoul', and to 0 if you
+ don't. */
+#undef HAVE_DECL_STRTOUL
+
+/* Define to 1 if you have the declaration of `strtoull', and to 0 if you
+ don't. */
+#undef HAVE_DECL_STRTOULL
+
+/* Define to 1 if you have the declaration of `strverscmp', and to 0 if you
+ don't. */
+#undef HAVE_DECL_STRVERSCMP
+
/* Define to 1 if you have the declaration of `vasprintf', and to 0 if you
don't. */
#undef HAVE_DECL_VASPRINTF
@@ -96,6 +131,9 @@
/* Define to 1 if you have the <locale.h> header file. */
#undef HAVE_LOCALE_H

+/* Define to 1 if the system has the type `long long'. */
+#undef HAVE_LONG_LONG
+
/* Define if <thread_db.h> has lwpid_t. */
#undef HAVE_LWPID_T

@@ -253,6 +291,9 @@
/* Bug reporting address */
#undef REPORT_BUGS_TO

+/* The size of `long long', as computed by sizeof. */
+#undef SIZEOF_LONG_LONG
+
/* If using the C implementation of alloca, define if you know the
direction of stack growth for your system; otherwise it will be
automatically deduced at runtime.

diff --git a/gdb/gdbserver/configure.ac b/gdb/gdbserver/configure.ac
index f883adc..60636f7 100644
--- a/gdb/gdbserver/configure.ac
+++ b/gdb/gdbserver/configure.ac
@@ -193,6 +193,8 @@ LIBS="$LIBS -ldl"
AC_CHECK_FUNCS(dladdr)
LIBS="$old_LIBS"

+libiberty_INIT
+
AC_CHECK_DECLS([strerror, perror, vasprintf, vsnprintf])

AC_CHECK_TYPES(socklen_t, [], [],
diff --git a/gdb/libiberty.m4 b/gdb/libiberty.m4
new file mode 100644
index 0000000..5655e07
--- /dev/null
+++ b/gdb/libiberty.m4
@@ -0,0 +1,31 @@
+dnl Bits libiberty clients must do on their autoconf step.
+dnl
+dnl Copyright (C) 2012-2015 Free Software Foundation, Inc.
+dnl
+dnl This file is free software; you can redistribute it and/or modify
+dnl it under the terms of the GNU General Public License as published by
+dnl the Free Software Foundation; either version 3 of the License, or
+dnl (at your option) any later version.
+dnl
+dnl This program is distributed in the hope that it will be useful,
+dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
+dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+dnl GNU General Public License for more details.
+dnl
+dnl You should have received a copy of the GNU General Public License
+dnl along with this program; see the file COPYING3. If not see
+dnl <http://www.gnu.org/licenses/>.
+dnl
+
+dnl Checks for declarations ansidecl.h and libiberty.h themselves
+dnl check with HAVE_DECL_XXX, etc.
+
+AC_DEFUN([libiberty_INIT],
+[
+ # Check for presence and size of long long.
+ AC_CHECK_TYPES([long long], [AC_CHECK_SIZEOF(long long)])
+
+ AC_CHECK_DECLS([basename(char *), ffs, asprintf, vasprintf, snprintf, vsnprintf])
+ AC_CHECK_DECLS([strtol, strtoul, strtoll, strtoull])
+ AC_CHECK_DECLS([strverscmp])
+])
--
1.9.3