Intel Pin Tool; Setting up in 5 easy steps

on Reading Time: 2 minutes

This is the beginning of the Intel Pin Tool Series. Most of the online resources regarding Pin Tool waste the valuable time of the reader by not getting to the point directly. I intend to present a clear blog series which will help a beginner to familiarize with the Pin Tool in no time. Having read this post, you will be able to set up Intel pin tool and run a basic example to count the number of instructions in your program.

Step 1

Download the pin tool from Intel (https://software.intel.com/en-us/articles/pin-a-binary-instrumentation-tool-downloads). Select the appropriate operating system and copy the download link. For example,

wget https://software.intel.com/sites/landingpage/pintool/downloads/pin-3.7-97619-g0d0c92f4f-gcc-linux.tar.gz -P /tmp/

Step 2

Extract the file that you have downloaded.

tar -zxvf pin-3.7-97619-g0d0c92f4f-gcc-linux.tar.gz

This section is optional. But if you are intending to use the tool on a regular basis, I would strongly suggest that you extract it into /opt directory and that you create a symbolic link so that you could manage versions in the future easily.

sudo cp /tmp/pin-3.7-97619-g0d0c92f4f-gcc-linux.tar.gz /opt/
cd /opt
tar -zxvf pin-3.7-97619-g0d0c92f4f-gcc-linux.tar.gz
ln -s /opt/pin-3.7-97619-g0d0c92f4f-gcc-linux /opt/pin-dir

Step 3

Navigate in to pin-dir and test by running a given example.

cd /opt/pin-dir/source/tools

Check whether you have a 32 bit architecture or a 64 bit architecture using lscpu command. Depending on this your compiler arguments will have to be modified. If the architecture is x86_64,

make all

If the architecture is 32 bit,

make all TARGET=ia32

Step 4

Run the instruction count example,  by navigating in to the folder obj-intel64. To test the tool, you will need a gcc compiled object file. For now assume that the object binary is prog.

cd ManualExamples/obj-intel64
./pin -t /opt/pin-dir/source/tools/ManualExamples/obj-intel64/inscount0.so -- ~/prog

Pro tip! – Do not forget the -- in between the above command. This is specified in the pin tool as follows. ./pin -t [full path to tool] – [full path to app]

Step 5

View the results. The instruction count in your program would be stored in inscount0.out which will be residing in the /opt/pin-dir directory.

cat /opt/pin-dir/inscount0.out

In the next blog post in the intel pin series, learn how you could create your own tool to count the number of branches.

Leave a Reply

avatar
  Subscribe  
Notify of