Re: [PATCH glibc 1/3] glibc: Perform rseq registration at C startup and thread creation (v19)
From: Florian Weimer
Date: Tue May 26 2020 - 08:41:28 EST
* Mathieu Desnoyers:
> Something like this ?
> #ifdef __cplusplus
> # if __cplusplus >= 201103L
> # define rseq_static_assert (expr, diagnostic) static_assert (expr, diagnostic)
> # define rseq_alignof alignof
> # endif
> #elif __STDC_VERSION__ >= 201112L
> # define rseq_static_assert (expr, diagnostic) _Static_assert (expr, diagnostic)
> # define rseq_alignof _Alignof
> #ifndef rseq_static_assert
> # define rseq_static_assert (expr, diagnostic) /* nothing */
You can't have a space in #defines like that, no matter what GNU style
> /* Ensure the compiler supports __attribute__ ((aligned)). */
> rseq_static_assert ((rseq_alignof (struct rseq_cs) >= 32, "alignment"));
> rseq_static_assert ((rseq_alignof (struct rseq) >= 32, "alignment"));
You need to move the ; into rseq_static_assert. And if you use explicit
arguments, you can't use double parentheses.
>> And something similar for _Alignas/attribute aligned,
> I don't see where _Alignas is needed here ?
> For attribute aligned, what would be the oldest supported C and C++
> standards ?
There are no standardized attributes for C, there is only _Alignas.
C++11 has an alignas specifier; it's not an attribute either. I think
these are syntactically similar.
>> with an error for
>> older standards and !__GNUC__ compilers (because neither the type nor
>> __thread can be represented there).
> By "type" you mean "struct rseq" here ? What does it contain that requires
> a __GNUC__ compiler ?
__attribute__ and __thread support.
> About __thread, I recall other compilers have other means to declare it.
> In liburcu, I end up with the following:
> #if defined (__cplusplus) && (__cplusplus >= 201103L)
> # define URCU_TLS_STORAGE_CLASS thread_local
> #elif defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
> # define URCU_TLS_STORAGE_CLASS _Thread_local
> #elif defined (_MSC_VER)
> # define URCU_TLS_STORAGE_CLASS __declspec(thread)
> # define URCU_TLS_STORAGE_CLASS __thread
> Would something along those lines be OK for libc ?
Yes, it would be okay (minus the Visual C++ part). This part does not
have to go into UAPI headers first. A fallback definition of __thread
should be okay. Outside glibc, the TLS model declaration is optional, I
think. The glibc *definition* ensures that the variable is