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

* Re: [PATCH] [gdb/build] Use gnulib fnmatch
  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
  0 siblings, 1 reply; 6+ messages in thread
From: Thiago Jung Bauermann @ 2026-11-12 22:53 UTC (permalink / raw)
  To: Tom de Vries; +Cc: gdb-patches

Hello Tom,

Tom de Vries <tdevries@suse.de> writes:

> 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.

This is somewhat subtle. Can it be fixed instead by removing
libiberty/fnmatch.c from the repo?

-- 
Thiago
(he/him)

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

* Re: [PATCH] [gdb/build] Use gnulib fnmatch
  2026-11-12 22:53 ` Thiago Jung Bauermann
@ 2026-11-13 14:52   ` Tom de Vries
  2026-11-13 18:16     ` Tom Tromey
  0 siblings, 1 reply; 6+ messages in thread
From: Tom de Vries @ 2026-11-13 14:52 UTC (permalink / raw)
  To: Thiago Jung Bauermann; +Cc: gdb-patches

On 11/12/26 11:53 PM, Thiago Jung Bauermann wrote:
> Hello Tom,
> 
> Tom de Vries <tdevries@suse.de> writes:
> 
>> 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.
> 
> This is somewhat subtle. Can it be fixed instead by removing
> libiberty/fnmatch.c from the repo?
> 

Hi Thiago,

thanks for the review.

That's a good question.  I've looked into this a bit.  I think this is 
the solution we want eventually, but for that to happen we need to 
update gcc to no longer use it (and start using gnulib), as well as 
other components in our repo which use the libiberty version instead of 
gnulib.  So that's quite a project.

I've updated the patch with a large comment explaining why the inclusion 
order is relevant, also discussing the alternative you mention here ( 
https://sourceware.org/pipermail/gdb-patches/2026-November/231883.html ).

Thanks,
- Tom

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

* Re: [PATCH] [gdb/build] Use gnulib fnmatch
  2026-11-13 14:52   ` Tom de Vries
@ 2026-11-13 18:16     ` Tom Tromey
  2026-11-18 15:57       ` Tom de Vries
  0 siblings, 1 reply; 6+ messages in thread
From: Tom Tromey @ 2026-11-13 18:16 UTC (permalink / raw)
  To: Tom de Vries; +Cc: Thiago Jung Bauermann, gdb-patches

>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:

Tom> That's a good question.  I've looked into this a bit.  I think this is
Tom> the solution we want eventually, but for that to happen we need to
Tom> update gcc to no longer use it (and start using gnulib), as well as
Tom> other components in our repo which use the libiberty version instead
Tom> of gnulib.  So that's quite a project.

Sharing gnulib would be very difficult, much worse even than you might
think :(

The main issue is that gdb is extremely sensitive to exactly which
gnulib modules are used.  I don't recall the details any more, but there
are some modules that cannot be imported, and if they are, things break.

Also, maybe worth noting that it's also very difficult to update gnulib.
I failed the last time I tried.

gnulib is painful enough that I've often thought we should remove it
again.

Though I have to say this current bug makes me second-guess my wish.  I
mean, on the one hand this self-test is maybe invalid or non-portable;
but OTOH shouldn't fnmatch work more nicely than libiberty's, since it's
exposed to the user?

But maybe another way to go, assuming gnulib removal is on the table,
would be to ensure that libiberty uses the macOS fnmatch and not the
replacement.

Tom

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

* Re: [PATCH] [gdb/build] Use gnulib fnmatch
  2026-11-13 18:16     ` Tom Tromey
@ 2026-11-18 15:57       ` Tom de Vries
  2026-11-19 20:39         ` Tom Tromey
  0 siblings, 1 reply; 6+ messages in thread
From: Tom de Vries @ 2026-11-18 15:57 UTC (permalink / raw)
  To: Tom Tromey; +Cc: Thiago Jung Bauermann, gdb-patches

On 11/13/26 7:16 PM, Tom Tromey wrote:
>>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:
> 
> Tom> That's a good question.  I've looked into this a bit.  I think this is
> Tom> the solution we want eventually, but for that to happen we need to
> Tom> update gcc to no longer use it (and start using gnulib), as well as
> Tom> other components in our repo which use the libiberty version instead
> Tom> of gnulib.  So that's quite a project.
> 
> Sharing gnulib would be very difficult, much worse even than you might
> think :(
> 

Hi Tom,

thanks for weighing in here.

> The main issue is that gdb is extremely sensitive to exactly which
> gnulib modules are used.  I don't recall the details any more, but there
> are some modules that cannot be imported, and if they are, things break.
> 
> Also, maybe worth noting that it's also very difficult to update gnulib.
> I failed the last time I tried.
> 

I've given updating a try.  I've filed a PR ( 
https://sourceware.org/bugzilla/show_bug.cgi?id=35004 ) and submitted a 
series ( 
https://sourceware.org/git/?p=binutils-gdb.git;a=shortlog;h=refs/heads/users/vries/try-gnulib-stable-202607 
, https://sourceware.org/pipermail/gdb-patches/2026-November/231948.html ).

I took a slightly different approach by using a stable branch rather 
than importing from trunk.

The thing I encountered that sounds most like the problem you describe 
above, is the pthread.h thing.

> gnulib is painful enough that I've often thought we should remove it
> again.
> 

I've filed a PR to discuss the merits of libiberty vs gnulib vs both ( 
https://sourceware.org/bugzilla/show_bug.cgi?id=35017 ).

> Though I have to say this current bug makes me second-guess my wish.  I
> mean, on the one hand this self-test is maybe invalid or non-portable;
> but OTOH shouldn't fnmatch work more nicely than libiberty's, since it's
> exposed to the user?
> 

I think so.  If we have it available, we should use it.

Thanks,
- Tom

> But maybe another way to go, assuming gnulib removal is on the table,
> would be to ensure that libiberty uses the macOS fnmatch and not the
> replacement.
> 
> Tom


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

* Re: [PATCH] [gdb/build] Use gnulib fnmatch
  2026-11-18 15:57       ` Tom de Vries
@ 2026-11-19 20:39         ` Tom Tromey
  0 siblings, 0 replies; 6+ messages in thread
From: Tom Tromey @ 2026-11-19 20:39 UTC (permalink / raw)
  To: Tom de Vries; +Cc: Tom Tromey, Thiago Jung Bauermann, gdb-patches

>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:

>> The main issue is that gdb is extremely sensitive to exactly which
>> gnulib modules are used.  I don't recall the details any more, but there
>> are some modules that cannot be imported, and if they are, things break.

Tom> The thing I encountered that sounds most like the problem you describe
Tom> above, is the pthread.h thing.

I tried to dig up whatever is was, but couldn't find it.

Maybe it was something that negatively impacted mingw.  I really can't
recall.

Tom

^ 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