Recently I have been running SimPoint sampling of SPEC CPU2006 on Sniper. For simulating RISC-V binaries, I use a setup where QEMU generates a SIFT trace file that is then fed to Sniper, but it suddenly occurred to me: "Can't x86 simulate an ELF directly without a trace file?" When I looked into it, I found that Sniper's internal structure is quite well designed, so I am recording it here. The second part covers the internal structure of the SIFT format and its connection to the simulation core.
Sniper Has Multiple Front-Ends
Looking at Sniper's source tree, the following three exist under frontend/.
frontend/ ├── pin-frontend/ # Intel PIN based (direct execution of x86 ELF) ├── qemu-frontend/ # QEMU plugin (RISC-V / ARM / x86) └── dr-frontend/ # DynamoRIO based
In addition, common/trace_frontend/ contains the "trace front-end" that reads SIFT trace files.
In other words, Sniper has two broad paths for supplying instructions.
| Path | Method | Target ISA |
|---|---|---|
| Dynamic binary instrumentation | Pin / QEMU / DynamoRIO | x86 (Pin/QEMU), RISC-V / ARM (QEMU) |
| SIFT trace replay | trace_frontend |
ISA-independent (regardless of the architecture at trace generation time) |
For this RISC-V simulation, the setup has two stages: "generate a SIFT trace with the QEMU front-end → replay it with Sniper's trace front-end."
Direct x86 Execution: How the Pin Front-End Works
frontend/pin-frontend/pin_frontend.cc is the part that simulates while directly executing an x86 ELF. Intel PIN is a dynamic binary instrumentation (DBI) framework that can insert arbitrary callbacks at each instruction or basic block while the program runs.
Initialization looks like this.
// pin_frontend.cc:111 this->parsing_error = PIN_Init(argc, const_cast<char**>(argv)); PIN_InitSymbols();
When the target program is launched under Pin, callbacks run for each Trace (a collection of basic blocks), and the instruction addresses, memory access addresses, and so on are passed to the simulation core. The memory address is obtained using a Pin API called IARG_MEMORYOP_EA.
The defining feature of this approach is that it simulates while executing. Because the program actually runs, real system calls are invoked as well. This makes it natural to switch between full-speed execution (fast-forward) and cycle-accurate simulation (detailed).
How run-sniper Launches Pin
Looking at run-sniper (Python3, 964 lines), in non-standalone mode it launches Pin as follows.
# run-sniper:759-765 pintool = 'pin_sim' cmd = '%(pin_home)s/intel64/bin/pinbin %(pinoptions)s \ -t %(sim_root)s/lib/%(pintool)s' \ + optcmd + ' -- ' + ' '.join(cmdline)
pin_sim is the Sniper Pin tool itself, placed under lib/ as a compiled shared library. Pin launches cmdline (the target ELF), and the instrumented instruction stream flows directly into Sniper's simulation core.
The RISC-V Case: Why a Trace File Is Needed
Pin is a framework dedicated to x86 binaries. A RISC-V binary cannot be fed directly to Pin on a Linux/x86 host.
For RISC-V, the following path is used.
RISC-V ELF binary
│
▼
QEMU (user-mode emulation)
│ Capture instructions via the QEMU plugin API
▼
QEMU front-end plugin (qemu_frontend.cc)
│ Write out the trace in SIFT format
▼
.sift file (disk or FIFO)
│
▼
Sniper trace front-end (trace_thread.cc)
│ Read the trace with Sift::Reader
▼
Simulation core (core.h / performance_model/)
frontend/qemu-frontend/qemu_frontend.cc uses QEMU's plugin API to decode instructions for each Translate Block (TB) and write them out in SIFT format.
// qemu_frontend.cc:30-40 std::unique_ptr<dl::DecodedInst> decode(const void* data, size_t size, uint64_t addr) { std::unique_ptr<dl::DecodedInst> decoded( m_decoder_factory.CreateInstruction( m_decoder.get(), static_cast<const uint8_t*>(data), size, addr)); m_decoder->decode(decoded.get()); return decoded; }
RISC-V instruction decoding is handled by decoder_lib/riscv_decoder.h, which is unified with x86's x86_decoder.h under the same abstract interface (dl_arch, dl_isa).
// decoder.h:10-45 typedef enum dl_arch { DL_ARCH_INTEL, DL_ARCH_RISCV, DL_ARCH_ARMv7, DL_ARCH_ARMv8 } dl_arch;
Thanks to this abstraction, whichever ISA's instructions the front-end (QEMU) decodes, the instruction information is passed to Sniper's simulation core through a unified interface.
Comparing the x86 and RISC-V Paths (Part 1 Summary)
| x86 (Pin approach) | RISC-V (SIFT approach) | |
|---|---|---|
| Instruction supply | Pin dynamically instruments the ELF and supplies instructions directly | QEMU generates SIFT while emulating |
| Host requirements | Run x86 binaries directly on an x86 host | Cross-emulate RISC-V on an x86 host |
| Trace file | Not needed (supplied in real time by dynamic instrumentation) | Needed (decoupled via a .sift file) |
| System calls | Pin intercepts and calls the real syscall | Conveyed by SIFT records (detailed in part 2) |
This is an English translation of the original Japanese post: Sniper シミュレータのフロントエンド構造を調査した (1. Pin による x86 直接実行と RISC-V の経路)