From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id YQTeElKW/WpiMRwAWB0awg (envelope-from ) for ; Wed, 18 Nov 2026 07:13:06 -0500 Received: by simark.ca (Postfix, from userid 112) id 493F61E0BC; Wed, 18 Nov 2026 07:13:06 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.3 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 7350D1E087 for ; Wed, 18 Nov 2026 07:13:05 -0500 (EST) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4605A4BA2E3F for ; Wed, 18 Nov 2026 12:13:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4605A4BA2E3F Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) by sourceware.org (Postfix) with ESMTP id 002F44BA2E08; Wed, 18 Nov 2026 12:12:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 002F44BA2E08 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gentoo.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gentoo.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 002F44BA2E08 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=140.211.166.183 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1795003959; cv=none; b=dxIowzmk3NPqAssiIi9kXfZ/Aq930gXwPro+fnjXDG5pYb1gh8xIrXb2jQiA1WHTsQaGuGbweFZQf5BqJapAaRkMW40KRnev0DWrbgORxR7aDvsqveQfilsGY/8rScLaHfeDUA8hjxyJcrG5KuZMtJInTCSKLCA1QGXw8HY0HM0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1795003959; c=relaxed/simple; bh=GyEK/h+ZfmUdD7Au0LtYzkyu7Mr4sTlPRN8Gt43xAjE=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=l176e7z55hBIb4vNSIs30zaGotGKknFQraeHOXNTcPe4kZFAfOmmvWAnZW4aouwyGd0mrTpIrw1XtVC1jE002w1pIHcwSRaJ0iwKsXCO2sP4b33u/Rv/RE7XFFDO42oEKD17gUbzh4cTVcBA1gyPf0Rdj1LNsoK9Gwe+KpYL/vo= ARC-Authentication-Results: i=1; sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 002F44BA2E08 Received: from mop.sam.mop (unknown [IPv6:2001:8b0:19dc:dc5a::a1c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: sam) by smtp.gentoo.org (Postfix) with ESMTPSA id 8BA12342986; Wed, 18 Nov 2026 12:12:37 +0000 (UTC) From: Sam James To: Nick Alcock 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 In-Reply-To: <87ld6qmjrq.fsf@esperi.org.uk> Organization: Gentoo References: <20261118004926.6404-1-nix@esperi.org.uk> <8733syzg76.fsf@gentoo.org> <87ld6qmjrq.fsf@esperi.org.uk> User-Agent: mu4e 1.14.4; emacs 32.0.50 Date: Wed, 18 Nov 2026 12:12:31 +0000 Message-ID: <87tslexrrk.fsf@gentoo.org> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org --=-=-= Content-Type: text/plain Nick Alcock writes: > On 18 Nov 2026, Sam James stated: > >> Nick Alcock 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). This is what I was going to suggest, but... > >> 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.) .. now you show this, I realise why it sounded familiar: https://gcc.gnu.org/PR127914. That is, we should just do (memrchr) instead. > >>> 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 :) :) --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEBBAEWCgCpFiEEJaa7iN2bdkxrVUHCc4QJ9SDfkZAFAmr9ljAbFIAAAAAABAAO bWFudTIsMi41KzEuMTIsMiwyXxSAAAAAAC4AKGlzc3Vlci1mcHJAbm90YXRpb25z Lm9wZW5wZ3AuZmlmdGhob3JzZW1hbi5uZXQyNUE2QkI4OEREOUI3NjRDNkI1NTQx QzI3Mzg0MDlGNTIwREY5MTkwDxxzYW1AZ2VudG9vLm9yZwAKCRBzhAn1IN+RkGmJ APoDFxJSqQ5Lkp/y5eSTThTDnzHLINT1+F9cJK1L8226+QEAhy7yMbR776x0zRvM 6IrLhzYDkO62hnISxCo8gs9SwAU= =N52N -----END PGP SIGNATURE----- --=-=-=--