[gdb/build] Workaround pcre2_posix linking problem

Message ID 20210406131645.GA1220@delia
State New
Headers show
Series
  • [gdb/build] Workaround pcre2_posix linking problem
Related show

Commit Message

Tom de Vries April 6, 2021, 1:16 p.m.
Hi,

On openSUSE Tumbleweed, the ncurses package got the --with-pcre2 configure
switch enabled, and solved the resulting dependencies using:
...
 $ cat /usr/lib64/libncursesw.so
 /* GNU ld script */
-INPUT(/lib64/libncursesw.so.6 AS_NEEDED(-ltinfo -ldl))
+INPUT(/lib64/libncursesw.so.6 AS_NEEDED(-ltinfo -ldl -lpcre2-posix -lpcre2-8))
...

GDB uses the regexp functions regcomp, regerror, regfree, regexec and re_search, see
gdb_regex.c.  The latter is a GNU extension.

Due to the changes mentioned above, the first four functions got bound to
lpcre2-posix, while re_search still got bound to lc, resulting in all sorts of
trouble, like hangs or:
...
$ gdb -q -batch -ex "apropos apropos"
Aborted (core dumped)
...

There is a debate whether it's legal to use re_search in combination with regcomp.

Either way, the immediate problem can be fixed/worked-around by adding -lc
before @LIBS@ in the CLIBS def in Makefile.in.

This is something that works with clang++, though not with g++, which drops
-lc, see PR gcc/99896.  For g++, we can work around this by using -Wl,-lc
instead.

Add -lc before @LIBS@ in CLIBS def.

Tested on x86_64-linux.

Any comments?

Thanks,
- Tom

[gdb/build] Workaround pcre2_posix linking problem

gdb/ChangeLog:

2021-04-06  Tom de Vries  <tdevries@suse.de>

	PR build/27681
	* Makefile.in (CDEFS): Add @LIBC@ before @LIBS@.
	* configure.ac: Define LIBC.
	* configure: Regenerate.

---
 gdb/Makefile.in  |  5 +++--
 gdb/configure    | 11 +++++++++++
 gdb/configure.ac |  8 ++++++++
 3 files changed, 22 insertions(+), 2 deletions(-)

Patch

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index 3318c1a5215..8bcbd8ea620 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -631,11 +631,12 @@  INTERNAL_LDFLAGS = \
 
 # Libraries and corresponding dependencies for compiling gdb.
 # XM_CLIBS, defined in *config files, have host-dependent libs.
-# LIBIBERTY appears twice on purpose.
+# LIBIBERTY appears twice on purpose.  LIBC is added before
+# LIBS to ensure that all functions in gdb_regex.c bind to libc.
 CLIBS = $(SIM) $(READLINE) $(OPCODES) $(LIBCTF) $(BFD) $(ZLIB) \
         $(LIBSUPPORT) $(INTL) $(LIBIBERTY) $(LIBDECNUMBER) \
 	$(XM_CLIBS) $(GDBTKLIBS) \
-	@LIBS@ @GUILE_LIBS@ @PYTHON_LIBS@ \
+	@LIBC@ @LIBS@ @GUILE_LIBS@ @PYTHON_LIBS@ \
 	$(LIBEXPAT) $(LIBLZMA) $(LIBBABELTRACE) $(LIBIPT) \
 	$(WIN32LIBS) $(LIBGNU) $(LIBGNU_EXTRA_LIBS) $(LIBICONV) \
 	$(LIBMPFR) $(LIBGMP) $(SRCHIGH_LIBS) $(LIBXXHASH) $(PTHREAD_LIBS) \
diff --git a/gdb/configure b/gdb/configure
index 4c80350596c..62f852a8ec1 100755
--- a/gdb/configure
+++ b/gdb/configure
@@ -728,6 +728,7 @@  HAVE_PYTHON_TRUE
 PYTHON_LIBS
 PYTHON_CPPFLAGS
 PYTHON_CFLAGS
+LIBC
 python_prog_path
 LTLIBMPFR
 LIBMPFR
@@ -11350,6 +11351,16 @@  _ACEOF
   fi
 fi
 
+if test "${GCC}" = yes; then
+  # G++ drops -lc, so wrap it using -Wl.  See PR gcc/99896.
+  GCC_LIBC="-Wl,-lc"
+  LIBC=$GCC_LIBC
+
+else
+  LIBC=-lc
+
+fi
+
 
 # Check whether --with-python-libdir was given.
 if test "${with_python_libdir+set}" = set; then :
diff --git a/gdb/configure.ac b/gdb/configure.ac
index 7035014484e..282bdd7fb74 100644
--- a/gdb/configure.ac
+++ b/gdb/configure.ac
@@ -927,6 +927,14 @@  else
   fi
 fi
 
+if test "${GCC}" = yes; then
+  # G++ drops -lc, so wrap it using -Wl.  See PR gcc/99896.
+  GCC_LIBC="-Wl,-lc"
+  AC_SUBST(LIBC, $GCC_LIBC)
+else
+  AC_SUBST(LIBC, -lc)
+fi
+
 dnl Use --with-python-libdir to control where GDB looks for the Python
 dnl libraries.
 dnl