From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id 45EAD3846078 for ; Tue, 6 Apr 2021 13:16:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 45EAD3846078 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tdevries@suse.de X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 5B17EB1EC for ; Tue, 6 Apr 2021 13:16:48 +0000 (UTC) Date: Tue, 6 Apr 2021 15:16:46 +0200 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH][gdb/build] Workaround pcre2_posix linking problem Message-ID: <20210406131645.GA1220@delia> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 06 Apr 2021 13:16:52 -0000 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 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(-) 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