Re: [PATCH v2] compiler.h: give up __compiletime_assert_fallback()

From: Masahiro Yamada
Date: Tue Aug 28 2018 - 09:47:39 EST


2018-08-28 19:55 GMT+09:00 Arnd Bergmann <arnd@xxxxxxxx>:
> On Mon, Aug 27, 2018 at 10:44 PM Daniel Santos <daniel.santos@xxxxxxxxx> wrote:
>>
>> On 08/27/2018 03:09 PM, Nick Desaulniers wrote:
>> >> Now we're back to the question of "what do you mean by 'constant'"? If
>> >> you mean a C constant expression (as defined in the C standard) than
>> >> almost none of this code fits that criteria. For these compile-time
>> >> assertions to work, we are concerned with the data flow analysis and
>> >> constant propagation performed by the compiler during optimization. You
>> >> will notice in include/linux/compiler.h that __compiletime_assert is a
>> >> no-op when __OPTIMIZE__ is not defined.
>> > Depending on optimizations for static assertions sounds problematic.
>>
>> (with my best Palpatine voice) It is unavoidable.
>>
>> Actually it's theoretically possible, but the compiler would have to do
>> something akin to copying it's control flow graph et. al, run -O2-ish
>> optimizations, perform the static assertions and then throw away the
>> optimized control flow graph and emit code based upon the original.
>
> In the context of the kernel, compiling with anything less than -O2 or
> -Os is not an issue, we don't do it anyway. -O0 never worked, and
> AFAICT we only build one file with -O1, but that is something we can do
> away with as well:
>
> from fs/reiserfs/Makefile:
> # gcc -O2 (the kernel default) is overaggressive on ppc32 when many inline
> # functions are used. This causes the compiler to advance the stack
> # pointer out of the available stack space, corrupting kernel space,
> # and causing a panic. Since this behavior only affects ppc32, this ifeq
> # will work around it. If any other architecture displays this behavior,
> # add it here.
> ccflags-$(CONFIG_PPC32) := $(call cc-ifversion, -lt, 0400, -O1)
>
> Arnd

Recently, I sent out patches to remove redundant GCC version checks,
including this one.

https://lore.kernel.org/patchwork/patch/977808/

I do not know who is maintaining reiserfs, though.


--
Best Regards
Masahiro Yamada