Introduction

LLVM Passes are an extraordinarily powerful tool that allow us to hook our own logic into the LLVM compilation process - by leveraging an extensive API that works on LLVM IR, we can run custom passes that belong to one of three categories:

or

LLVM Passes are similar in spirit to GCC plugins, but with richer documentation and a more fleshed out ecosystem. The LLVM Project invests significant effort in a clean codebase - and the effort shines when developing the passes.

Initial Motivation - Backstory

My initial interest in LLVM Passes began in a previous project I worked on - I was compiling code and running it in a system with:

I often found myself frustrated that even though I was able to establish full network communications with the system, I was unable to properly debug my code beyond black-boxing and the limited tracing capabilities afforded to me. I found myself thinking something along the lines of:

<aside> 💡 What if every single opcode was augmented with a network protocol that would communicate with a debugging host?

</aside>

What this means is - for every single opcode - we would have code that would send a packet out to a host to notify it of the current debugging state, and wait for further commands (standard step/ continue / run to)

This is a pretty crazy fucking idea, because:

There are some stark disadvantages that immediately come to mind: