Is it possible to get the exact PC address of an instruction?

I wish to perform some instrumentation at a particular PC address/instruction using LLVM and I wished to know if getting the PC address of the instruction is in fact possible given the nature of the llvm compiler? For instance, I wish to inject a fault multiple times at the same instruction address and analyze this behavior. I wish to get the PC address of the instruction so as to be able to point to it as my injection target for all my runs.

Hello Abhay,

Are you talking about fault injection at runtime? With an instruction generated from C/C++ source? I can imagine using a label in the source code, and finding the address of that label afterward, which limits you to the first instruction generated after the label.

But in the general case, if I had to do this myself, I’d probably end up disassembling the object file to find the instruction of interest; or generating asm source (with -S) and inserting a label before running it through the assembler. None of these tactics do anything clever within LLVM, it would work with any toolchain.

Good luck,

–paulr