Alignment of LinuxBIOS table structures

Stefan Reinauer stepan at openbios.org
Tue Nov 30 03:24:00 CET 2004


* Eric W. Biederman <ebiederman at lnxi.com> [041129 19:21]:
> To see what the problem actually amounts to I walked through my
> compiler collection with a simple test to see what sizeof reported
> for lb_memory_range, (without adding the packed attribute).
 
> On 32bit x86 I tested with:
> gcc-2.7.2
> gcc-2.95
> gcc-3.0
> gcc-3.2
> gcc-3.3
> gcc-3.4
> 
> And in each instance the result was 20. 
 
> So from what I can see with 32bit x86 code we are consistent, and we
> do not have compiler version dependencies.   So the bad definition
> is consistent.

x86 QNX/Neutrino 6.2.1 (with gcc 2.95.3):
# gcc -v
Reading specs from /usr/lib/gcc-lib/ntox86/2.95.3qnx-nto/specs
gcc version 2.95.3qnx-nto 20010315 (release)

sizeof(lb_memory_range): 24
sizeof(struct lb_memory): 8

It seems gcc does not always behave the same. 

> It is a good pragmatic solution, but actually needing __attribute__ ((packed))
> is an issue.  As Ron has pointed out, not all compilers support it.
> And having a definition that varies between 32bit and 64bit is a
> problem anyway.
 
So you are saying people out there are building LinuxBIOS with non-gnu 
compilers? I actually doubt that, assuming a lot of objcopy/objdump/ld
magic is pretty much gnu specific as well.. 

one could go like:

#ifdef __GNUC__
#define STRICTSIZE __attribute__ ((packed))
#else
#define STRICTSIZE 
#endif

Fixing the issue among all gcc versions while not breaking anything on
others. It really sucks that gcc does magic here that makes writing
portable code really ugly.

Stefan




More information about the coreboot mailing list