[coreboot] cross gcc 4.7.2 bit filed issue

WANG Siyuan wangsiyuanbuaa at gmail.com
Fri Feb 1 10:41:33 CET 2013

I found an issue of cross gcc built by util/crossgcc/buildgcc
take this piece of code as an example

struct st{
        unsigned int a:12;

then I declare a variable:
struct st m;

This is my test result:
1) If I compile it by host gcc, sizeof(m) is 4.

2) If I put these codes in a coreboot mainboard, build it by cross
gcc. use printk to print the length.
sizeof(m) is 2.

3) If I use cross gcc, compile the code use "-c" flag (put these code
in size.c, not put it in a mainboard's source)
use "nm --format sysv size.o" to check, the length is 4

Name                  Value   Class        Type         Size     Line  Section

m                  |00000004|   C  |            OBJECT|00000004|     |*COM*

My question is:
Although 12 bits only take 2 Bytes, in the struct I declare it as
unsigned int. So sizeof(m) should be 4. Why it is 2 when building it
in coreboot?

About test 3:
coreboot's cross gcc doesn't have C Library, so I declare a global
variable and use nm to check the size.

Yours sincerely,
WANG Siyuan

More information about the coreboot mailing list