Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Nick Alcock <nix@esperi.org.uk>
To: Sam James <sam@gentoo.org>
Cc: binutils@sourceware.org, gdb-patches@sourceware.org, iain@sandoe.co.uk
Subject: Re: [PATCH] Fix libiberty.h inclusion on non-glibc hosts tree-wide
Date: Wed, 18 Nov 2026 12:00:41 +0000	[thread overview]
Message-ID: <87ld6qmjrq.fsf@esperi.org.uk> (raw)
In-Reply-To: <8733syzg76.fsf@gentoo.org>

On 18 Nov 2026, Sam James stated:

> Nick Alcock <nix@esperi.org.uk> writes:
>
>> In 2025, Iain Sandoe added memrchr support to libiberty.h. This requires
>> a new AC_CHECK_FUNCS of memrchr in every project that transitively
>> includes it, or builds on non-glibc, non-Linux hosts will fail (observed
>> on FreeBSD 15).
>
> That doesn't sound right to me as stated: it would mean nobody has reported or
> tested that in over a year, even for say musl? Or do you mean 'non-glibc
> and non-Linux'? (I guess you do based on the condition in libiberty.h
> now I look).
>
> Anyway, does it really require that?
>
> include/libiberty.h has:
>
> /* Make memrchr available on systems that do not have it.  */
> #if !defined (__GNU_LIBRARY__ ) && !defined (__linux__) && \
>     !defined (HAVE_MEMRCHR)
> extern void *memrchr(const void *, int, size_t);
> #endif
>
> so on say, FreeBSD, I would expect this to be used. Then you get the
> link-time definition from libiberty?

Like glibc, FreeBSD these days defines memrchr but uses extra macro
magic which disagrees with a redefinition of the prototype unless the
prototype is in scope. So if you don't check for it in the subproject's
configury, all those tests fail and we hit the prototype and then
explode.

Maybe the right fix is to also add a #ifndef memrchr outside all the
others, on the grounds that if the system already defines memrchr as a
macro we are certain to not need to redefine it? The same might be worth
doing to the declarations of the other POSIX-specified things in
libiberty.h (of which there are a quite a few, and quite a few
AC_CHECK_FUNCS of them in projects that don't use them just to stop
things breaking at #include time).

> Can you show me what the failure is please?

  CC       targets.lo
In file included from /usr/include/stdio.h:38,
                 from ../../bfd/sysdep.h:30,
                 from ../../bfd/targets.c:22:
../../bfd/../include/libiberty.h:226:14: error: expected identifier or '(' before '_Generic'
  226 | extern void *memrchr(const void *, int, size_t);
      |              ^~~~~~~
gmake[3]: *** [Makefile:2329: targets.lo] Error 1
gmake[3]: *** Waiting for unfinished jobs....

(and so on for every other affected file.)

... because on FreeBSD, memrchr is a macro:

#define memrchr(b, c, n)        __qualsel((b),                          \
        (const void *)(memrchr)((b), (c), (n)), (memrchr)((b), (c), (n)))

(where __qualsel is a _Generic usage.)

>> Fix trivial, but a tad invasive, since a lot of projects include
>> libiberty.h, and it shows up a few places that don't include config.h at
>> all (including some that include ansidecl.h, which requires config.h for
>> proper operation).
>>
>> All relevant configury regenerated.
>>
>> Also touches GDB machinery, so gdb-patches is Cc:ed.
>>
>> Iain Sandoe Cc:ed: Iain, if you disagree with my rather nasty approach
>> here, I'd be interested in anything better. (The need to use %top in
>> binutils/arlex.l is slightly worrying.  It's not in POSIX, but
>> we need something like it or we can't include config.h before the
>> system headers it must precede.  (Including config.h in libiberty.h
>> won't work for the same reason.)
>>
>> But if you don't do this, you can't compile binutils/arlex.c on
>> FreeBSD any more (or any non-Linux, non-glibc system).
>
> Sorry if I'm missing something obvious here, it's a busy fortnight
> for me but I wanted to reply before we do something that may be the
> wrong direction.

I spent the entire time I was working on this commit thinking I was
missing something obvious. Hence the need for review :)

-- 
NULL && (void)

  reply	other threads:[~2026-11-18 12:01 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18  0:49 Nick Alcock
2026-11-18  7:24 ` Jan Beulich
2026-11-18  7:41   ` Iain Sandoe
2026-11-18 11:50     ` Nick Alcock
2026-11-18  8:39 ` Sam James
2026-11-18 12:00   ` Nick Alcock [this message]
2026-11-18 12:12     ` Sam James
2026-11-18 17:18       ` Nix
2026-11-19 20:35 ` Tom Tromey
2026-11-20 15:25   ` [PATCH v2] Support libiberty functions as macros; fix up AC_CHECK_DECL tree-wide Nick Alcock

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=87ld6qmjrq.fsf@esperi.org.uk \
    --to=nix@esperi.org.uk \
    --cc=binutils@sourceware.org \
    --cc=gdb-patches@sourceware.org \
    --cc=iain@sandoe.co.uk \
    --cc=sam@gentoo.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