1

I tried to count the number of instructions for an application that only prints out "Hello, World!" with the given instruction counting tool. (which is located at ./pin/source/tools/ManualExamples/inscount)

And I wondered if there is any difference between static linking and dynamic linking.

So I compiled in the following manners.

  • g++ -o hello_dynamic hello.cc

  • g++ -o hello_static hello.cc -static.

When I instrumented them, I've noticed that statically compiled executable and dynamically compiled executable shows quite different results.

  • Dynamically compiled file's instruction counts: 2060434

  • Statically compiled file's instruction counts: 82239

The dynamically compiled file shows roughly 25 times many instructions.

I might think no matter how they are compiled, they need to execute the same number of instructions.

I wonder what makes the results so different between them.

It would be appreciated if anyone could help me find out the reason.

Thanks,

Tae
  • 125
  • 5
  • 2
    Dynamic linking runs instructions in the process to resolve dynamic library symbols; the whole point of dynamic linking is to defer some of it until runtime, which of course means executing instructions in the context of that process. – Peter Cordes May 19 '20 at 06:18
  • What does the tool count? Instructions in the program or instructions executed at runtime (both times with the same input)? Does it count only the program's instructions or also instructions from the called system functions/libraries. – Werner Henze May 19 '20 at 06:21
  • @WernerHenze, Tool source code says that it counts the number of dynamic instructions executed. According to the post on StackOverflow, the dynamic instruction count is the actual number of instructions executed by CPU. (https://stackoverflow.com/questions/13458135/dynamic-vs-static-instruction-count) – Tae May 19 '20 at 06:54
  • @PeterCordes, I might think this pin tool counts the number of instructions at runtime. I am not sure they have a different number of instructions in this case. – Tae May 19 '20 at 07:13
  • For a start you can test with an empty `main`. Then you have the overhead of the dynamic linking. The overload comes, as Peter said, from the loading of the libraries. Then you can add your code and check how much instructions that adds in each case. – Werner Henze May 19 '20 at 17:57

0 Answers0