svn commit: r216161 - in head/sys: amd64/amd64 i386/i386

Bruce Evans brde at optusnet.com.au
Sat Dec 4 11:44:47 UTC 2010


On Sat, 4 Dec 2010, Kostik Belousov wrote:

> On Sat, Dec 04, 2010 at 11:36:25AM +0100, Roman Divacky wrote:
>> On Fri, Dec 03, 2010 at 06:17:16PM -0500, Jung-uk Kim wrote:
> ...
>>>> I just tried it.  GCC generates identical binaries as I thought.
>>>> However, Clang doesn't do the optimization. :-/
>>>
>>> Strangely, Clang increases .bss when a global variable is explicitly
>>> initialized to zero.
>>>
>>> -  2 .bss 00000004 0000000000000000 0000000000000000 00000540 2**2
>>> +  2 .bss 00000014 0000000000000000 0000000000000000 00000540 2**3
>>
>> in my naive test gcc produces:
>>
>> .globl foo
>> 	.section	.bss
>> 	.align 4
>> 	.type	foo, @object
>> 	.size	foo, 4
>> foo:
>> 	.zero	4
>>
>>
>> and clang produces:
>>
>> 	.type	foo, at object             # @foo
>> 	.bss
>> 	.globl	foo
>> 	.align	4
>> foo:
>> 	.long	0                       # 0x0
>> 	.size	foo, 4
>>
>> ie. both put them into BSS
> I have no idea how and where your gcc is configured, in particular, I
> find the non-documenting directive .zero somewhat puzzling.

All of gcc-3.3.3 on i386 on my local system, and gcc-4.2.1 on amd64 and i386
on FreeBSD cluseter machines produce the .zero, and either the .align or
the .p2align.  I think '.zero 4' is just a spelling of '.long 0' if longs
have size 4.  Not clear why the clang asm generates a different object.

> Behaviour of clang looks like a plain bug, since initialized objects must
> be put into the .data section, not into .bss.

Note that gcc does this too in the above.  The above is for explicitly
initialized (to 0) objects.  Such objects can be put in the bss just as
validly as implicitly initialized (to 0) ones.

> Both gcc 4.2.1/FreeBSD and plain 4.5.1 produce
>   .comm   foo,4,4
> when compiling the file consisting of
> long foo;
> line. For amd64, substitute 4 by 8.

Now the initialization is implicit.

I guess the difference is to preserve the possibility of laying out the
objects using explicit initialization.  Hmm, this only works if they
are all explicitly initialized to 0 -- others cannot remain adjacent
since they musyt be moved to put them in the data section.  Of course,
C doesn't require anything for the layout.  ABIs might, but I don't
know of any other than defacto ones.

Bruce


More information about the svn-src-head mailing list