Linux size command, why are bss and data sections not zero?
Clash Royale CLAN TAG#URR8PPP
up vote
8
down vote
favorite
I came across the size command which gives the section size of the ELF file. While playing around with it, I created an output file for the simplest C++ program :
int main()return 0;
Clearly, I have not defined any initialized or uninitialized, data then why are my BSS and DATA sections of the size 512 and 8 bytes?
I thought it might be because of int main()
, I tried creating object file for the following C program :
void main()
I still don't get 0 for BSS and DATA sections.
Is it because a certain minimum sized memory is allocated to those section?
EDIT- I thought it might be because of linked libraries but my object is dynamically linked so probably it shouldn't be the issue
memory c c++ elf
migrated from unix.stackexchange.com Aug 22 at 13:32
This question came from our site for users of Linux, FreeBSD and other Un*x-like operating systems.
add a comment |Â
up vote
8
down vote
favorite
I came across the size command which gives the section size of the ELF file. While playing around with it, I created an output file for the simplest C++ program :
int main()return 0;
Clearly, I have not defined any initialized or uninitialized, data then why are my BSS and DATA sections of the size 512 and 8 bytes?
I thought it might be because of int main()
, I tried creating object file for the following C program :
void main()
I still don't get 0 for BSS and DATA sections.
Is it because a certain minimum sized memory is allocated to those section?
EDIT- I thought it might be because of linked libraries but my object is dynamically linked so probably it shouldn't be the issue
memory c c++ elf
migrated from unix.stackexchange.com Aug 22 at 13:32
This question came from our site for users of Linux, FreeBSD and other Un*x-like operating systems.
3
There is a static library for the C runtime which is linked by the compiler, and which includes the real entry point which calls main(). You should see the real entry point function e.g. if you runobjdump --disassemble
.objdump -f
will show information including the "start address".
â sourcejedi
Aug 22 at 7:13
I see a few libraries linked to my object when i run objdump on it, the ouput offile a.out
said it's dynamically linked ELF so i assumed there are no statically linked libraries, guess i was wrong.
â Time Traveller
Aug 22 at 7:20
2
Related: A Whirlwind Tutorial on Creating Really Teensy ELF Executables for Linux
â nxnev
Aug 22 at 7:37
1
Related: unix.stackexchange.com/questions/419697/⦠and unix.stackexchange.com/questions/418354/â¦
â Rui F Ribeiro
Aug 22 at 7:57
1
Compile it with -g and runnm
on it - you will see all the symbols in the elf file.
â filo
Aug 22 at 11:22
add a comment |Â
up vote
8
down vote
favorite
up vote
8
down vote
favorite
I came across the size command which gives the section size of the ELF file. While playing around with it, I created an output file for the simplest C++ program :
int main()return 0;
Clearly, I have not defined any initialized or uninitialized, data then why are my BSS and DATA sections of the size 512 and 8 bytes?
I thought it might be because of int main()
, I tried creating object file for the following C program :
void main()
I still don't get 0 for BSS and DATA sections.
Is it because a certain minimum sized memory is allocated to those section?
EDIT- I thought it might be because of linked libraries but my object is dynamically linked so probably it shouldn't be the issue
memory c c++ elf
I came across the size command which gives the section size of the ELF file. While playing around with it, I created an output file for the simplest C++ program :
int main()return 0;
Clearly, I have not defined any initialized or uninitialized, data then why are my BSS and DATA sections of the size 512 and 8 bytes?
I thought it might be because of int main()
, I tried creating object file for the following C program :
void main()
I still don't get 0 for BSS and DATA sections.
Is it because a certain minimum sized memory is allocated to those section?
EDIT- I thought it might be because of linked libraries but my object is dynamically linked so probably it shouldn't be the issue
memory c c++ elf
asked Aug 22 at 6:55
Time Traveller
migrated from unix.stackexchange.com Aug 22 at 13:32
This question came from our site for users of Linux, FreeBSD and other Un*x-like operating systems.
migrated from unix.stackexchange.com Aug 22 at 13:32
This question came from our site for users of Linux, FreeBSD and other Un*x-like operating systems.
3
There is a static library for the C runtime which is linked by the compiler, and which includes the real entry point which calls main(). You should see the real entry point function e.g. if you runobjdump --disassemble
.objdump -f
will show information including the "start address".
â sourcejedi
Aug 22 at 7:13
I see a few libraries linked to my object when i run objdump on it, the ouput offile a.out
said it's dynamically linked ELF so i assumed there are no statically linked libraries, guess i was wrong.
â Time Traveller
Aug 22 at 7:20
2
Related: A Whirlwind Tutorial on Creating Really Teensy ELF Executables for Linux
â nxnev
Aug 22 at 7:37
1
Related: unix.stackexchange.com/questions/419697/⦠and unix.stackexchange.com/questions/418354/â¦
â Rui F Ribeiro
Aug 22 at 7:57
1
Compile it with -g and runnm
on it - you will see all the symbols in the elf file.
â filo
Aug 22 at 11:22
add a comment |Â
3
There is a static library for the C runtime which is linked by the compiler, and which includes the real entry point which calls main(). You should see the real entry point function e.g. if you runobjdump --disassemble
.objdump -f
will show information including the "start address".
â sourcejedi
Aug 22 at 7:13
I see a few libraries linked to my object when i run objdump on it, the ouput offile a.out
said it's dynamically linked ELF so i assumed there are no statically linked libraries, guess i was wrong.
â Time Traveller
Aug 22 at 7:20
2
Related: A Whirlwind Tutorial on Creating Really Teensy ELF Executables for Linux
â nxnev
Aug 22 at 7:37
1
Related: unix.stackexchange.com/questions/419697/⦠and unix.stackexchange.com/questions/418354/â¦
â Rui F Ribeiro
Aug 22 at 7:57
1
Compile it with -g and runnm
on it - you will see all the symbols in the elf file.
â filo
Aug 22 at 11:22
3
3
There is a static library for the C runtime which is linked by the compiler, and which includes the real entry point which calls main(). You should see the real entry point function e.g. if you run
objdump --disassemble
. objdump -f
will show information including the "start address".â sourcejedi
Aug 22 at 7:13
There is a static library for the C runtime which is linked by the compiler, and which includes the real entry point which calls main(). You should see the real entry point function e.g. if you run
objdump --disassemble
. objdump -f
will show information including the "start address".â sourcejedi
Aug 22 at 7:13
I see a few libraries linked to my object when i run objdump on it, the ouput of
file a.out
said it's dynamically linked ELF so i assumed there are no statically linked libraries, guess i was wrong.â Time Traveller
Aug 22 at 7:20
I see a few libraries linked to my object when i run objdump on it, the ouput of
file a.out
said it's dynamically linked ELF so i assumed there are no statically linked libraries, guess i was wrong.â Time Traveller
Aug 22 at 7:20
2
2
Related: A Whirlwind Tutorial on Creating Really Teensy ELF Executables for Linux
â nxnev
Aug 22 at 7:37
Related: A Whirlwind Tutorial on Creating Really Teensy ELF Executables for Linux
â nxnev
Aug 22 at 7:37
1
1
Related: unix.stackexchange.com/questions/419697/⦠and unix.stackexchange.com/questions/418354/â¦
â Rui F Ribeiro
Aug 22 at 7:57
Related: unix.stackexchange.com/questions/419697/⦠and unix.stackexchange.com/questions/418354/â¦
â Rui F Ribeiro
Aug 22 at 7:57
1
1
Compile it with -g and run
nm
on it - you will see all the symbols in the elf file.â filo
Aug 22 at 11:22
Compile it with -g and run
nm
on it - you will see all the symbols in the elf file.â filo
Aug 22 at 11:22
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
8
down vote
accepted
In fact, if you are compiling with the libc attached to the binary, there are functions that are added before (and after) the main()
function. They are here mostly to load dynamic libraries (even if you do not need it in your case) and unload it properly once main()
end.
These functions have global variables that require storage; uninitialized (zero initialized) global variables in the BSS segment and initialized global variables in the DATA segment.
This is why, you will always see BSS and DATA in all the binaries compiled with the libc. If you want to get rid of this, then you should write your own assembly program, like this (asm.s
):
.globl _start
ÃÂ _start:
mov %eax, %ebx
And, then compile it without the libc:
$> gcc -nostdlib -o asm asm.s
You should reduce your footprint to the BSS and DATA segment on this ELF binary.
Thank you! I figured out my mistake, time to brush up my concepts of gcc and linking libraries.
â Time Traveller
Aug 22 at 7:25
1
No problem, this field is huge! You have to start somewhere! Good luck and keep going! :)
â perror
Aug 22 at 7:26
Please be more precise: "These functions use a little bit of memory that is taken from the BSS and the DATA segment." could better be told as "These functions have global variables that require storage; uninitialized (zero initialized) global variables in the BSS segment and initialized global variables in the DATA segment"
â Paul Ogilvie
Aug 22 at 13:43
add a comment |Â
up vote
8
down vote
int main()return 0;
puts data in .text
only.
$ echo 'int main()return 0;' | gcc -xc - -c -o main.o && size main.o
text data bss dec hex filename
67 0 0 67 43 main.o
You're probably size
ing a fully linked executable.
$ gcc main.o -o main && size main
text data bss dec hex filename
1415 544 8 1967 7af main
thank you! i figured out my mistake :)
â Time Traveller
Aug 22 at 7:25
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
8
down vote
accepted
In fact, if you are compiling with the libc attached to the binary, there are functions that are added before (and after) the main()
function. They are here mostly to load dynamic libraries (even if you do not need it in your case) and unload it properly once main()
end.
These functions have global variables that require storage; uninitialized (zero initialized) global variables in the BSS segment and initialized global variables in the DATA segment.
This is why, you will always see BSS and DATA in all the binaries compiled with the libc. If you want to get rid of this, then you should write your own assembly program, like this (asm.s
):
.globl _start
ÃÂ _start:
mov %eax, %ebx
And, then compile it without the libc:
$> gcc -nostdlib -o asm asm.s
You should reduce your footprint to the BSS and DATA segment on this ELF binary.
Thank you! I figured out my mistake, time to brush up my concepts of gcc and linking libraries.
â Time Traveller
Aug 22 at 7:25
1
No problem, this field is huge! You have to start somewhere! Good luck and keep going! :)
â perror
Aug 22 at 7:26
Please be more precise: "These functions use a little bit of memory that is taken from the BSS and the DATA segment." could better be told as "These functions have global variables that require storage; uninitialized (zero initialized) global variables in the BSS segment and initialized global variables in the DATA segment"
â Paul Ogilvie
Aug 22 at 13:43
add a comment |Â
up vote
8
down vote
accepted
In fact, if you are compiling with the libc attached to the binary, there are functions that are added before (and after) the main()
function. They are here mostly to load dynamic libraries (even if you do not need it in your case) and unload it properly once main()
end.
These functions have global variables that require storage; uninitialized (zero initialized) global variables in the BSS segment and initialized global variables in the DATA segment.
This is why, you will always see BSS and DATA in all the binaries compiled with the libc. If you want to get rid of this, then you should write your own assembly program, like this (asm.s
):
.globl _start
ÃÂ _start:
mov %eax, %ebx
And, then compile it without the libc:
$> gcc -nostdlib -o asm asm.s
You should reduce your footprint to the BSS and DATA segment on this ELF binary.
Thank you! I figured out my mistake, time to brush up my concepts of gcc and linking libraries.
â Time Traveller
Aug 22 at 7:25
1
No problem, this field is huge! You have to start somewhere! Good luck and keep going! :)
â perror
Aug 22 at 7:26
Please be more precise: "These functions use a little bit of memory that is taken from the BSS and the DATA segment." could better be told as "These functions have global variables that require storage; uninitialized (zero initialized) global variables in the BSS segment and initialized global variables in the DATA segment"
â Paul Ogilvie
Aug 22 at 13:43
add a comment |Â
up vote
8
down vote
accepted
up vote
8
down vote
accepted
In fact, if you are compiling with the libc attached to the binary, there are functions that are added before (and after) the main()
function. They are here mostly to load dynamic libraries (even if you do not need it in your case) and unload it properly once main()
end.
These functions have global variables that require storage; uninitialized (zero initialized) global variables in the BSS segment and initialized global variables in the DATA segment.
This is why, you will always see BSS and DATA in all the binaries compiled with the libc. If you want to get rid of this, then you should write your own assembly program, like this (asm.s
):
.globl _start
ÃÂ _start:
mov %eax, %ebx
And, then compile it without the libc:
$> gcc -nostdlib -o asm asm.s
You should reduce your footprint to the BSS and DATA segment on this ELF binary.
In fact, if you are compiling with the libc attached to the binary, there are functions that are added before (and after) the main()
function. They are here mostly to load dynamic libraries (even if you do not need it in your case) and unload it properly once main()
end.
These functions have global variables that require storage; uninitialized (zero initialized) global variables in the BSS segment and initialized global variables in the DATA segment.
This is why, you will always see BSS and DATA in all the binaries compiled with the libc. If you want to get rid of this, then you should write your own assembly program, like this (asm.s
):
.globl _start
ÃÂ _start:
mov %eax, %ebx
And, then compile it without the libc:
$> gcc -nostdlib -o asm asm.s
You should reduce your footprint to the BSS and DATA segment on this ELF binary.
edited Aug 22 at 13:45
answered Aug 22 at 7:22
perror
4,386124362
4,386124362
Thank you! I figured out my mistake, time to brush up my concepts of gcc and linking libraries.
â Time Traveller
Aug 22 at 7:25
1
No problem, this field is huge! You have to start somewhere! Good luck and keep going! :)
â perror
Aug 22 at 7:26
Please be more precise: "These functions use a little bit of memory that is taken from the BSS and the DATA segment." could better be told as "These functions have global variables that require storage; uninitialized (zero initialized) global variables in the BSS segment and initialized global variables in the DATA segment"
â Paul Ogilvie
Aug 22 at 13:43
add a comment |Â
Thank you! I figured out my mistake, time to brush up my concepts of gcc and linking libraries.
â Time Traveller
Aug 22 at 7:25
1
No problem, this field is huge! You have to start somewhere! Good luck and keep going! :)
â perror
Aug 22 at 7:26
Please be more precise: "These functions use a little bit of memory that is taken from the BSS and the DATA segment." could better be told as "These functions have global variables that require storage; uninitialized (zero initialized) global variables in the BSS segment and initialized global variables in the DATA segment"
â Paul Ogilvie
Aug 22 at 13:43
Thank you! I figured out my mistake, time to brush up my concepts of gcc and linking libraries.
â Time Traveller
Aug 22 at 7:25
Thank you! I figured out my mistake, time to brush up my concepts of gcc and linking libraries.
â Time Traveller
Aug 22 at 7:25
1
1
No problem, this field is huge! You have to start somewhere! Good luck and keep going! :)
â perror
Aug 22 at 7:26
No problem, this field is huge! You have to start somewhere! Good luck and keep going! :)
â perror
Aug 22 at 7:26
Please be more precise: "These functions use a little bit of memory that is taken from the BSS and the DATA segment." could better be told as "These functions have global variables that require storage; uninitialized (zero initialized) global variables in the BSS segment and initialized global variables in the DATA segment"
â Paul Ogilvie
Aug 22 at 13:43
Please be more precise: "These functions use a little bit of memory that is taken from the BSS and the DATA segment." could better be told as "These functions have global variables that require storage; uninitialized (zero initialized) global variables in the BSS segment and initialized global variables in the DATA segment"
â Paul Ogilvie
Aug 22 at 13:43
add a comment |Â
up vote
8
down vote
int main()return 0;
puts data in .text
only.
$ echo 'int main()return 0;' | gcc -xc - -c -o main.o && size main.o
text data bss dec hex filename
67 0 0 67 43 main.o
You're probably size
ing a fully linked executable.
$ gcc main.o -o main && size main
text data bss dec hex filename
1415 544 8 1967 7af main
thank you! i figured out my mistake :)
â Time Traveller
Aug 22 at 7:25
add a comment |Â
up vote
8
down vote
int main()return 0;
puts data in .text
only.
$ echo 'int main()return 0;' | gcc -xc - -c -o main.o && size main.o
text data bss dec hex filename
67 0 0 67 43 main.o
You're probably size
ing a fully linked executable.
$ gcc main.o -o main && size main
text data bss dec hex filename
1415 544 8 1967 7af main
thank you! i figured out my mistake :)
â Time Traveller
Aug 22 at 7:25
add a comment |Â
up vote
8
down vote
up vote
8
down vote
int main()return 0;
puts data in .text
only.
$ echo 'int main()return 0;' | gcc -xc - -c -o main.o && size main.o
text data bss dec hex filename
67 0 0 67 43 main.o
You're probably size
ing a fully linked executable.
$ gcc main.o -o main && size main
text data bss dec hex filename
1415 544 8 1967 7af main
int main()return 0;
puts data in .text
only.
$ echo 'int main()return 0;' | gcc -xc - -c -o main.o && size main.o
text data bss dec hex filename
67 0 0 67 43 main.o
You're probably size
ing a fully linked executable.
$ gcc main.o -o main && size main
text data bss dec hex filename
1415 544 8 1967 7af main
answered Aug 22 at 7:18
PSkocik
27.9k43762
27.9k43762
thank you! i figured out my mistake :)
â Time Traveller
Aug 22 at 7:25
add a comment |Â
thank you! i figured out my mistake :)
â Time Traveller
Aug 22 at 7:25
thank you! i figured out my mistake :)
â Time Traveller
Aug 22 at 7:25
thank you! i figured out my mistake :)
â Time Traveller
Aug 22 at 7:25
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f51968080%2flinux-size-command-why-are-bss-and-data-sections-not-zero%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
3
There is a static library for the C runtime which is linked by the compiler, and which includes the real entry point which calls main(). You should see the real entry point function e.g. if you run
objdump --disassemble
.objdump -f
will show information including the "start address".â sourcejedi
Aug 22 at 7:13
I see a few libraries linked to my object when i run objdump on it, the ouput of
file a.out
said it's dynamically linked ELF so i assumed there are no statically linked libraries, guess i was wrong.â Time Traveller
Aug 22 at 7:20
2
Related: A Whirlwind Tutorial on Creating Really Teensy ELF Executables for Linux
â nxnev
Aug 22 at 7:37
1
Related: unix.stackexchange.com/questions/419697/⦠and unix.stackexchange.com/questions/418354/â¦
â Rui F Ribeiro
Aug 22 at 7:57
1
Compile it with -g and run
nm
on it - you will see all the symbols in the elf file.â filo
Aug 22 at 11:22