Re: Same code but different objects layout = different output object size

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 20 Feb 2008 14:35:56 -0600
John Love-Jensen <eljay@xxxxxxxxx> wrote:

We have next files:
cat << EOF > full.c
#include <stdio.h>

void imprime(const char *m)
{
        printf("%s\n", m);
}

int main()
{
        imprime("Beautiful day");
        return 0;
}
EOF
cat << EOF > a.c
void imprime(const char *m);
int main()
{
        imprime("Beautiful day");
        return 0;
}
EOF
cat << EOF > b.c
#include <stdio.h>
void imprime(const char *m)
{
        printf("%s\n", m);
}
EOF

Now,
gcc a.c b.c -o ab
"a.c" and "b.c" built "ab"

gcc full.c -o full
"full.c" built "full"

In comparing files sizes (Target:amd64):
du -b full
8396
du -b ab
8453

Therefore, ab > full

> Hi Felipe,
> 
> > Well, the problem is when I split a C source file into two files. Output
> > object size of splitted source is bigger than size of one-file source. My
> > question to mail list is Why? What happens? What section grows up?
> 
> Are you including or excluding the object header block?
In object header section, ".comment" section has different size.
.comment size of full is 000000f3
.comment size of ab is 00000114

That only explains 33 bytes between "ab" and "full". In ab, ld puts
together .comment of "a.s" and "b.s".

do I could avoid this?

> What does the assembly (.s) of the two files indicate when you use a
> --save-temps?
Function main() in "a.s" has one more instruction.
main:
.LFB2:
        pushq   %rbp
.LCFI0:
        movq    %rsp, %rbp
.LCFI1:
        movl    $.LC0, %edi
        movl    $0, %eax
        call    imprime
        movl    $0, %eax
        leave
        ret

and in "full.s":
main:
.LFB3:
        pushq   %rbp
.LCFI3:
        movq    %rsp, %rbp
.LCFI4:
        movl    $.LC0, %edi
        call    imprime
        movl    $0, %eax
        leave
        ret

> 
> What does an object dump of the single .o versus the two separated .o files
> indicate?
A different NOP padding in .text and more text in .comment
> --Eljay
> 


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux