As the title states, I am looking for a way to make compile my PIN tool with some dependencies. So for example if I #include "somefile.h"
in my PIN tool, and generate some object file g++ -c somefile.cpp
, how do I link my object file to compile with my PIN tool so I can use it's functionality in my PIN tool?
Asked
Active
Viewed 1,492 times
4

TypeKazt
- 318
- 1
- 13
-
Note that the object file must be compiled with the same runtimes as Pin itself. I recommend that you look at some Pin kit makefiles to see how obj files are generated and add a similar line to your Pintool makefile. – nitzanms May 04 '16 at 10:59
2 Answers
6
So I was able to find some documentation on altering the "makefile.rules" under PIN's website here. For my situation these 6 lines below would be added to the end of "makefile.rules".
$(OBJDIR)"somefile"$(OBJ_SUFFIX): "somefile".cpp "somefile".h
$(CXX) $(TOOL_CXXFLAGS) $(COMP_OBJ)$@ $<
$(OBJDIR)"PinFile"$(OBJ_SUFFIX): "pin_tool".cpp
$(CXX) $(TOOL_CXXFLAGS) $(COMP_OBJ)$@ $<
$(OBJDIR)"pin_tool"$(PINTOOL_SUFFIX): $(OBJDIR)"somefile"$(OBJ_SUFFIX) $(OBJDIR)"PinFile"$(OBJ_SUFFIX) "somefile".h
$(LINKER) $(TOOL_LDFLAGS_NOOPT) $(LINK_EXE)$@ $(^:%.h=) $(TOOL_LPATHS) $(TOOL_LIBS)
The only thing that would change from one make file to another would be the words I put in quotes. Note that the quoted words should not have quotes around them in the actual "makefile.rules"

TypeKazt
- 318
- 1
- 13
-
1To those copy/pasting the code in this answer: Note that there should be a tab before the build commands, instead of four spaces ([reference](https://stackoverflow.com/questions/16931770/makefile4-missing-separator-stop)). – janw Aug 05 '20 at 16:25
2
You need a new rule at the end of your "makefile.rules" :
$(OBJDIR)YourPinToolMainFile$(PINTOOL_SUFFIX): $(OBJDIR)YourPinToolMainFile$(OBJ_SUFFIX) $(OBJDIR)somefile$(OBJ_SUFFIX)
$(LINKER) $(TOOL_LDFLAGS) $(LINK_EXE)$@ $^ $(TOOL_LPATHS) $(TOOL_LIBS)

olmpc
- 81
- 4
-
I followed your instruction It compiled successfully but when I run the Pintool, the linking error appeared as follows:- dlopen failed: cannot locate symbol "_ZN5CacheC2Ev" referenced by... Any suggestion ?? – Bernard Nongpoh Apr 04 '18 at 09:45