NetBSD Problem Report #58796
From www@netbsd.org Thu Oct 31 19:02:52 2024
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256
client-signature RSA-PSS (2048 bits) client-digest SHA256)
(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
by mollari.NetBSD.org (Postfix) with ESMTPS id 8412D1A9238
for <gnats-bugs@gnats.NetBSD.org>; Thu, 31 Oct 2024 19:02:52 +0000 (UTC)
Message-Id: <20241031190251.1A4151A923B@mollari.NetBSD.org>
Date: Thu, 31 Oct 2024 19:02:51 +0000 (UTC)
From: campbell+netbsd@mumble.net
Reply-To: campbell+netbsd@mumble.net
To: gnats-bugs@NetBSD.org
Subject: arm/mcontext.h has nested extern for _lwp_getprivate
X-Send-Pr-Version: www-1.0
>Number: 58796
>Category: misc
>Synopsis: arm/mcontext.h has nested extern for _lwp_getprivate
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: misc-bug-people
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Thu Oct 31 19:05:00 +0000 2024
>Closed-Date: Mon Mar 17 00:00:36 +0000 2025
>Last-Modified: Mon Mar 17 00:00:36 +0000 2025
>Originator: Taylor R Campbell
>Release: current, 10, 9, ...
>Organization:
The NestedexternLWP Private Foundation
>Environment:
>Description:
<lwp.h> (include/lwp.h) declares _lwp_getprivate, the out-of-line syscall stub in libc to query the lwp's private pointer.
<machine/mcontext.h> (sys/arch/*/include/mcontext.h) defines _lwp_getprivate_fast or _lwp_gettcb_fast and _lwp_settcb. The Arm version is defined in terms of _lwp_getprivate as a fallback for some broken Arm cores.
Currently, all users of _lwp_getprivate/gettcb/settcb_fast are expected to (a) define _RTLD_SOURCE, _LIBC_SOURCE, or __LIBPTHREAD_SOURCE__, and (b) include <lwp.h>, which includes <machine/mcontext.h> via <sys/ucontext.h>, and which _then_ declares _lwp_getprivate.
So the declaration of _lwp_getprivate isn't available by the time Arm's <machine/mcontext.h> (sys/arch/arm/include/mcontext.h) needs it, and adding #include <lwp.h> to Arm's <machine/mcontext.h> would create a circular dependency with <lwp.h>.
>How-To-Repeat:
code inspection, and/or build with -Werror=nested-extern
>Fix:
1. Move the definitions of _lwp_getprivate/gettcb/settcb_fast (plus TLS_TP_OFFSET and TLS_DTV_OFFSET, and whatever other parts are directly relevant) to a new header file <machine/lwp_private.h>.
2. Use #include <lwp.h> in the Arm and PowerPC <machine/lwp_private.h> implementations (and whichever other ones need _lwp_getprivate/setprivate or similar).
3. Include <machine/lwp_private.h> explicitly in all users of _lwp_getprivate/gettcb/settcb_fast instead of using the kooky _RTLD_SOURCE/_LIBC_SOURCE/__LIBPTHREAD_SOURCE__ conditionalization.
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed
State-Changed-By: riastradh@NetBSD.org
State-Changed-When: Mon, 17 Mar 2025 00:00:36 +0000
State-Changed-Why:
fixed in HEAD, not worth pullup
https://mail-index.netbsd.org/source-changes/2024/11/30/msg154647.html
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.