Re: [PATCH] sched: Work around undefined behavior in sched class checking

From: Andi Kleen
Date: Wed May 05 2021 - 10:39:38 EST


> Context:
>
> <https://lore.kernel.org/lkml/20210505033945.1282851-1-ak@xxxxxxxxxxxxxxx/>
>
> Obviously, GCC doesn't do this in general.

We've seen it in other cases before, that's why RELOC_HIDE exists.
A classic case was __pa_symbol()

That dates back nearly two decades at this point.

> Would you please provide a
> minimal test case?

You can only reproduce it with a LTO build because it needs knowledge
between different translation units for this specific case.

But gcc will totally do the optimization even without LTO if it can
prove the same inside a single TU.

If you want to reproduce it you can use my tree here
git://git.kernel.org/pub/scm/linux/kernel/git/ak/linux-misc lto-5.12-3
and revert the fix. The kernel will not boot.

-Andi