问题描述:

I have this simple code.

#include<stdio.h>

int main()

{

return 0;

}

running the size command on the executable show the following output

 text data bss dec hex filename

1053 276 4 1333 535 a.out

My question is , even though i don't have any unintialised global or static variable, why does bss has 4 bytes?

网友答案:

You link your code against the standard C library. Specifically, you link against code that runs before main() starts and again after main() returns.

That code has data and bss requirements.

If you want to avoid those requirements, you can try linking without the standard library:

$ gcc  -nostartfiles -nostdlib -nodefaultlibs x.c
$ size a.out
  text     data     bss     dec     hex filename
   118        0       0     118      76 a.out

Of course, then you'll need to make other (significant!) changes to your program:

$ cat x.c 
void _start() {
  __asm("mov $1, %eax; mov %eax,%ebx; int $0x80");
}

References:

  • http://www.muppetlabs.com/~breadbox/software/tiny/teensy.html
  • http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html#Link-Options
相关阅读:
Top