On Thu, 26 Nov 2020 at 00:03, Segher Boessenkool
<
seg...@kernel.crashing.org> wrote:
>
> On Wed, Nov 25, 2020 at 11:56:40AM -0800, Kees Cook wrote:
> > On Sat, Nov 14, 2020 at 11:20:17AM +0100, Ard Biesheuvel wrote:
> > > In spite of the apparent difference of opinion here, there are two
> > > irrefutable facts about __attribute__((optimize)) on GCC that can only
> > > lead to the conclusion that we must never use it in Linux:
> > > - the GCC developers refuse to rigorously define its behavior, so we
> > > don't know what it actually does;
>
> This is because it isn't clear at all what it *should* do, for some
> options. For others it is obvious, and it works just fine for those.
>
The problem is that the distinction of some vs. others is not
documented, and may change between architectures or GCC versions.
> (And we do not rigorously define the behaviour of almost *anything*, not
> in the user manual anyway!)
>
> The interface has huge usability problems. We want to wean people off
> of using this attribute. But claiming all kinds of FUD about it is a
> disservice to users: it works fine for where it does work, there is no
> reason for people to hurriedly change their code (or change it at all).
>
What do you mean by all kinds of FUD? The kind of FUD appearing on the
GCC wiki? I'll quote it again here for everyone's convenience.
"""
Currently (2015), this attribute is known to have several critical
bugs (PR37565, PR63401, PR60580, PR50782). Using it may produce not
effect at all or lead to wrong-code.
Quoting one GCC maintainer: "I consider the optimize attribute code
seriously broken and unmaintained (but sometimes useful for debugging
- and only that)." source
Unfortunately, the people who added it are either not working on GCC
anymore or not interested in fixing it. Do not try to guess how it is
supposed to work by trial-and-error. There is not a list of options
that are safe to use or known to be broken. Bug reports about the
optimize attribute being broken will probably be closed as WONTFIX
(PR59262), thus it is not worth to open new ones. If it works for you
for a given version of GCC, it doesn't mean it will work on a
different machine or a different version.
The only realistic choices are to not use it, to use it and accept its
brokenness (current or future one, since it is unmaintained), or join
GCC and fix it (perhaps motivating other people along the way to join
your effort).
"""
The reason we have to change code in the kernel is because it actually
breaks stuff. For instance, functions using __attribute__((optimize))
to disable GCSE are suddenly compiled with or without stack protector
checks or frame pointers, even though the opposite option is set at
the compilation unit level.
I am not disputing that __attribute__((optimize)) is highly useful in
some cases, I am just arguing that such cases don't exist in a Linux
kernel running on a production system.