From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id QYaADiki92r/0AgAWB0awg (envelope-from ) for ; Fri, 13 Nov 2026 09:43:53 -0500 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=pRbukwTG; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=w9oy/DKB; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=pRbukwTG; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=w9oy/DKB; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 2E19D1E087; Fri, 13 Nov 2026 09:43:53 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 07B291E087 for ; Fri, 13 Nov 2026 09:43:52 -0500 (EST) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 21CC74BC054C for ; Fri, 13 Nov 2026 14:43:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 21CC74BC054C Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=pRbukwTG; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=w9oy/DKB; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=pRbukwTG; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=w9oy/DKB Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by sourceware.org (Postfix) with ESMTPS id 0EDDE4B92088 for ; Fri, 13 Nov 2026 14:41:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0EDDE4B92088 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0EDDE4B92088 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1794580882; cv=none; b=WdK3U6FyRMWlPErntuFL/dlmt8+cHWqdYpvLEVJHIcP7n4inW1IhQJ/E7aijnqnr0gzBEOf3VKOiNXPoWTXWS95iR7NjRh84voEQvbckOaBharqABruABtWQKNCiFKcIZsng8coAIs0khaKPNGvt+0UyNozJIaGaC1S9OQMjID8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1794580882; c=relaxed/simple; bh=2toX3uRsZkokNoNjslDFVOkFawCeCi3XZsJ7VfgpO9w=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-ID:MIME-Version; b=sV7PSv/K1FuVGcHj9hY0kAUsXIs7Y9QA+IrlI11oHyxkaeeHwvADLzk55huL6PHdOakDecaeP/6CWKlPsZGPQdetp0pqrX+hVwLZ5GOECraSeYK+DdUse7J5/PupDwiherrAhiB7oOXgYg+sqRHJAyFOBfXr6ld8EGRBrkUPo/s= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=pRbukwTG; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=w9oy/DKB; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=pRbukwTG; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=w9oy/DKB DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0EDDE4B92088 Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 21B4D21F55 for ; Fri, 13 Nov 2026 14:41:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1794580881; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XSzJ9tuMd8qK0JrwS68P2cVoN0p9KWLYArdb/m00+vM=; b=pRbukwTGvQ5dMR3JpSzSbFHt/xQuaSBsv9PHmJAJhkaZoWzNQXPTHPr2nsZZUq3bc6AX6t hOVjP45IWoOQ6MwLGpt5xUukl7Q9wPVflrUdCs+BWNdxU6lOzlxQ61/UQ9NGakGbK9fPQs ZohtaWOLSBVqm8/zX28rh0qVcZTZZ8c= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1794580881; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XSzJ9tuMd8qK0JrwS68P2cVoN0p9KWLYArdb/m00+vM=; b=w9oy/DKBxk06UvdkVdp9Da8JuRHbOIlA6kfdLzhWPXb/d72Rn7bcwiKX93JCGppdXJd9F6 lFZsnbxHBx6+2fCA== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1794580881; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XSzJ9tuMd8qK0JrwS68P2cVoN0p9KWLYArdb/m00+vM=; b=pRbukwTGvQ5dMR3JpSzSbFHt/xQuaSBsv9PHmJAJhkaZoWzNQXPTHPr2nsZZUq3bc6AX6t hOVjP45IWoOQ6MwLGpt5xUukl7Q9wPVflrUdCs+BWNdxU6lOzlxQ61/UQ9NGakGbK9fPQs ZohtaWOLSBVqm8/zX28rh0qVcZTZZ8c= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1794580881; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XSzJ9tuMd8qK0JrwS68P2cVoN0p9KWLYArdb/m00+vM=; b=w9oy/DKBxk06UvdkVdp9Da8JuRHbOIlA6kfdLzhWPXb/d72Rn7bcwiKX93JCGppdXJd9F6 lFZsnbxHBx6+2fCA== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id DF1A113511 for ; Fri, 13 Nov 2026 14:41:20 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id gsLWFpAh92r6BwAAD6G6ig:T3 (envelope-from ) for ; Fri, 13 Nov 2026 14:41:20 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH v2 2/2] [gdb/build] Use gnulib fnmatch Date: Fri, 13 Nov 2026 15:41:19 +0100 Message-ID: <20261113144119.47839-3-tdevries@suse.de> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20261113144119.47839-1-tdevries@suse.de> References: <20261113144119.47839-1-tdevries@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spamd-Result: default: False [-11.80 / 50.00]; SUSE_INTERNAL_BYPASS(-9.00)[]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-0.999]; MIME_GOOD(-0.10)[text/plain]; RCPT_COUNT_ONE(0.00)[1]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DBL_BLOCKED_OPENRESOLVER(0.00)[sourceware.org:url,imap1.dmz-prg2.suse.org:helo,gnu.org:url]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; RCVD_TLS_ALL(0.00)[] X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org I built gdb on aarch64-macos, ran the skip_gfile_matching selftest and got: ... (gdb) maint selftest -v skip_gfile_matching ... Pattern (*[[:digit:]]*.h) Filename (xx1xx.h) Fullname (/tmp/xx1xx.h) Regexp (/[^/]*[[:digit:]][^/]*\.h$) Matched: No [Expected: Yes] ... Failed: 5 Self test failed: self-test failed at gdb/skip.c:1820 Failures: skip_gfile_matching Ran 1 unit tests, 1 failed ... Disabling this piece of code in do_skip_gfile_p using gdb_filename_fnmatch: ... /* If basenames don't match then the full pattern cannot match. The gdb_filename_fnmatch already handles case insensitive filesystems, and as we're only checking the basenames here, directory separators are not a problem. */ if (!basenames_may_differ && gdb_filename_fnmatch (lbasename (pattern.c_str ()), lbasename (get_filename ()), FNM_FILE_NAME | FNM_NOESCAPE) != 0) return false; ... makes the selftest pass. The failure reduces to this minimal reproducer: ... const char *pattern = "[[:digit:]]"; const char *string = "1"; int flags = FNM_FILE_NAME | FNM_NOESCAPE; int res = fnmatch (pattern, string, flags); gdb_assert (res == 0); ... and the root cause is that we use libiberty's fnmatch, which is rather old (based on some glibc v1 version). This happens as follows: - because system libc is not glibc, the !__GNU_LIBRARY__ test in libiberty/fnmatch.c succeeds and fnmatch.o contains an fnmatch function - because system libc is not glibc, gnulib also compiles an fnmatch function - because of the inclusion order in INTERNAL_CFLAGS of libiberty vs gnulib, the libiberty copy gets used For contrast, on x86_64-linux: - because system libc is glibc, the !__GNU_LIBRARY__ test in libiberty/fnmatch.c fails and fnmatch.o is empty - because system libc is glibc, gnulib doesn't compile an fnmatch function - fnmatch binds to fnmatch from the system glibc Fix this by changing the inclusion order in INTERNAL_CFLAGS. More concretely, by: - factoring out GNULIB_LIBIBERTY_CFLAGS, - using GNULIB_LIBIBERTY_CFLAGS in INTERNAL_CFLAGS instead of INCGNU and INCLUDE_CFLAGS, and - adding an extensive comment at GNULIB_LIBIBERTY_CFLAGS to explain why inclusion order matters. Likewise in gdbserver and gdbsupport dirs. Tested on aarch64-macos by rebuilding and running the selftests. Tested on x86_64-linux. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34877 --- gdb/Makefile.in | 56 ++++++++++++++++++++++++++++++++++++++++-- gdbserver/Makefile.in | 8 ++++-- gdbsupport/Makefile.am | 10 +++++--- gdbsupport/Makefile.in | 10 +++++--- 4 files changed, 74 insertions(+), 10 deletions(-) diff --git a/gdb/Makefile.in b/gdb/Makefile.in index 41dbb814787..55c4d012f25 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -157,6 +157,59 @@ CC_LD = $(LIBTOOL) $(SILENT_FLAG) --mode=link $(CXX) $(CXX_DIALECT) INCLUDE_DIR = $(srcdir)/../include INCLUDE_CFLAGS = -I$(INCLUDE_DIR) +# GDB uses GNU libiberty and Gnulib. Both are part portability, part utility +# libraries. Both are maintained externally, and we have in-repo copies. +# +# Libiberty is a "decommissioned GNU package". OTOH, libiberty is maintained +# as part of GCC, and so at least the parts that GCC relies on are maintained. +# For functionality provided by both Gnulib and libiberty, we prefer the +# Gnulib one because it's actively maintained as a whole. +# +# While for Gnulib we have a means to selectively import only the part that we +# want (gnulib/update-gnulib.sh), libiberty is imported as a whole. +# Consequently we can end up with conflicting files, making inclusion +# order the determining factor for which one we use. So reflecting the +# preference mentioned above, we include Gnulib before libiberty. +# +# As a running example, consider fnmatch. +# +# On a macOS system: +# - libiberty provides: +# - include/fnmatch.h +# - build/libiberty/fnmatch.o containing a definition for fnmatch +# - Gnulib provides: +# - build/gnulib/import/fnmatch.h, mapping fnmatch to rpl_fnmatch +# - build/gnulib/import/fnmatch.o containing a definition for rpl_fnmatch +# Depending on which fnmatch.h gets picked, GDB gets either the libiberty or +# the Gnulib version. Note that in this case at least, linking order doesn't +# matter. Also note that even when GDB uses Gnulib's fnmatch, other +# components may still use libiberty's. +# +# For contrast, let's also consider fnmatch on a Linux system with glibc: +# - libiberty provides: +# - include/fnmatch.h +# - build/libiberty/fnmatch.o containing no definitions +# - Gnulib provides nothing fnmatch related +# In this case, the fnmatch.h from libiberty is used, but at link time glibc's +# version is used, which is not ideal. +# +# So while enforcing inclusion order works, IWBN to have a better solution. +# +# Some alternatives avoiding libiberty's fnmatch are: +# - selective importing of libiberty, like we have for Gnulib. +# - updating the external libiberty (maintained in GCC) to drop fnmatch. The +# first step for this would be for GCC to stop using libiberty's fnmatch, +# which was once proposed as part of an effort to start using Gnulib in +# GCC [1], but this effort stalled. +# [1] https://gcc.gnu.org/wiki/replacelibibertywithgnulib +# Both of these would have to take into consideration other in-repo components +# using libiberty. +# +# We could also update the external libiberty to include a more modern copy of +# fnmatch. But the question is whether it's a good use of effort to maintain a +# decommissioned library if a better alternative is already available. +GNULIB_LIBIBERTY_CFLAGS = $(INCGNU) $(INCLUDE_CFLAGS) + # Where is the "-liberty" library? Typically in ../libiberty. LIBIBERTY = ../libiberty/libiberty.a @@ -636,13 +689,12 @@ INTERNAL_CFLAGS = \ $(GDB_CFLAGS) \ $(OPCODES_CFLAGS) \ $(BFD_CFLAGS) \ - $(INCLUDE_CFLAGS) \ + $(GNULIB_LIBIBERTY_CFLAGS) \ $(READLINE_CFLAGS) \ $(ZLIBINC) \ $(ZSTD_CFLAGS) \ $(LIBDECNUMBER_CFLAGS) \ $(INTL_CFLAGS) \ - $(INCGNU) \ $(INCSUPPORT) \ $(LIBBACKTRACE_INC) \ $(ENABLE_CFLAGS) \ diff --git a/gdbserver/Makefile.in b/gdbserver/Makefile.in index aac8742a923..e489af1f410 100644 --- a/gdbserver/Makefile.in +++ b/gdbserver/Makefile.in @@ -118,6 +118,11 @@ INCSUPPORT = \ -I$(srcdir)/.. \ -I.. +# See gdb/Makefile.in. +GNULIB_LIBIBERTY_CFLAGS = \ + $(INCGNU) \ + -I$(INCLUDE_DIR) + # All the includes used for CFLAGS and for lint. # -I. for config files. # -I${srcdir} for our headers. @@ -132,9 +137,8 @@ INCLUDE_CFLAGS = \ -I${srcdir} \ -I$(srcdir)/../gdb/regformats \ -I$(srcdir)/.. \ - -I$(INCLUDE_DIR) \ + $(GNULIB_LIBIBERTY_CFLAGS) \ -I$(srcdir)/../gdb \ - $(INCGNU) \ $(INCSUPPORT) \ $(INTL_CFLAGS) diff --git a/gdbsupport/Makefile.am b/gdbsupport/Makefile.am index 01a623b1be0..c895e0ecaca 100644 --- a/gdbsupport/Makefile.am +++ b/gdbsupport/Makefile.am @@ -20,16 +20,20 @@ AUTOMAKE_OPTIONS = no-dist foreign ACLOCAL_AMFLAGS = -I . -I ../config +# See gdb/Makefile.in. +GNULIB_LIBIBERTY_CFLAGS = \ + -I$(srcdir)/../gnulib/import \ + -I../gnulib/import \ + -I$(srcdir)/../include + # Suppress 'configure.ac: error: AM_GNU_GETTEXT used but SUBDIRS not defined' # from Automake, as gdbsupport uses AM_GNU_GETTEXT through # ZW_GNU_GETTEXT_SISTER_DIR, but doesn't have any translations (currently). SUBDIRS = AM_CPPFLAGS = \ - -I$(srcdir)/../include \ -I$(srcdir)/../gdb \ - -I$(srcdir)/../gnulib/import \ - -I../gnulib/import \ + $(GNULIB_LIBIBERTY_CFLAGS) \ -I.. \ -I$(srcdir)/.. \ $(INCINTL) \ diff --git a/gdbsupport/Makefile.in b/gdbsupport/Makefile.in index c3be0660336..c05ce5fc494 100644 --- a/gdbsupport/Makefile.in +++ b/gdbsupport/Makefile.in @@ -389,15 +389,19 @@ top_srcdir = @top_srcdir@ AUTOMAKE_OPTIONS = no-dist foreign ACLOCAL_AMFLAGS = -I . -I ../config +# See gdb/Makefile.in. +GNULIB_LIBIBERTY_CFLAGS = \ + -I$(srcdir)/../gnulib/import \ + -I../gnulib/import \ + -I$(srcdir)/../include + # Suppress 'configure.ac: error: AM_GNU_GETTEXT used but SUBDIRS not defined' # from Automake, as gdbsupport uses AM_GNU_GETTEXT through # ZW_GNU_GETTEXT_SISTER_DIR, but doesn't have any translations (currently). SUBDIRS = AM_CPPFLAGS = \ - -I$(srcdir)/../include \ -I$(srcdir)/../gdb \ - -I$(srcdir)/../gnulib/import \ - -I../gnulib/import \ + $(GNULIB_LIBIBERTY_CFLAGS) \ -I.. \ -I$(srcdir)/.. \ $(INCINTL) \ -- 2.51.0