I'm not sure this is going to be an adequate answer, but not enough space in the comments.
In general, if you want to pass anything via a custom LLVM
optimization pass, you need to either 1) produce bitcode and use the pass then on it, or 2) have clang
run that pass for you.
For 1), it means that you need to preprocess and compile the program with the same options and flags and do the same at the linking phase (when you're done processing the generated bitcode). AFAIK, the easiest and less invasive is to use the wllvm
utility (especially since xnu
uses make
).
For 2), you need to register your plugin with clang
's pass manager. According to the documentation, there are various registries for that, but the clang
one is not mentioned. Looking at how LLVM
does it in e.g. llvm/Transforms/IPO/PassManagerBuilder.h
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
// using llvm::PassManagerBuilder
// using llvm::RegisterStandardPasses
static void registerHello(const llvm::PassManagerBuilder &Builder,
llvm::legacy::PassManagerBase &PM) {
PM.add(new HelloPass());
return;
}
static llvm::RegisterStandardPasses RegisterHello(llvm::PassManagerBuilder::EP_EarlyAsPossible, registerHello);
and call it as
clang -Xclang -load -Xclang [path to plugin]/libHelloPass.so foo.c -o foo