ELF weirdness

H.J. Lu hjl@nynexst.com
Mon Nov 27 20:01:00 GMT 1995

> This is an ELF-specific question, so I thought I'd ask you before
> looking further.  I'm running gcc 2.7.0.  I have not yet installed
> 2.7.1.  Compiling this program with "gcc foo.c -o foo":
> int
> main (void)
> {
>   static int x __attribute__ ((aligned (16)));
>   return 0;
> }
> Results in this error:
> gwar:~$ gcc foo.c -o foo
> foo: Not enough room for program headers (allocated 5, need 6)
> /usr/i486-linux/bin/ld: final link failed: Bad value
> Compiling with "gcc -b i486-linuxaout foo.c -o foo" works fine.
> Does this happen to you?  Is this a known bug?  Thanks!

It looks like a gcc/gas bug. In c-common.c around line 515, there is

	align = TREE_INT_CST_LOW (align_expr) * BITS_PER_UNIT;

It seems to work ok with the a.out format. But the gcc for x86/ELF
outputs the .comm stuff differently depending on if the symbol is
local or not. If it is local, the alignment will be divided by
BITS_PER_UNIT. If the source code is changed to

static int x __attribute__ ((aligned (16))) = 0;

gcc will complain:

warning: alignment of `x' is greater than maximum object file alignment

But gas seems not in sync with gcc. I don't know who is correct. I think
gas may be correct. Gcc may be changed to

	align = TREE_INT_CST_LOW (align_expr)

and output local symbols with log2 (align) instead of divide it by
BITS_PER_UNIT. But I don't know if the changes will work on all


More information about the Gas2 mailing list