Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 20 Nov 2001 20:06:23 +0800 (CST)
From:      freebsd@hoolan.org
To:        freebsd-hackers@freebsd.org
Subject:   c++ compiler allocates uninitialized global variable in .data section
Message-ID:  <Pine.BSF.4.05.10111162100300.28821-100000@hoolan.org>

next in thread | raw e-mail | index | archive | help

I found that c++ compiler (4.4-RELEASE) allocates uninitialized global
variable in the data section instead of the bss section. Here is my
code sample (b.cpp):

char aa[1024*1024*10];

void f(void)
{
}

after c++ -c b.cpp I get a nearly 10MB object file, whereas on linux
(RedHat 7.2, gcc-2.96-98) it produces a file less than 1kB. So I
assemble it to find the diffenece.

on FreeBSD:

.globl aa
.data
        .p2align 5
        .type    aa,@object
        .size    aa,10485760
aa:
        .zero   10485760

but on Linux:

.globl aa
.bss
        .align 32
        .type    aa,@object
        .size    aa,10485760
aa:
        .zero   10485760

In consequence, that's why I get a huge object file with FreeBSD c++.
Is this behavior of c++ correct? I suppose uninitialized data should
goes to .bss section according to elf(5).


Regards,
Jeffrey Tang



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.05.10111162100300.28821-100000>