Fix libiberty.h inclusion on non-glibc hosts tree-wide
A patch addresses issues with `libiberty.h` inclusion on non-glibc systems, ensuring `memrchr` support is correctly handled and configuration is updated across…
This patch corrects an issue where libiberty.h inclusion fails on non-glibc hosts (like FreeBSD) after memrchr support was added in 2025. The fix involves adding an AC_CHECK_FUNCS for memrchr in various project configurations and ensuring config.h is included where necessary. The change is described as ‘tad invasive’ due to its widespread application but is deemed essential for cross-platform compatibility.
- proposer
Proposes a patch to fix `libiberty.h` inclusion issues on non-glibc systems by adding `memrchr` checks and updating configuration.
“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). 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 includ…”
- reviewer
Acknowledges the issue and the proposed solution, indicating it seems reasonable and seeking clarification on the scope.
“On 18.11.2026 01:49, Nick Alcock wrote: > 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). > > Fix trivial, but a tad invasive, since a lot of projects include > libiberty.h, and it shows up a few places that don'…”
- contributor
Responds to the proposed fix, acknowledging the issue and expressing openness to alternative solutions if the current approach is deemed too invasive.
“@sam, @pietro … any ideas most welcome. > On 18 Nov 2026, at 12:24, Jan Beulich <jbeulich@suse.com> wrote: > > On 18.11.2026 01:49, Nick Alcock wrote: >> 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). > > I…”
- other
Questions the premise of the problem, seeking clarification on whether the issue is specific to non-Linux and non-glibc environments, and notes the historical context of BSD systems.
“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…”
Technical Tradeoffs
- Increased build system complexity (more `configure.ac` checks) vs. broader platform compatibility.
- 'Invasive' code changes affecting multiple subprojects vs. fixing a fundamental build issue.
In Details
This patch addresses a build breakage on non-glibc, non-Linux systems (like FreeBSD) that emerged after memrchr was added to libiberty.h. The core issue is that libiberty.h now relies on memrchr, which needs to be detected via AC_CHECK_FUNCS. The fix is to insert this check into the configure.ac of multiple Binutils subprojects and ensure config.h is included correctly, especially in files like arlex.l which historically omitted it. The patch is described as 'invasive' due to touching many configuration scripts and files.
- libiberty.h
- A header file in GNU projects that provides a collection of utility functions, often used when the target system's C library is insufficient or non-standard.
- memrchr
- A C standard library function that searches a string for the last occurrence of a character.
- non-glibc hosts
- Systems that do not use the GNU C Library (glibc) as their primary C standard library. Examples include musl libc or BSD-derived libc implementations.
- AC_CHECK_FUNCS
- An Autoconf macro used in
configure.acfiles to check for the availability of specific functions in the C library. - config.h
- A header file automatically generated by Autoconf's
configurescript, containing definitions and macros based on the host system's capabilities and configuration.