|
|
Log in / Subscribe / Register

grsecurity: Teardown of a Failed Linux LTS Spectre Fix

grsecurity: Teardown of a Failed Linux LTS Spectre Fix

Posted Sep 4, 2019 9:37 UTC (Wed) by niner (guest, #26151)
Parent article: grsecurity: Teardown of a Failed Linux LTS Spectre Fix

So all this started when the compiler threw a warning about something that shouldn't be a problem in any way: "ISO C90 forbids mixed declarations and code". Why is the kernel compiled as C90? This restriction adds now value and constantly trips up developers. I don't think anybody would seriously expect the kernel to compile on a > 20 year old compiler that doesn't support C99.


to post comments

grsecurity: Teardown of a Failed Linux LTS Spectre Fix

Posted Sep 4, 2019 11:20 UTC (Wed) by Wol (subscriber, #4433) [Link] (3 responses)

But IS IT compiled as C90?

Or is the compiler merely saying "if you feed this to a C90 compiler, it will fail ..."

Cheers,
Wol

grsecurity: Teardown of a Failed Linux LTS Spectre Fix

Posted Sep 4, 2019 11:28 UTC (Wed) by edomaur (subscriber, #14520) [Link]

It is. It's "C89+extensions".

grsecurity: Teardown of a Failed Linux LTS Spectre Fix

Posted Sep 4, 2019 12:48 UTC (Wed) by Paf (subscriber, #91811) [Link] (1 responses)

I’m pretty sure this restriction - which I do think adds value but I’m not going in that particular bikeshed - is part of all the C specs *since* C90, so... yeah. No issue with supporting old compilers. So if you want to get rid of it, you will have to go in that specific bikeshed. It says “standards committee” on the side, and I hear they keep dogs inside. Big, angry ones.

grsecurity: Teardown of a Failed Linux LTS Spectre Fix

Posted Sep 4, 2019 12:57 UTC (Wed) by niner (guest, #26151) [Link]

From gcc(1): "Warn when a declaration is found after a statement in a block. This construct, known from C++, was introduced with ISO C99 and is by default allowed in GCC. It is not supported by ISO C90."

So old C versions required all declarations to appear first in a block. C++ removed that requirement and the ISO standards committee backported that relaxation of the rules to C99.

grsecurity: Teardown of a Failed Linux LTS Spectre Fix

Posted Sep 4, 2019 20:35 UTC (Wed) by dezgeg (guest, #92243) [Link] (3 responses)

I belive the kernel intentionally doesn't use C99 because the ability to declare variables in the middle of a basic block is seen as a bad feature, see for example https://lkml.org/lkml/2012/4/12/18.

(I personally find that forcing declarations to happen at start of blocks is a great way to introduce uninitialized variable-related bugs).

grsecurity: Teardown of a Failed Linux LTS Spectre Fix

Posted Sep 4, 2019 22:04 UTC (Wed) by adobriyan (guest, #30858) [Link] (1 responses)

It is one of the silly rules indeed. Writing "for (int i = 0; i < N; i++)" is clearly superior.

grsecurity: Teardown of a Failed Linux LTS Spectre Fix

Posted Sep 9, 2019 23:14 UTC (Mon) by mangix (guest, #126006) [Link]

for (auto i...) is better still. But C++11.

grsecurity: Teardown of a Failed Linux LTS Spectre Fix

Posted Sep 8, 2019 6:06 UTC (Sun) by marcH (subscriber, #57642) [Link]

> (I personally find that forcing declarations to happen at start of blocks is a great way to introduce uninitialized variable-related bugs).

When you use a programming language designed for memory corruption, you want to make the most of it. /s


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds