Re: [PATCH 1/8] Compiler attributes: GCC function alignment workarounds

From: Mark Rutland
Date: Thu Jan 12 2023 - 06:49:51 EST


On Wed, Jan 11, 2023 at 06:27:53PM +0000, Mark Rutland wrote:
> On Mon, Jan 09, 2023 at 03:43:16PM +0100, Miguel Ojeda wrote:
> > On Mon, Jan 9, 2023 at 2:58 PM Mark Rutland <mark.rutland@xxxxxxx> wrote:
> > >
> > > As far as I can tell, GCC doesn't respect '-falign-functions=N':
> > >
> > > * When the __weak__ attribute is used
> > >
> > > GCC seems to forget the alignment specified by '-falign-functions=N',
> > > but will respect the '__aligned__(N)' function attribute. Thus, we can
> > > work around this by explciitly setting the alignment for weak
> > > functions.
> > >
> > > * When the __cold__ attribute is used
> > >
> > > GCC seems to forget the alignment specified by '-falign-functions=N',
> > > and also doesn't seem to respect the '__aligned__(N)' function
> > > attribute. The only way to work around this is to not use the __cold__
> > > attibute.
> >
> > If you happen to have a reduced case, then it would be nice to link it
> > in the commit. A bug report to GCC would also be nice.
> >
> > I gave it a very quick try in Compiler Explorer, but I couldn't
> > reproduce it, so I guess it depends on flags, non-trivial functions or
> > something else.
>
> So having spent today coming up with tests, it turns out it's not quite as I
> described above, but in a sense worse. I'm posting a summary here for
> posterity; I'll try to get this to compiler folk shortly.

I've added the cold bits to an existing ticket:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88345

I have not been able to reproduce the issue with __weak__, so I'll go dig into
that some more; it's likely I was mistaken there.

Thanks,
Mark.