Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] [gdb/build] Use gnulib fnmatch
@ 2026-11-09 19:26 Tom de Vries
  2026-11-12 22:53 ` Thiago Jung Bauermann
  0 siblings, 1 reply; 6+ messages in thread
From: Tom de Vries @ 2026-11-09 19:26 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.

Tested on aarch64-macos by rebuilding and running the selftests.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34877
---
 gdb/Makefile.in | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index 41dbb814787..3752939feca 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -630,19 +630,21 @@ INTERNAL_CPPFLAGS = $(CPPFLAGS) @GUILE_CPPFLAGS@ @PYTHON_CPPFLAGS@ \
 	@LARGEFILE_CPPFLAGS@
 
 # INTERNAL_CFLAGS is the aggregate of all other *CFLAGS macros.
+# Order INCGNU before INCLUDE_CFLAGS to prefer gnulib's fnmatch to
+# libiberty's.
 INTERNAL_CFLAGS = \
 	$(GLOBAL_CFLAGS) \
 	$(PROFILE_CFLAGS) \
 	$(GDB_CFLAGS) \
 	$(OPCODES_CFLAGS) \
 	$(BFD_CFLAGS) \
+	$(INCGNU) \
 	$(INCLUDE_CFLAGS) \
 	$(READLINE_CFLAGS) \
 	$(ZLIBINC) \
 	$(ZSTD_CFLAGS) \
 	$(LIBDECNUMBER_CFLAGS) \
 	$(INTL_CFLAGS) \
-	$(INCGNU) \
 	$(INCSUPPORT) \
 	$(LIBBACKTRACE_INC) \
 	$(ENABLE_CFLAGS) \

base-commit: 3512193901c2ee73f74c004d5bbb8e0022f3418a
-- 
2.51.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-11-19 20:41 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-09 19:26 [PATCH] [gdb/build] Use gnulib fnmatch Tom de Vries
2026-11-12 22:53 ` Thiago Jung Bauermann
2026-11-13 14:52   ` Tom de Vries
2026-11-13 18:16     ` Tom Tromey
2026-11-18 15:57       ` Tom de Vries
2026-11-19 20:39         ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox