On Sat, Jul 11, 2026 at 12:00 AM Jakub Jelinek <[email protected]> wrote:
>
> On Wed, Jul 08, 2026 at 08:26:32PM +0800, H.J. Lu wrote:
> > > Not my main area of expertise - but looks OK.
> > >
> > > Thanks,
> > > Richard.
> >
> > Hi Jakub,
> >
> > Does it look correct to you?
>
> This looks really weird.  cfgexpand.cc (expand_stack_vars) already has code to
> take care about alignments, if I try to lay out e.g. -O2 -fsanitize=address
> struct [[gnu::aligned (64)]] A { unsigned char a[512]; };
> struct [[gnu::aligned (128)]] B { unsigned char a[1024]; };
> struct [[gnu::aligned (32)]] C { unsigned char a[2048]; };
> struct [[gnu::aligned (256)]] D { unsigned char a[4096]; };
> struct E { unsigned char a[513]; };
> struct F { unsigned char a[1025]; };
> struct G { unsigned char a[2049]; };
> struct H { unsigned char a[4097]; };
>
> [[gnu::noipa]] void
> bar (struct A *a, struct B *b, struct C *c, struct D *d, struct E *e, struct 
> F *f, struct G *g, struct H *h)
> {
>   __builtin_printf ("%p %p %p %p %p %p %p %p\n", a, b, c, d, e, f, g, h);
> }
>
> [[gnu::noipa]] void
> foo (void)
> {
>   struct A a;
>   struct B b;
>   struct C c;
>   struct D d;
>   struct E e;
>   struct F f;
>   struct G g;
>   struct H h;
>   bar (&a, &b, &c, &d, &e, &f, &g, &h);
> }
>
> int
> main ()
> {
>   foo ();
> }
> the vars are laid out in the a, c, e, g, b, d, f, h order (because the
> sorting first key is very large alignment (never on x86_64), size and only
> then alignment, and all the vars have proper alignment.
>

All stack variables do have the proper alignments.  But when
we allocate ASAN red zone aligned with ASAN alignment on
stack, we don't take alignments of stack variables into account.
When a stack variable alignment > ASAN alignment,  it has the
wrong alignment at run-time since ASAN red zone size on the
stack is only aligned to ASAN alignment.  My patch pads ASAN
red zone so that ASAN red zone size is aligned to

MAX (ASAN alignment, alignments of stack variables)

-- 
H.J.

Reply via email to