Cross-Compiling SPEC CPU2017 for RISC-V (RV64): A Practical Guide
- Rajeev Gadgil
- May 12
- 3 min read
SPEC CPU2017 is a well-known benchmark suite for evaluating CPU-intensive performance. Although it assumes native compilation and execution, there are cases—especially with RISC-V (RV64) platforms—where cross-compilation is the only feasible route.
This guide walks through the steps to cross-compile SPEC CPU2017 for RISC-V, transfer the binaries to a target system, and optionally use the --fake option to simulate runs where execution isn't possible or needed during development.

Cross-compiling is essential when:
Your RISC-V target system (e.g., dev board or emulator) lacks compiler tools.
You're benchmarking an emulator (e.g., QEMU) or a minimal Linux image.
Native builds are too slow or memory-constrained.
Prerequisites

A working RISC-V cross-toolchain (e.g., riscv64-linux-gnu-gcc).
Installed SPEC CPU2017 suite on your host machine.
Access to a RISC-V target environment (real or emulated).
Optional: knowledge of the --fake flag in SPEC CPU2017 (we'll explain it below).
Step-by-Step Guide

1. Install SPEC CPU2017 on the Host Machine
Install SPEC on your x86_64 development system as usual:
bash
./install.sh
2. Setup the Cross-Toolchain
Make sure the RISC-V toolchain is installed and available:
bash
export CROSS_COMPILE=riscv64-linux-gnu- export CC=${CROSS_COMPILE}gcc export CXX=${CROSS_COMPILE}g++
Make sure the compiler binaries are in your $PATH.
3. Create a RISC-V SPEC Config File
Copy and modify an existing config:
bash
cd $SPEC_DIR/config cp linux64-gcc.cfg linux-rv64-cross.cfg
Then edit linux-rv64-cross.cfg:
ini
default=default=base,peak
CC = riscv64-linux-gnu-gcc
CXX = riscv64-linux-gnu-g++
COPTIMIZE = -O2 -static
CXXOPTIMIZE = -O2 -static
PORTABILITY = -DSPEC_CPU_LINUX
EXTRA_LDFLAGS = -static
Use --sysroot or target-specific flags if needed. The -static flag is highly recommended to avoid runtime issues on minimal RISC-V Linux systems.
4. Build the Benchmarks (Without Running)
This step compiles the benchmarks using the cross toolchain, but does not attempt to run them:
bash
cd $SPEC_DIR ./bin/runcpu --config=linux-rv64-cross --action=build --tune=base --size=ref all
This will create executable binaries in the benchmark run/ directories.
5. (Optional) Simulate Benchmark Runs Using --fake
If you only want to verify that the binaries were built correctly and prepare result directories for later manual execution, you can use:
bash
./bin/runcpu --config=linux-rv64-cross --action=run --fake --tune=base --size=ref all
This does not execute the binaries. Instead, it fakes a successful run and populates the result directories and reports.
Use cases for --fake:
Validate build structure without requiring target hardware.
Automate CI pipelines for SPEC builds.
Pre-generate result directories to collect logs from target systems later.
Important: --fake is not a benchmark run. It's a metadata operation. You still need to run the binaries on the actual hardware to get performance data.
6. Transfer Binaries to Target System
Find the executables in:
bash
$SPEC_DIR/benchspec/CPU/*/run/*
Use scp, rsync, or embed them into a disk image. On your RISC-V target:
bash
cd /run/path ./<benchmark_name>_base.riscv64
Capture performance stats using /usr/bin/time, perf, or another profiler.
Troubleshooting
Issue | Fix |
Illegal instruction | Cross-compiler may be targeting wrong ISA; use -march=rv64gc |
Segmentation fault | Missing libraries or stack size issues; try -static or ulimit -s unlimited |
Missing libstdc++ | Use -static-libstdc++ or provide shared libs manually |
QEMU hangs or crashes | Upgrade QEMU version or run on real hardware |
Summary
With proper configuration, cross-compiling SPEC CPU2017 for RISC-V is not only feasible, but it’s also a powerful way to bring industrial-grade performance testing to emerging architectures. The --fake flag is a valuable tool when you're preparing runs in a disconnected or staged workflow.
Bonus: CI/CD Pipeline Tip
If you’re integrating into CI:
Use --action=build and --fake together to validate builds.
Export binaries as artifacts.
Deploy them onto your RISC-V target for actual execution.
Commenti