Re: gcc-10: kernel stack is corrupted and fails to boot

From: Arvind Sankar
Date: Thu May 14 2020 - 11:50:36 EST


On Thu, May 14, 2020 at 10:40:44AM +0200, Arnd Bergmann wrote:
> On Thu, May 14, 2020 at 7:22 AM Arvind Sankar <nivedita@xxxxxxxxxxxx> wrote:
> > On Wed, May 13, 2020 at 09:52:07PM -0700, Linus Torvalds wrote:
> > > On Wed, May 13, 2020, 20:50 Andy Lutomirski <luto@xxxxxxxxxxxxxx> wrote:
> > The gcc docs [1,2] at least don't inspire much confidence that this will
> > continue working with plain asm("") though:
> >
> > "Note that GCCâs optimizers can move asm statements relative to other
> > code, including across jumps."
> > ...
> > "Note that the compiler can move even volatile asm instructions relative
> > to other code, including across jump instructions."
> >
> > Even if we don't include an instruction in it I think it should at least
> > have a memory clobber, to stop the compiler from deciding that it can be
> > moved before the call so it can do the tail-call optimization.
>
> I think LTO would still be able to notice that cpu_startup_entry() can
> be annotated __attribute__((noreturn)) and optimize the callers
> accordingly, which in turn would allow a tail call again after dead code
> elimination.
>
> Arnd

Yes, with LTO the only solution is to actually compile the caller
without stack checking I think. Although at present gcc actually
doesn't tail-call optimize calls to noreturn functions that could easily
change.