Skip to content

Instrument

This post records how to instrument the Linux kernel with LLVM.

Write an LLVM Transformation Pass

Please refer to PassBuilder.h and choose the correct pass registration function.

In our case, we use registerOptimizerLastEPCallback to call this pass at the end of compilation.

llvmGetPassPluginInfo() {
    return {LLVM_PLUGIN_API_VERSION, "IdentifyProg", "v0.1", [](PassBuilder &PB) {
        PB.registerOptimizerLastEPCallback(
            [](ModulePassManager &MPM, auto) {
                MPM.addPass(IdentifyProg());
                return true;
        });
    }};
}

Invoke the Pass During Kernel Build

Add pass to KCFLAGS option.

make CC=wllvm HOSTCC=wllvm KCFLAGS=" -fpass-plugin=/path/to/libPass.so" -j192

Reference