linuxbios and gcc 3.2: got it.

Ronald G. Minnich rminnich at lanl.gov
Tue Dec 3 10:32:00 CET 2002


it's a fundamental disagreement between 3.2 and 2.96. I think 3.2 is 
right, 2.96 is wrong. But it bit us, because we conformed to 2.96 usage.

Consider the following:
struct thing { int z; }; 
struct thingy {  int a; struct thing t[1]; };

This is like our irq_table struct now. We wish to have the array t be 
variable-sized, and the way you get that in gcc 2 is to just initialize it 
as needed:

struct thingy x = {1, {{2}, {3}}};

t will be forced to grow as needed. 

What a kludge! We declare it as t[1], but then grow it by making the 
initializer too big!

What does gcc 3.2 do with this? Well, that's a good question. I've seen a 
few different results from gcc:
- complain, and product a truncated output file with no entries
- not even produce an output file. 
- in no case does what it does match what gcc 2 did

gcc 3.2 does the sane thing in my view. If you make the array [1], that's 
all you should get. Growing it with too big an initializer is ugly!

So how to declare this? Like this:

struct thing { int z; }; 
struct thingy {  int a; struct thing t[]; };
                                     ^^^
struct thingy x = {1, {{2}, {3}}};

This works fine. I am going to modify the irq_table struct, since gcc296 
complains about the [] but still produces the right code. 

My mistake was zeroing in on the mptable, not the irq_table, because I 
forgot that our phase 1 image in IDE-flash is a non-SMP kernel. But it was 
a good thing in the end as I found this nasty non-compliant (for 3.2) bit 
of code in linuxbios.

ron




More information about the coreboot mailing list