From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH] [gdb/build] Use gnulib fnmatch
Date: Mon, 9 Nov 2026 20:26:55 +0100 [thread overview]
Message-ID: <20261109192655.32551-1-tdevries@suse.de> (raw)
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
next reply other threads:[~2026-11-09 19:27 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-09 19:26 Tom de Vries [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261109192655.32551-1-tdevries@suse.de \
--to=tdevries@suse.de \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox