stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Sebor <mse...@gmail.com>
Subject Re: STDCXX-1072 SPARC V8 mutex alignment requirements
Date Fri, 28 Sep 2012 15:36:56 GMT
The patch looks reasonable to me, except for the missing guard
for _RWSTD_NO_LONG_DOUBLE. For C++ 11 compilers, we might want
to replace the union with the alignas features. Of course, that
will require another configuration test and macro, and most
likely won't help the current Sun Studio compiler (unless it
already implements alignas). Although it's possible that the
compiler supports the GCC aligned attribute (we might want to
use it with Linux compilers versions that don't yet implement
C++ 11 alignas).

Martin

On 09/28/2012 06:29 AM, Liviu Nicoara wrote:
> I have created the above and linked it to the closed STDCXX-1066.
>
> In short, my reading about this issue is that the kernel patch changed
> the alignment of the userland mutex objects from a machine word to a
> double-word boundary. No changes are required of the users who use such
> objects in their programs unless users create mutex objects in buffers
> which may not be aligned on a proper boundary. E.g., the following are
> safe:
>
> mutex_t lock;
>
> struct S {
> char misalign;
> mutex_t lock;
> };
>
> whereas the following is not:
>
> union {
> void* align;
> char buf [sizeof mutex_t];
> } u;
>
> new (&u) mutex_t;
>
> because the alignment requirements for void pointer are less strict than
> for mutex_t. A few places in the library use the latter for all sorts of
> static objects (mostly local statics). I looked esp. for places where we
> build objects that contain mutex sub-objects inside a union-aligned buffer:
>
> struct S {
> char c;
> mutex_t m;
> };
>
> ...
>
> union {
> void* align; // <- incorrect
> char buf [sizeof (S)];
> } u;
>
> new (&u) S ();
>
> The alignment must be changed to a value equal or greater than the mutex
> alignment requirements.
>
> IMO, the patch I attached does not break binary compatibility. It uses a
> one size fits all long double for alignment -- like we use in
> rw/_mutex.h -- but in doing so dispenses with all sorts of preprocessor
> conditionals.
>
> I still don't have access to a SPARC machine. Any feed-back and/or SPARC
> build results are more than welcome!
>
> Thanks!
>
> Liviu
>


Mime
View raw message