From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id om+bKqmT/WqQKhwAWB0awg (envelope-from ) for ; Wed, 18 Nov 2026 07:01:45 -0500 Received: by simark.ca (Postfix, from userid 112) id 817791E0BC; Wed, 18 Nov 2026 07:01:45 -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 B66C51E087 for ; Wed, 18 Nov 2026 07:01:44 -0500 (EST) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 315004BA23CA for ; Wed, 18 Nov 2026 12:01:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 315004BA23CA Received: from mail.esperi.org.uk (icebox.esperi.org.uk [81.187.191.129]) by sourceware.org (Postfix) with ESMTPS id 7E1F84BA2E1A for ; Wed, 18 Nov 2026 12:00:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7E1F84BA2E1A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=esperi.org.uk Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=esperi.org.uk ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 7E1F84BA2E1A Authentication-Results: sourceware.org; arc=none smtp.remote-ip=81.187.191.129 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1795003246; cv=none; b=ASErRJ4FxxN6Qcja+Q6Rdy4LPZh/bMv3N2bVlQ0h7wK2jGoATEqYS4t2LMvHsVjg0r1KRJJzkdVK+621Y7yr/JucbtQOtKAcLj1Z/JNq/PJ91LS+0OX40kisH+qMrJkFedBN0PFq/aAycDgbFBkwDno1Nc6A45yP46UJgvcR0/w= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1795003246; c=relaxed/simple; bh=1htHNS894fVlm4e2uqhLISq0jSSYbK7PPdrgqMayJ4s=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=dLA5UbktaT/Qj5BiK3dbhG8ufEoSoH1w488LKoSO1in8PRmaUrSLvnLHiFJFYw5iVTOoMCzIKIz/+qGmjkePF89fSjjGXMFJI0VyiZAN2or4WFiKs0HjWXLCq1Syp9/TAi4zR8wUDQ6TFSNU3YCC38e0ZtU3ggImNrmgPygnMVc= ARC-Authentication-Results: i=1; sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7E1F84BA2E1A Received: from loom (nix@sidle.srvr.nix [192.168.14.8]) by mail.esperi.org.uk (8.17.2/8.17.2) with ESMTPS id 6AIC0fHs018461 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Wed, 18 Nov 2026 12:00:43 GMT From: Nick Alcock To: Sam James 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: <8733syzg76.fsf@gentoo.org> References: <20261118004926.6404-1-nix@esperi.org.uk> <8733syzg76.fsf@gentoo.org> Emacs: an inspiring example of form following function... to Hell. Date: Wed, 18 Nov 2026 12:00:41 +0000 Message-ID: <87ld6qmjrq.fsf@esperi.org.uk> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-DCC-wuwien-Metrics: loom 1290; Body=4 Fuz1=4 Fuz2=4 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 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). > 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)