lkml.org 
[lkml]   [2020]   [Mar]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [RFC PATCH glibc 4/8] glibc: Perform rseq(2) registration at C startup and thread creation (v15)
Date
* Mathieu Desnoyers:

>> You also need to add an assert that the compiler supports
>> __attribute__ ((aligned)) because ignoring it produces an
>> ABI-incompatible header.
>
> Are you aware of some helper macro I should use to do this, or
> is it done elsewhere in glibc ?

I don't think we have any such GCC-only types yet. max_align_t is
provided by GCC itself.

>> The struct rseq/struct rseq_cs definitions
>> are broken, they should not try to change the alignment.
>
> AFAIU, this means we should ideally not have used __attribute__((aligned))
> in the uapi headers in the first place. Why is it broken ?

Compilers which are not sufficiently GCC-compatible define
__attribute__(X) as the empty expansion, so you silently get a
different ABI.

There is really no need to specify 32-byte alignment here. Is not
even the size of a standard cache line. It can result in crashes if
these structs are heap-allocated using malloc, when optimizing for
AVX2.

For example, clang turns

void
clear (struct rseq *p)
{
memset (p, 0, sizeof (*p));
}

into:

vxorps %xmm0, %xmm0, %xmm0
vmovaps %ymm0, (%rdi)
vzeroupper
retq

My understanding is that vmovaps will trap if the pointer is
misaligned (“When the source or destination operand is a memory
operand, the operand must be aligned on a 32-byte boundary or a
general-protection exception (#GP) will be generated.”).

> However, now that it is in the wild, it's a bit late to change that.

I had forgotten about the alignment crashes. I think we should
seriously consider changing the types. 8-(

\
 
 \ /
  Last update: 2020-03-19 19:18    [W:0.076 / U:0.116 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site