Skip to content
Advertisement

SIZE command in UNIX

The following is my C file:

JavaScript

It contains only return statement. But if I use the size command, it shows the output like this:

JavaScript

Even though my program does not contain any global variable, or undeclared data. But, the output shows data segment have 252 and the bss have 8 bytes. So, why the output is like this? what is 252 and 8 refers.

Advertisement

Answer

Size Command

First see the definition of each column:

  • text – Actual machine instructions that your CPU going to execute. Linux allows to share this data.
  • data – All initialized variables (declarations) declared in a program (e.g., float salary=123.45;).
  • bss – The BSS consists of uninitialized data such as arrays that you have not set any values to or null pointers.

As Blue Moon said. On Linux, the execution starts by calling _start() function. Which does environment setup. Every C program has hidden “libraries” that depends on compilator you using. There are settings for global parameters, exit calls and after complete configuration it finally calls your main() function. ASFAIK there’s no way to see how your code looks encapsulated with configuration and _start() function. But I can show you that even your code contains more information than you thought the closer to hardware we are.

Hint: Type readelf -a a.out to see how much information your exec really carrying.

What is inside?

Do not compare code in your source file to the size of executable file, it depends on the OS, compilator, and used libraries.

In my example, with exactly the same code, SIZE returns:

JavaScript

Let’s see what is inside…

JavaScript

This will run the preprocessor over a.c, perform the initial compilation and then stop before the assembler is run.

JavaScript

Then look on the assembly code

JavaScript

Next step would converting above code to 01 notation.

As you can see. Even simple c program contains complicated operation the closer to hardware your code is. I hope I have explained to you why the executable file is bigger than you thought. If you have any doubts, feel free to comment my post. I will edit my answer immediately.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement