NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

misc/58796: arm/mcontext.h has nested extern for _lwp_getprivate



>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:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Oct 31 19:05:00 +0000 2024
>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.



Home | Main Index | Thread Index | Old Index