1

I run pintool 'instCount' on basic C program with empty body within the main function.

int main() {

}

When I run the instCount on this program executable , it shows around 86000 instructions. Even the program is very small why so many instructions are genrated..??Any idea.??

Thank you

ANTHONY
  • 333
  • 5
  • 18

1 Answers1

4

What's missing is that behind the scenes, a lot of work is done to get you up to the point where the main() function is executed. There is a lot of work that the runtime needs to perform in order to provide the environment as you expect to get it. For example:

  • Libraries must be loaded and initialized.
  • Internal data structures (e.g. the dynamic memory allocator) need to be allocated and initialized.
  • There are various factors in the environment that may change the way the runtime should be have. This needs to be checked and also acted upon.

The things I listed are just a very partial list of what happens during startup. Similar things occur during shutdown which also add to the instruction count.

nitzanms
  • 1,786
  • 12
  • 35
  • Can you elaborate more on "environment" that you are talking about.Secondly, even though I'm not including any header files why it has to load libraries.!? – ANTHONY Jan 11 '16 at 08:03
  • In Unix, for example, an environment variable called LD_PRELOAD may mean that certain libraries need to be loaded even if the program didn't request them to be loaded. – nitzanms Jan 11 '16 at 08:31
  • @ANTHONY I'm afraid that explaining the intricacies of how files are loaded is a little beyond the scope of this question. I recommend that you give the following link a look to see a little of what happens during startup: http://dbp-consulting.com/tutorials/debugging/linuxProgramStartup.html – nitzanms Jan 11 '16 at 08:35
  • In C, header files have nothing to do with libraries being loaded or not, they are simply there to allow the compiler to see definitions for stuff in places outside the source file currently being compiled. – nitzanms Jan 11 '16 at 08:40