llvm-tutor icon indicating copy to clipboard operation
llvm-tutor copied to clipboard

How to add a plugin when compiling an entire codebase

Open vjpr opened this issue 3 years ago • 2 comments

Related

  • https://github.com/banach-space/llvm-tutor/issues/28
  • https://stackoverflow.com/questions/23130821/llvm-run-own-pass-automatically-with-clang?rq=1

I am trying to instrument all function calls in an existing codebase.

I don't want to have to modify existing makefile scripts too extensively.


The solution is to use the legacy pass manager.

clang++ -flegacy-pass-manager -Xclang -load -Xclang ./libmypass.so input.cpp

It seems that the new pass manager doesn't allow this yet.

You must take care to choose the correct extension point. See here are the extension points. See [here] (https://github.com/rdadolf/clangtool/blob/353b80061ce30c3062bbe4752dbaa2a1c84cc9c8/clangtool.cpp#L42-L49) for an explanation of which ones to use.


This information should be added to the readme.md.

vjpr avatar Jan 19 '22 11:01 vjpr

Hello @vjpr , thanks for creating this issue and for your extensive research on this matter :)

The solution is to use the legacy pass manager.

Unfortunately, the Legacy PM will be removed after LLVM 14?

This information should be added to the readme.md.

Good point! Do you have the bandwidth to create a PR? This would have to be added with the caveat that it will stop working once LLVM 15 is released. Sadly :(

banach-space avatar Jan 24 '22 20:01 banach-space