git: 24fd63e0970f - main - mips: Don't set __NO_TLS to disable some uses of TLS.
Jessica Clarke
jrtc27 at freebsd.org
Thu Feb 18 21:07:38 UTC 2021
On 18 Feb 2021, at 20:52, Konstantin Belousov <kostikbel at gmail.com> wrote:
> On Wed, Feb 17, 2021 at 04:48:22PM -0800, John Baldwin wrote:
>> On 2/17/21 4:35 PM, John Baldwin wrote:
>>> The branch main has been updated by jhb:
>>>
>>> URL: https://cgit.FreeBSD.org/src/commit/?id=24fd63e0970f91189dd2acde987bd2e4c8c04a50
>>>
>>> commit 24fd63e0970f91189dd2acde987bd2e4c8c04a50
>>> Author: John Baldwin <jhb at FreeBSD.org>
>>> AuthorDate: 2021-02-18 00:34:23 +0000
>>> Commit: John Baldwin <jhb at FreeBSD.org>
>>> CommitDate: 2021-02-18 00:34:23 +0000
>>>
>>> mips: Don't set __NO_TLS to disable some uses of TLS.
>>> __NO_TLS was originally added to disable use of _Thread in the locale
>>> code in libc in 82dd5016bd749d1d9e1531bd1703aebeecceab34. At the time
>>> libc did not support TLS on MIPS (I believe), but TLS support was
>>> added to libc (at least _set_tp.c) for MIPS about a month after
>>> __NO_TLS was added, but __NO_TLS was still left around.
>>> Reviewed by: imp
>>> Sponsored by: DARPA
>>> Differential Revision: https://reviews.freebsd.org/D28713
>>> ---
>>> sys/sys/cdefs.h | 3 +--
>>> 1 file changed, 1 insertion(+), 2 deletions(-)
>>>
>>> diff --git a/sys/sys/cdefs.h b/sys/sys/cdefs.h
>>> index 64f26480a2f5..ff18911f6acf 100644
>>> --- a/sys/sys/cdefs.h
>>> +++ b/sys/sys/cdefs.h
>>> @@ -768,8 +768,7 @@
>>> #endif
>>> #endif /* __STDC_WANT_LIB_EXT1__ */
>>> -#if defined(__mips) || \
>>> - (defined(__powerpc64__) && (!defined(_CALL_ELF) || _CALL_ELF == 1))
>>> +#if defined(__powerpc64__) && (!defined(_CALL_ELF) || _CALL_ELF == 1)
>>> #define __NO_TLS 1
>>> #endif
>>
>> It would be really nice to kill __NO_TLS entirely. There is at least one
>> unconditional use of _Thread_local (sorry, should have used that instead
>> of _Thread above) in libc in stdlib/cxa_thread_atexit_impl.c, so it seems
>> highly unlikely that TLS is actually broken on any of our platforms as the
>> libc build would have been broken instead.
>
> There is a difference between compile and runtime. The mentioned libc
> use in cxa_thread_atexit_impl.c is to support some (I believe) rarely
> used C++ feature of thread-local storage with destructors, so it might
> be simply not observed often. OTOH, locale functions infect almost
> everything string-related in libc, so the breakage would be quite
> visible.
It's also used in jemalloc for tsd_initialized which is a rather key
variable, so if TLS is broken you won't get very far in userspace
(source: I had to debug implementing it for CHERI-MIPS), well before
you even think about getting to locale functions.
> But, I wonder, what does CALL_ELF mean? Is it for old 64bit PowerPC ABI,
> that was abandoned with the switch to ELFv2?
Yes, _CALL_ELF == 2 for ELFv2. I highly doubt the defines were needed
for the ELFv1 ABI, but they're especially redundant now. Presumably
David's original fixed commit[1] added powerpc64 to that list because
TLS wasn't yet supported in LLVM; that happened later in 2012 and our
wiki changed it to being implemented in December 2012[2]. So I suspect
it should have been deleted 8 years ago.
Jess
[1] b0968176b3a821598a31de6698e01931d1417584
[2] https://wiki.freebsd.org/action/diff/BuildingFreeBSDWithClang?action=diff&rev1=340&rev2=341
More information about the dev-commits-src-main
mailing list