* [PATCH v2 0/2] [gdb/build] Use gnulib fnmatch
@ 2026-11-13 14:41 Tom de Vries
2026-11-13 14:41 ` [PATCH v2 1/2] [gdbsupport] Use INCGNU order in AM_CPPFLAGS Tom de Vries
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Tom de Vries @ 2026-11-13 14:41 UTC (permalink / raw)
To: gdb-patches
This series contains two patches.
The first is a cosmetic cleanup to make the following patch more regular.
The second fixes PR build/34877.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34877
Changes in v2:
- add patch for gdbsupport to use same order as in INCGNU
- introduce GNULIB_LIBIBERTY_CFLAGS
- extend comment
- make similar changes in gdbsupport and gdbserver
versions:
- v1 https://sourceware.org/pipermail/gdb-patches/2026-November/231753.html
Tom de Vries (2):
[gdbsupport] Use INCGNU order in AM_CPPFLAGS
[gdb/build] Use gnulib fnmatch
gdb/Makefile.in | 56 ++++++++++++++++++++++++++++++++++++++++--
gdbserver/Makefile.in | 8 ++++--
gdbsupport/Makefile.am | 10 +++++---
gdbsupport/Makefile.in | 10 +++++---
4 files changed, 74 insertions(+), 10 deletions(-)
base-commit: 5a1c88b169767f282bd232d066b37a87df310555
--
2.51.0
^ permalink raw reply [flat|nested] 8+ messages in thread* [PATCH v2 1/2] [gdbsupport] Use INCGNU order in AM_CPPFLAGS 2026-11-13 14:41 [PATCH v2 0/2] [gdb/build] Use gnulib fnmatch Tom de Vries @ 2026-11-13 14:41 ` Tom de Vries 2026-11-13 19:09 ` Thiago Jung Bauermann 2026-11-13 14:41 ` [PATCH v2 2/2] [gdb/build] Use gnulib fnmatch Tom de Vries 2026-11-13 18:27 ` [PATCH v2 0/2] " Tom Tromey 2 siblings, 1 reply; 8+ messages in thread From: Tom de Vries @ 2026-11-13 14:41 UTC (permalink / raw) To: gdb-patches INCGNU from Makefile.gnulib.inc.in uses the gnulib include files from the gnulib sources and the gnulib build in this order: ... INCGNU = -I$(srcdir)/$(GNULIB_PARENT_DIR)/gnulib/import \ -I$(GNULIB_PARENT_DIR)/gnulib/import ... Gdb and gdbserver use INCGNU, but gdbsupport doesn't: ... AM_CPPFLAGS = \ ... -I../gnulib/import \ -I$(srcdir)/../gnulib/import \ ... ... and uses the opposite order. This shouldn't matter, but for consistency, use the same order. --- gdbsupport/Makefile.am | 2 +- gdbsupport/Makefile.in | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gdbsupport/Makefile.am b/gdbsupport/Makefile.am index 4a3d94c1caa..01a623b1be0 100644 --- a/gdbsupport/Makefile.am +++ b/gdbsupport/Makefile.am @@ -28,8 +28,8 @@ SUBDIRS = AM_CPPFLAGS = \ -I$(srcdir)/../include \ -I$(srcdir)/../gdb \ - -I../gnulib/import \ -I$(srcdir)/../gnulib/import \ + -I../gnulib/import \ -I.. \ -I$(srcdir)/.. \ $(INCINTL) \ diff --git a/gdbsupport/Makefile.in b/gdbsupport/Makefile.in index 2da8adcc7ac..c3be0660336 100644 --- a/gdbsupport/Makefile.in +++ b/gdbsupport/Makefile.in @@ -396,8 +396,8 @@ SUBDIRS = AM_CPPFLAGS = \ -I$(srcdir)/../include \ -I$(srcdir)/../gdb \ - -I../gnulib/import \ -I$(srcdir)/../gnulib/import \ + -I../gnulib/import \ -I.. \ -I$(srcdir)/.. \ $(INCINTL) \ -- 2.51.0 ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 1/2] [gdbsupport] Use INCGNU order in AM_CPPFLAGS 2026-11-13 14:41 ` [PATCH v2 1/2] [gdbsupport] Use INCGNU order in AM_CPPFLAGS Tom de Vries @ 2026-11-13 19:09 ` Thiago Jung Bauermann 0 siblings, 0 replies; 8+ messages in thread From: Thiago Jung Bauermann @ 2026-11-13 19:09 UTC (permalink / raw) To: Tom de Vries; +Cc: gdb-patches Tom de Vries <tdevries@suse.de> writes: > INCGNU from Makefile.gnulib.inc.in uses the gnulib include files from the > gnulib sources and the gnulib build in this order: > ... > INCGNU = -I$(srcdir)/$(GNULIB_PARENT_DIR)/gnulib/import \ > -I$(GNULIB_PARENT_DIR)/gnulib/import > ... > > Gdb and gdbserver use INCGNU, but gdbsupport doesn't: > ... > AM_CPPFLAGS = \ > ... > -I../gnulib/import \ > -I$(srcdir)/../gnulib/import \ > ... > ... > and uses the opposite order. > > This shouldn't matter, but for consistency, use the same order. > --- > gdbsupport/Makefile.am | 2 +- > gdbsupport/Makefile.in | 2 +- > 2 files changed, 2 insertions(+), 2 deletions(-) Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org> -- Thiago (he/him) ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2 2/2] [gdb/build] Use gnulib fnmatch 2026-11-13 14:41 [PATCH v2 0/2] [gdb/build] Use gnulib fnmatch Tom de Vries 2026-11-13 14:41 ` [PATCH v2 1/2] [gdbsupport] Use INCGNU order in AM_CPPFLAGS Tom de Vries @ 2026-11-13 14:41 ` Tom de Vries 2026-11-13 19:10 ` Thiago Jung Bauermann 2026-11-13 18:27 ` [PATCH v2 0/2] " Tom Tromey 2 siblings, 1 reply; 8+ messages in thread From: Tom de Vries @ 2026-11-13 14:41 UTC (permalink / raw) To: gdb-patches 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 ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 2/2] [gdb/build] Use gnulib fnmatch 2026-11-13 14:41 ` [PATCH v2 2/2] [gdb/build] Use gnulib fnmatch Tom de Vries @ 2026-11-13 19:10 ` Thiago Jung Bauermann 0 siblings, 0 replies; 8+ messages in thread From: Thiago Jung Bauermann @ 2026-11-13 19:10 UTC (permalink / raw) To: Tom de Vries; +Cc: gdb-patches Tom de Vries <tdevries@suse.de> writes: > 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(-) Thank you for your extra investigation and explanation on the v1 thread, and for the comment update. Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org> -- Thiago (he/him) ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 0/2] [gdb/build] Use gnulib fnmatch 2026-11-13 14:41 [PATCH v2 0/2] [gdb/build] Use gnulib fnmatch Tom de Vries 2026-11-13 14:41 ` [PATCH v2 1/2] [gdbsupport] Use INCGNU order in AM_CPPFLAGS Tom de Vries 2026-11-13 14:41 ` [PATCH v2 2/2] [gdb/build] Use gnulib fnmatch Tom de Vries @ 2026-11-13 18:27 ` Tom Tromey 2026-11-14 13:41 ` Tom de Vries 2 siblings, 1 reply; 8+ messages in thread From: Tom Tromey @ 2026-11-13 18:27 UTC (permalink / raw) To: Tom de Vries; +Cc: gdb-patches >>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes: Tom> This series contains two patches. Tom> The first is a cosmetic cleanup to make the following patch more regular. Tom> The second fixes PR build/34877. Tom> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34877 This kind of patch is scary because this area has historically been quite delicate. Did you try a mingw build? Sometimes that's more problematic than real unix-style hosts. Anyway I think it is probably ok. (Certainly patch #1 is ok.) Approved-By: Tom Tromey <tom@tromey.com> Tom ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 0/2] [gdb/build] Use gnulib fnmatch 2026-11-13 18:27 ` [PATCH v2 0/2] " Tom Tromey @ 2026-11-14 13:41 ` Tom de Vries 2026-11-16 13:51 ` Tom de Vries 0 siblings, 1 reply; 8+ messages in thread From: Tom de Vries @ 2026-11-14 13:41 UTC (permalink / raw) To: Tom Tromey; +Cc: gdb-patches On 11/13/26 7:27 PM, Tom Tromey wrote: >>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes: > > Tom> This series contains two patches. > Tom> The first is a cosmetic cleanup to make the following patch more regular. > > Tom> The second fixes PR build/34877. > > Tom> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34877 > Hi Tom, thanks for the review. > This kind of patch is scary because this area has historically been > quite delicate. > Yeah, I'm starting to realize that. > Did you try a mingw build? Sometimes that's more problematic than real > unix-style hosts. > I didn't, so thanks for that pointer. I investigated this, and found that on msys2-ucrt64, libiberty's fnmatch is used, so we get same error in the selftest. The problem is that gnulib doesn't use the rpl_ prefix that ensures that the gnulib version is linked. I'm preparing a patch for that. > Anyway I think it is probably ok. (Certainly patch #1 is ok.) > Thanks, I'll commit shortly. - Tom > Approved-By: Tom Tromey <tom@tromey.com> > > Tom ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 0/2] [gdb/build] Use gnulib fnmatch 2026-11-14 13:41 ` Tom de Vries @ 2026-11-16 13:51 ` Tom de Vries 0 siblings, 0 replies; 8+ messages in thread From: Tom de Vries @ 2026-11-16 13:51 UTC (permalink / raw) To: Tom Tromey; +Cc: gdb-patches On 11/14/26 2:41 PM, Tom de Vries wrote: >> Did you try a mingw build? Sometimes that's more problematic than real >> unix-style hosts. >> > > I didn't, so thanks for that pointer. I investigated this, and found > that on msys2-ucrt64, libiberty's fnmatch is used, so we get same error > in the selftest. > > The problem is that gnulib doesn't use the rpl_ prefix that ensures that > the gnulib version is linked. I'm preparing a patch for that. I've submitted it here ( https://sourceware.org/pipermail/gdb-patches/2026-November/231927.html ). Thanks, - Tom ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-11-16 13:52 UTC | newest] Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2026-11-13 14:41 [PATCH v2 0/2] [gdb/build] Use gnulib fnmatch Tom de Vries 2026-11-13 14:41 ` [PATCH v2 1/2] [gdbsupport] Use INCGNU order in AM_CPPFLAGS Tom de Vries 2026-11-13 19:09 ` Thiago Jung Bauermann 2026-11-13 14:41 ` [PATCH v2 2/2] [gdb/build] Use gnulib fnmatch Tom de Vries 2026-11-13 19:10 ` Thiago Jung Bauermann 2026-11-13 18:27 ` [PATCH v2 0/2] " Tom Tromey 2026-11-14 13:41 ` Tom de Vries 2026-11-16 13:51 ` Tom de Vries
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox