News: 1631709824

  ARM Give a man a fire and he's warm for a day, but set fire to him and he's warm for the rest of his life (Terry Pratchett, Jingo)

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

(2021/09/15)


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 [1]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.

[2]

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

[3]

[4]

Torvalds [5]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 [6]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.

[7]

"No one appears to actually be building on 4.9 – there are close to 200 errors (neé warnings) on x86_64 allmodconfig there currently," [8]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," [9]said kernel developer Arnd Bergmann.

[10]Linus Torvalds admits to 'self-inflicted damage' with -Werror as Linux 5.15 rc1 debuts

[11]3 years, 17 alphas, 2 betas, and over 7,500 commits later, OpenSSL version 3 is here

[12]Compromise reached as Linux kernel community protests about treating compiler warnings as errors

[13]GitHub merges 'useless garbage' says Linus Torvalds as new NTFS support added to Linux kernel 5.15

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.

[14]

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 [15]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 [16]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. ®

Get our [17]Tech Resources



[1] https://lore.kernel.org/lkml/20210910234047.1019925-2-ndesaulniers@google.com/#t

[2] https://pubads.g.doubleclick.net/gampad/jump?co=1&iu=/6978/reg_software/front&sz=300x50%7C300x100%7C300x250%7C300x251%7C300x252%7C300x600%7C300x601&tile=2&c=2YUIYvLNnyHImyTgv2HMSaAAAAJM&t=ct%3Dns%26unitnum%3D2%26raptor%3Dcondor%26pos%3Dtop%26test%3D0

[3] https://pubads.g.doubleclick.net/gampad/jump?co=1&iu=/6978/reg_software/front&sz=300x50%7C300x100%7C300x250%7C300x251%7C300x252%7C300x600%7C300x601&tile=4&c=44YUIYvLNnyHImyTgv2HMSaAAAAJM&t=ct%3Dns%26unitnum%3D4%26raptor%3Dfalcon%26pos%3Dmid%26test%3D0

[4] https://pubads.g.doubleclick.net/gampad/jump?co=1&iu=/6978/reg_software/front&sz=300x50%7C300x100%7C300x250%7C300x251%7C300x252%7C300x600%7C300x601&tile=3&c=33YUIYvLNnyHImyTgv2HMSaAAAAJM&t=ct%3Dns%26unitnum%3D3%26raptor%3Deagle%26pos%3Dmid%26test%3D0

[5] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=316346243be6df12799c0b64b788e06bad97c30b

[6] https://www.theregister.com/2021/09/08/compromise_linux_kernel_compiler_warnings/

[7] https://pubads.g.doubleclick.net/gampad/jump?co=1&iu=/6978/reg_software/front&sz=300x50%7C300x100%7C300x250%7C300x251%7C300x252%7C300x600%7C300x601&tile=4&c=44YUIYvLNnyHImyTgv2HMSaAAAAJM&t=ct%3Dns%26unitnum%3D4%26raptor%3Dfalcon%26pos%3Dmid%26test%3D0

[8] https://lore.kernel.org/lkml/202109101917.5BA95B87E0@keescook/

[9] https://lore.kernel.org/lkml/CAK8P3a3kD4vd6Xiq_L1YKQPd41=pNbXoA59fuZK3dTtShezoKg@mail.gmail.com/

[10] https://www.theregister.com/2021/09/13/linux_5_15_rc1/

[11] https://www.theregister.com/2021/09/08/openssl_3/

[12] https://www.theregister.com/2021/09/08/compromise_linux_kernel_compiler_warnings/

[13] https://www.theregister.com/2021/09/06/github_merges_useless_garbage_says/

[14] https://pubads.g.doubleclick.net/gampad/jump?co=1&iu=/6978/reg_software/front&sz=300x50%7C300x100%7C300x250%7C300x251%7C300x252%7C300x600%7C300x601&tile=3&c=33YUIYvLNnyHImyTgv2HMSaAAAAJM&t=ct%3Dns%26unitnum%3D3%26raptor%3Deagle%26pos%3Dmid%26test%3D0

[15] https://lkml.org/lkml/2005/12/13/223

[16] https://www.theregister.com/2021/07/05/rust_for_linux_kernel_project/

[17] https://whitepapers.theregister.com/



karlkarl

"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)."

Agreed, the all variables at start of a block really isn't a problem. Especially since for those who do like variables located near to where they are used, the start of a block can also be within if and while statements. Not just at the start of the function.

As for for loops, this is possibly the only slightly annoying thing about C89. However for those projects where we do want to support simplistic / experimental compilers, the following is possible:

{size_t i = 0; for(; i < len; ++i) {

/* Use i */

}}

It possibly looks a little nasty but compared to the alternatives, I don't actually mind it. Though in this day and age C99 is generally the most common. I find C11 to be a little excessive. This shouldn't be like C++ where everyone chases version numbers like little fat kids wanting more, MORE, *MORE!* ;)

Dan 55

If you can only put variables at the start of a block and then you delete some code in a function, you're in danger of leaving some variables at the top which could be deleted.

I suppose they'll be optimised away in the object code, but the source code should be clean and understandable.

karlkarl

Very true.

The -Wall and -pedantic flags *should* pick up on unused variables. Though sometimes we don't always get to use such capable compilers ;)

Anonymous Coward

"Agreed, the all variables at start of a block really isn't a problem. Especially since for those who do like variables located near to where they are used, the start of a block can also be within if and while statements. Not just at the start of the function."

Actually, the fact it was not possible in C89 was the reason I switched to ADA, back in the 90s.

I was tired of reading single letter var names in messy code.

But sadly, my boss objected since I was the only one developing in ADA ;)

GTK3 to GTK4 is a MUCH MORE OBJECTIONABLE change.......

Anonymous Coward

It's taken me years to get my brain wrapped around using Glade, GTK3 and C......to the point that I can just about write stuff that works!!

*

Then I get GTK4. Just read the advice for converting GTK3 to GTK4. HUNDREDS of statements like "Do not do X".

*

....and Glade CAN'T be used with GTK4.

*

Some folk out there in the open source world JUST DON'T GET IT!!!!!!!!

*

gcc 4.9 to gcc 5.X......what's wrong with gcc11.2?......works fine here!!!

At the source of every error which is blamed on the computer you will find
at least two human errors, including the error of blaming it on the computer.