Skip to main content
skill CX Codex

jit-compilation — Claude Code skill: what it does, how to install

jit-compilation teaches the agent to build a JIT: LLVM ORC and LLJIT, Cranelift, inline caches, trampolines, Rust dynasm. Useful for interpreter hot paths and REPLs.

MIT 382 installs ★ 298 updated 2026-06-27

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add mohitmishra786/low-level-dev-skills --skill jit-compilation -a claude-code
Open on GitHub

What jit-compilation does

The skill walks an agent through just-in-time compilation. It starts with LLJIT, the shortest way to run LLVM IR from memory, then moves to the ORC JIT v2 layers (ExecutionSession, IRLayer, ObjectLayer). Cranelift JIT and lazy compilation with trampolines get their own sections. Inline caches for dynamic dispatch and the W^X policy are covered too.

Inside are code samples: a C++ LLJIT module with an add function, a Rust Cranelift setup, an mmap plus mprotect snippet, and an x86_64 dynasm routine. A decision tree picks the backend. A table maps symptoms to fixes, such as a symbol missing on lookup, a segfault from an ABI mismatch, or stale code after recompilation.

The LLJIT sample builds with clang++ and llvm-config, so LLVM with the core, orcjit and native components has to be installed first. The dynasm sample targets x86_64 only.

What it helps with

  • build a minimal JIT with LLJIT and call a generated add from C++
  • compile a function lazily on first call through a trampoline
  • add an inline cache to a polymorphic call site in an interpreter
  • write machine code into memory, then flip the page to RX under W^X
  • track down why JIT code segfaults or a symbol lookup fails

Example prompts for the agent

  • Build a minimal JIT with LLJIT: an add function from LLVM IR, called from C++
  • Add lazy compilation to my ORC JIT using trampolines
  • Write an x86_64 addition routine with Rust dynasm

How to install jit-compilation

1Skills CLI (Vercel)

npx skills add mohitmishra786/low-level-dev-skills --skill jit-compilation -a claude-code

2Manually: put the files in place

~/.claude/skills/jit-compilation/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/jit-compilation/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about jit-compilation

How do I install jit-compilation in Claude Code?

Run npx skills add mohitmishra786/low-level-dev-skills --skill jit-compilation -a claude-code. The skill file lands at ~/.claude/skills/jit-compilation/SKILL.md.

What does jit-compilation do?

It gives the agent a working guide to JIT compilation: LLJIT and the ORC JIT v2 layers, Cranelift, lazy compilation via trampolines, inline caches, W^X and dynasm for x86_64.

Which JIT backend does the skill recommend?

If you need LLVM optimizations, ORC JIT or LLJIT. For fast compile times and embedding, Cranelift. For tiny assembly snippets, dynasm.

Source text

SKILL.md · MIT
---
name: jit-compilation
description: JIT compilation skill for runtime code generation. Use when building LLVM ORC JIT, LLJIT, Cranelift JIT, inline caches, trampolines, or Rust dynasm codegen. Activates on queries about ORC JIT, LLJIT, Cranelift, ExecutionSession, inline cache, W^X, or dynasm.
---

# JIT Compilation

## Purpose

Guide agents through just-in-time compilation: LLVM ORC JIT v2 (`ExecutionSession`, `IRLayer`, `ObjectLayer`), LLJIT for simpler use cases, Cranelift JIT, inline caches for dynamic dispatch, trampolines for lazy compilation, security considerations (W^X, code signing), and Rust `dynasm` for x86 codegen.

## When to Use

- Building an interpreter with a JIT hot-path
- Implementing lazy function compilation on first call
- Embedding dynamic code generation in a REPL or game engine
- Prototyping codegen without writing a full linker
- Creating inline caches for polymorphic call sites
- Generating x86 machine code from Rust with `dynasm`

## Workflow

### 1. JIT architecture overview

```
Source/AST/Bytecode
    → IR (LLVM IR or Cranelift CLIF)
    → Object file (in memory)
    → Runtime linker (RTDyldObjectLinkingLayer)
    → Executable code in R+X memory
    → Function pointer call
```

### 2. LLJIT — simplest LLVM JIT

```cpp
#include "llvm/ExecutionEngine/Orc/LLJIT.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/IRBuilder.h"

using namespace llvm;
using namespace llvm::orc;

int main() {
    auto JIT = cantFail(LLJITBuilder().create());

    LLVMContext Context;
    auto M = std::make_unique<Module>("jit", Context);
    IRBuilder<> Builder(Context);

    // int add(int a, int b) { return a + b; }
    Function *AddFn = Function::Create(
        FunctionType::get(Builder.getInt32Ty(),
                          {Builder.getInt32Ty(), Builder.getInt32Ty()}, false),
        Function::ExternalLinkage, "add", M.get());

    BasicBlock *BB = BasicBlock::Create(Context, "entry", AddFn);
    Builder.SetInsertPoint(BB);
    auto Args = AddFn->arg_begin();
    Value *Sum = Builder.CreateAdd(Args, Args + 1);
    Builder.CreateRet(Sum);

    cantFail(JIT->addIRModule(ThreadSafeModule(std::move(M), std::make_unique<LLVMContext>())));

    auto AddSym = JIT->lookup("add");
    auto *AddPtr = (int (*)(int, int))AddSym->getValue();
    int result = AddPtr(3, 4);  // 7
    return 0;
}
```

```bash
clang++ -std=c++17 jit.cpp $(llvm-config --cxxflags --ldflags --libs core orcjit native) -o jit
```

### 3. ORC JIT v2 layers

```cpp
ExecutionSession ES;
auto &MainJD = ES.createBareJITDylib("main");

RTDyldObjectLinkingLayer ObjectLayer(
    ES, []() { return std::make_unique<SectionMemoryManager>(); });

IRCompileLayer CompileLayer(
    ES, ObjectLayer, std::make_unique<TargetMachineBuilder>());

// Add IR module to JITDylib
ThreadSafeModule TSM = ...;
CompileLayer.add(MainJD, std::move(TSM));

// Resolve symbol
auto Sym = ES.lookup({&MainJD}, "my_func");
```

Layers:
- **IRLayer** — compiles LLVM IR to object
- **ObjectLayer** — links relocatable objects
- **ExecutionSession** — symbol lookup and JITDylib management

### 4. Lazy compilation with trampolines

```
First call → trampoline → compile function → patch trampoline → direct call
```

```cpp
// Simplified lazy compile on first invocation
void *LazyCompile(const std::string &Name) {
    if (!Compiled.count(Name)) {
        auto Fn = CompileFromAST(Name);
        Compiled[Name] = Fn;
        // Patch call site or update function pointer table
    }
    return Compiled[Name];
}
```

ORC supports lazy reexports and lazy compilation via `LazyCallThroughManager`.

### 5. Inline caches

```javascript
// Concept: monomorphic call site caches resolved target
// Pseudocode for dynamic language
function call_site(obj, method, args) {
    if (obj.class_id === cache.class_id) {
        return cache.fn_ptr(args);  // fast path
    }
    cache.class_id = obj.class_id;
    cache.fn_ptr = resolve_method(obj, method);
    return cache.fn_ptr(args);
}
```

JIT generates specialized code per cached type; deoptimize on cache miss.

### 6. Cranelift JIT

```rust
use cranelift::prelude::*;
use cranelift_jit::{JITBuilder, JITModule};
use cranelift_module::{Linkage, Module};

let isa = cranelift_native::builder().finish(settings::Flags::new(settings::builder()))?;
let jit_builder = JITBuilder::with_isa(isa, cranelift_module::default_libcall_names());
let mut module = JITModule::new(jit_builder);

let mut ctx = module.make_context();
ctx.func = Function::with_name_signature(
    module.declare_function("add", Linkage::Export, &sig)?,
    sig,
);
// ... build IR in ctx.func ...
module.define_function(func_id, &mut ctx)?;
module.finalize_definitions()?;
let code = module.get_finalized_function(func_id);
let add_fn: fn(i32, i32) -> i32 = unsafe { std::mem::transmute(code) };
```

Cranelift: faster compile times than LLVM, good for embeddable JITs.

### 7. Security — W^X policy

```
W^X (Write XOR Execute)
├── Memory page is writable OR executable, never both
├── JIT: allocate RW → write code → mprotect(RX)
└── macOS hardened runtime requires signed JIT pages
```

```c
#include <sys/mman.h>

void *mem = mmap(NULL, size, PROT_READ | PROT_WRITE,
                 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
// write machine code to mem
mprotect(mem, size, PROT_READ | PROT_EXEC);
```

Linux: `MAP_JIT` on Apple platforms; `sealed` memfd on hardened systems.

### 8. Rust dynasm (x86)

```rust
use dynasm::dynasm;
use dynasmrt::{Assembler, ExecutableBuffer};

let mut asm = Assembler::new().unwrap();
dynasm!(asm
    ; .arch x86_64
    ; add:
    ; add eax, ecx
    ; ret
);
let buf = asm.finalize().unwrap();
let add_fn: fn(i32, i32) -> i32 = unsafe { std::mem::transmute(buf.ptr(0)) };
```

Use for lightweight asm snippets without LLVM dependency.

### 9. Decision tree

```
JIT backend choice?
├── Need LLVM optimizations → ORC JIT / LLJIT
├── Fast compile, embeddable → Cranelift
├── Tiny asm snippets → dynasm
└── ML workloads → MLIR → ORC pipeline
```

## Common Problems

| Symptom | Cause | Fix |
|---------|-------|-----|
| Symbol not found on lookup | Name mangling or not exported | Use C linkage; `LLVMExternalLinkage` |
| Segfault calling JIT code | ABI mismatch | Match calling convention and types |
| W^X mmap failed | SELinux/grsecurity | Use `MAP_JIT`; check `dmesg` |
| Stale code after recompile | Old function pointer | Invalidate caches; use trampolines |
| LLVM JIT slow compile | `-O2` in JIT | Use `-O0` for JIT; optimize hot paths only |
| Cranelift verify error | Invalid CLIF | Enable `cranelift_codegen::verify_function` |

## Related Skills

- `skills/compiler-internals/llvm-passes` — optimize before JIT
- `skills/compiler-internals/compiler-frontend` — AST to IR for JIT input
- `skills/compiler-internals/mlir` — MLIR lowering to LLVM for JIT
- `skills/compilers/llvm` — LLVM IR fundamentals
- `skills/low-level-programming/interpreters` — bytecode interpreters using JIT
- `skills/low-level-programming/assembly-x86` — hand-written asm context

© mohitmishra786 · MIT · mohitmishra786/low-level-dev-skills

Similar skills

All skills for Programming languages →

From the same set140

The whole set →
protocol-analysis protocol-analysis is a Claude Code skill that decodes I2C, SPI, and UART captures with sigrok and PulseView, then checks them against driver code. It handles silent-sensor bus analysis. CX Codex +1 383installs gpio-baremetal gpio-baremetal configures GPIO modes, alternate functions, pull resistors, and EXTI interrupts on bare-metal microcontrollers without HAL. CX Codex +1 383installs apple-silicon A skill for developers building on Apple Silicon: tuning code for unified memory, Metal Performance Shaders, Instruments profiling, Rosetta 2 behavior, and 16KB page size quirks. CX Codex +1 383installs code-generation-and-backends code-generation-and-backends explains LLVM backend stages, from IR legalization to assembly output. Use it to investigate llc, TableGen patterns, or the outline of a new target port. CX Codex +1 382installs kernel-testing Skill for Linux kernel testing: KUnit for unit tests, kselftest for regression checks, syzkaller for fuzzing, and LTP for syscall compatibility. Activates on kunit.py queries, syzkaller config, or KernelCI setup. CX Codex +1 382installs branch-prediction-and-speculation branch-prediction-and-speculation is a Claude Code skill that explains CPU branch prediction and speculative execution to help optimize hot loops and protect code from cache timing leaks. CX Codex +1 382installs os-dev-scratch os-dev-scratch is a Claude Code skill for building a minimal x86-64 OS, from boot stages to drivers and context switching. It activates on questions about kernel boot, interrupts, page tables, or QEMU. CX Codex +1 381installs kernel-security kernel-security — a skill for SELinux and AppArmor policies, seccomp-bpf sandboxing, KASLR, Intel CET, ARM PAC and BTI. Write LSM rules, triage kernel CVEs, and configure kernel mitigations. CX Codex +1 381installs

Project sponsors

Companies that keep this analytics open