0

I've been counting the instructions executed by an empty C program using Intel's Pin. Most of the time I get a total instruction count of 118724, but now and then the count goes up to 118770. What can be the reason for this change?

Code run: int main() {}

  • Is it the same executable you run all the time? It's not different builds of the same source? – Some programmer dude Jun 10 '19 at 10:24
  • Yes, I compiled the code once, then ran it multiple times. – JustAnotherUser Jun 10 '19 at 10:27
  • Sounds like a bad tool...? – Lundin Jun 10 '19 at 10:31
  • check the RTL output and assembler output. If they are different then it's a problem from compiler. Ifnot, it is in the backend – alinsoar Jun 10 '19 at 10:33
  • Could it instrument some of its own inserted instructions? Perhaps there are some signals, interrupts, or other OS-specific processing happening that gets instrumented? – Some programmer dude Jun 10 '19 at 10:33
  • I used gcc without any flags. Is there a simply way of comparing the RTL and assembler output? Maybe due to my lack of knowledge on the subject and due to this being the first time I see RTL, there is no obvious way for me to compare the two. I used the -S switch and -da switch for gcc respectively to get the outputs. – JustAnotherUser Jun 10 '19 at 10:59
  • I think it's unlikely that it counts it's own instructions since what it does is JITing the binary and runs some C++ code that increments a counter between every instruction it finds in the binary. – JustAnotherUser Jun 10 '19 at 11:03
  • 1
    No it obviously doesn't count its own instruction. But be wary that PIN starts very early in the process life, so it starts instrumenting everything the system loader is doing (basically in the libc). The fact that you have two different instruction count is probably due to a if / else branch somewhere in the ELF loading code (depending of the system state at a 't' time). If this bothers you you can restrict the instrumentation code to your own binary if you wish. – Neitsa Jun 11 '19 at 12:28
  • Thank you, I'd say this most likely answers my question. – JustAnotherUser Jun 22 '19 at 17:25

1 Answers1

0

I feel like @Neitsa answered my question in their comment to the original post. I'll quote it here.

But be wary that PIN starts very early in the process life, so it starts instrumenting everything the system loader is doing (basically in the libc). The fact that you have two different instruction count is probably due to a if / else branch somewhere in the ELF loading code (depending of the system state at a 't' time). If this bothers you you can restrict the instrumentation code to your own binary if you wish.