[PATCH] Fix libiberty.h inclusion on non-glibc hosts tree-wide

Sam James sam@gentoo.org
Wed Nov 18 08:39:25 GMT 2026


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?

Can you show me what the failure is please?

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

sam
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 418 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20261118/aa8e248c/attachment-0001.sig>


More information about the Binutils mailing list