Re: Build failure with GCC 15 (-std=gnu23)

From: Sam James
Date: Mon Nov 18 2024 - 21:57:41 EST


Nathan Chancellor <nathan@xxxxxxxxxx> writes:

> Hi Kostadin,
>
> Just a quick FYI off the bat, you only directed this to LKML, which is
> basically like sending it into the void because very few people actually
> read every message on LKML. I only caught it because I have a filter set
> up for mentions of Clang and LLVM. I'd suggest adding at least the
> Kbuild mailing list, which I have done now. I have also added Arnd
> because I seem to recall him looking into how hard it would be to build
> the kernel with C23.

FWIW, scripts/get_maintainers.pl for stddef.h and types.h doesn't
include kbuild -- maybe we should add that in.

>
> On Mon, Nov 18, 2024 at 02:26:49PM +0000, Kostadin Shishmanov wrote:
>> Whenever I try to build the kernel with upcoming GCC 15 which defaults to -std=gnu23 I get a build failure:
>>
>> ```
>> In file included from ./include/uapi/linux/posix_types.h:5,
>> from ./include/uapi/linux/types.h:14,
>> from ./include/linux/types.h:6,
>> from ./include/uapi/linux/mei_uuid.h:12,
>> from ./include/uapi/linux/mei.h:10,
>> from ./include/linux/mod_devicetable.h:12,
>> from scripts/mod/devicetable-offsets.c:3:
>> ./include/linux/stddef.h:11:9: error: expected identifier before ‘false’
>> 11 | false = 0,
>> ./include/linux/types.h:35:33: error: two or more data types in declaration specifiers
>> 35 | typedef _Bool bool;
>> ./include/linux/types.h:35:1: warning: useless type name in empty declaration
>> 35 | typedef _Bool bool;
>> ```
>>
>> This can be reproduced on older GCC versions with KCFLAGS="-std=gnu23"
>
> The kernel builds explicitly with '-std=gnu11' (see Makefile), so I
> would not expect the default switch on the GCC side to matter. That
> signals to me that we are not actually using that flag everywhere
> then?

Right, that's the conclusion I reached when discussing it with Kostadin.

> Building with V=1, I can see '-std=gnu11' in the compiler command for
> scripts/mod/devicetable-offsets.s, which is generated from
> scripts/mod/devicetable-offsets.c, so it seems like something else is
> going on here?

I can reproduce it with `make defconfig` at
158f238aa69d91ad74e535c73f552bd4b025109c in Linus' tree with just `make
V=1 -j$(nproc) -l$(nproc)` (i.e. no CFLAGS manipulation at all).

```
# CC drivers/firmware/efi/libstub/x86-5lvl.o
gcc -Wp,-MMD,drivers/firmware/efi/libstub/.x86-5lvl.o.d -nostdinc -I./arch/x86/include -I./arch/x86/include/generated -I./include -I./arch/x86/include/uapi -I./arch/x86/include/genera
ted/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/compiler-version.h -include ./include/linux/kconfig.h -include ./include/linux/compiler_types.h -D__KERNEL__
-fmacro-prefix-map=./= -mcmodel=small -m64 -D__KERNEL__ -fPIC -fno-strict-aliasing -mno-red-zone -mno-mmx -mno-sse -fshort-wchar -Wno-pointer-sign -Wno-address-of-packed-member -fno-asy
nchronous-unwind-tables -Os -DDISABLE_BRANCH_PROFILING -include ./include/linux/hidden.h -D__NO_FORTIFY -ffreestanding -fno-stack-protector -D__DISABLE_EXPORTS -DKBUILD_MODFILE='"driv
ers/firmware/efi/libstub/x86-5lvl"' -DKBUILD_BASENAME='"x86_5lvl"' -DKBUILD_MODNAME='"x86_5lvl"' -D__KBUILD_MODNAME=kmod_x86_5lvl -c -o drivers/firmware/efi/libstub/x86-5lvl.o drivers/fi
rmware/efi/libstub/x86-5lvl.c
In file included from ./include/uapi/linux/posix_types.h:5,
from ./include/uapi/linux/types.h:14,
from ./include/linux/types.h:6,
from ./include/linux/kasan-checks.h:5,
from ./include/asm-generic/rwonce.h:26,
from ./arch/x86/include/generated/asm/rwonce.h:1,
from ./include/linux/compiler.h:317,
from ./include/linux/build_bug.h:5,
from ./include/linux/init.h:5,
from ./include/linux/efi.h:15,
from drivers/firmware/efi/libstub/file.c:10:
./include/linux/stddef.h:11:9: error: expected identifier before ‘false’
11 | false = 0,
| ^~~~~
```

-std=gnu11 certainly isn't there.

>
> [...]

thanks,
sam