This article is more than 1 year old

Linux kernel minimum compiler raised to GCC 5.1, allowing potential C11 use

Change also has handy side effect of fixing some warnings as errors

Linux creator and maintainer Linus Torvalds has merged a late change to the forthcoming 5.15 kernel code that raises the minimum compiler from GCC 4.9 to 5.1 – which may in future enable use of an updated version of the C programming language, C11.

Previously, the minimum version of GCC (GNU Compiler Collection) was 4.9, for which the first release arrived in 2014. The change to 5.1 was proposed by Google's Nick Desaulniers, who works on compiling the kernel with Clang, to simplify code required to work around errors caused by missing compiler features.

"Raising the minimum supported versions allows us to remove all of the fallback helpers for !COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW, instead dispatching the compiler builtins," he explained.

The kernel already specifies a minimum of GCC 5.1 for arm64 builds. GCC 5.1 was first released in April 2015.

Torvalds merged the change, not only because of Desaulniers' issue, but also for reasons relating to the clean-up required to treat warnings as errors (-Werror), a contentious change that was modified to apply only to test builds, but remains important.

"Gcc-4.9 support has been an annoyance for some time, and with -Werror I had the choice of applying a fairly big patch from Kees Cook to remove a fair number of initializer warnings (still leaving some), or this patch series from Nick that just removes the source of the problem," said Torvalds.

"No one appears to actually be building on 4.9 – there are close to 200 errors (neé warnings) on x86_64 allmodconfig there currently," said Cook, a kernel security engineer at Google.

Some commented that they do still use GCC 4.9, but in this case the solution will be to stick with an older kernel release.

"According to distrowatch, this will lose support for the distro gcc version of Debian 8 (Jessie), Ubuntu 15.04, and older Android AOSP (new versions use clang to build kernels, old versions also need older kernels). I think that is acceptable," said kernel developer Arnd Bergmann.

Bergmann also observed that "after this, I think we can also change the --std=gnu89 to --std=gnu11, as an additional benefit." Torvalds also noted this, saying: "We can probably change our use of '--std=gnu89' to '--std=gnu11', and finally start using local loop declarations etc. But this series does _not_ yet do that."

These directives determine the C standard used. std=gnu89 means ISO C90 with GNU extensions, which include some C99 features. The change would enable use of C11 with GNU extensions. C11 was ratified a decade ago, as its name implies.

In C89, all variable declarations have to be at the start of a block of code, whereas in C99 on, variables can be declared anywhere in a block. Torvalds said in 2005: "It's a coding style issue. We put our variable declarations where people can _find_ them, not in random places in the code. Putting variables in the middle of code only improves readability when you have messy code. Now, one feature that _may_ be worth it is the loop counter thing: for (int i = 10; i; i--) kind of syntax actually makes sense and is a real feature (it makes 'i' local to the loop, and can actually help people avoid bugs– you can't use 'i' by mistake after the loop)."

With all the excitement about the possible future use of Rust in kernel coding, the latest change is a reminder that not only is the kernel coded in C, it also uses an old version of the language. The latest version of C, and the default in GCC if no directive is used, is ISO/IEC 9899:2018 also known as C17 or C18, but this only fixes defects in C11 and does not introduce new language features. ®

More about


Send us news

Other stories you might like