Turns a benchmark's C source into an ELF that HFIM can inject faults into. Two things live here, and nothing else does.
The injection contract. hfim.h declares fim_init() and
fim_exit(). A benchmark calls the first where the measured work begins
and the second where it ends; between them is the window a fault can
land in, and at fim_exit the framework reads the observable state.
Both are compiled non-inline so they keep stable addresses in the symbol
table for a debugger to break on. The implementation handles the
shutdown mechanism per architecture, so a benchmark never has to know
whether it is on RISC-V or AArch64.
The build script. build.sh compiles a benchmark directory against
that contract and produces build/<name>_<arch>.elf.
hfim-sdk/build.sh benchmarks/fibonacci
hfim-sdk/build.sh benchmarks/fibonacci --target gem5-se
What is deliberately absent is the boot layer: start.S, the linker
script, the UART driver. Those name a specific machine, where its RAM
begins and where its serial port is, so they belong to the platform and
travel with the template. This repository is board-agnostic, which is
what lets one copy serve every board.
The entry point is main.c. Without one, the single source at the top of
the directory is the entry point, and it may be C or assembly: a
protection tool that rewrites a whole program can hand over one .s
with main inside it, and that file builds as it is. More than one
top-level source, and no main.c, is an error, because nothing says
which one is the program.
Anything under src/ is compiled in alongside the entry point: .c,
.s as it is, and .S through the preprocessor. That is where a tool's
output goes when the benchmark keeps its own main.c around it. Every
one of these files counts toward the build hash, so editing any of them
rebuilds the ELF.
Assembly from LLVM must carry DWARF 4 debug information, not 5
(-gdwarf-4 when the IR is made). The assembler in the toolchain image,
GNU as 2.40, rejects the DWARF 5 line tables that clang and llc write by
default.
For a bare-metal target the script needs boot code. It looks, in order,
at --startup <dir>, then HFIM_STARTUP, then startup/<arch> in the
repository holding the benchmark. Run it from inside a template and the
third case applies with nothing to configure.
--target gem5-se needs none of it: gem5's system-emulation mode loads
the ELF and emulates Linux syscalls, so there is no machine to bring up.
The Build Settings are arguments: --optflag (default O1),
--runtime (default nostdlib) and --toolchain, or --cc to name
the compiler outright. The script never reads the benchmark's
fim.yaml; a benchmark that needs another runtime or optimisation level
gets it from its campaign, which hfim turns into these arguments.
Run by hand, OPTFLAG, RISCV_CC, AARCH64_CC and HFIM_STARTUP in
the environment still override them.
hfim runs it with --settings-given: every setting is an argument
(--optflag, --runtime, --startup, and --cc for the compiler its
Build Record fingerprints), and the script reads none of those
variables. A setting left out is an error. --print-settings prints
what a run would use and exits without compiling, so it works on a
machine with no cross compiler.
| Target | Produces | Needs |
|---|---|---|
qemu-bare (default) |
a freestanding ELF that boots on the bare machine | a bare-metal cross compiler, riscv64-unknown-elf-gcc |
gem5-se |
an ordinary static Linux userspace ELF | a Linux cross compiler, riscv64-linux-gnu-gcc |
Both toolchains ship inside the
hfim-sim-qemu image, so a
build inside that container needs nothing installed on the host.
--toolchain <name> picks a compiler by name, resolved through
toolchains/, so a campaign that pins one (build_toolchain) never
records an absolute path.
The same sources, Build Settings and compiler give the same ELF, byte
for byte, whichever directory the repository sits in and whenever it is
built. Each translation unit is compiled to its own named object and
then linked, so no temporary file name reaches the symbol table. Debug
information names files relative to the repository (./benchmarks/...,
./startup/...) and to this SDK (hfim-sdk/...). There is no build-id
note, the build runs with LC_ALL=C and TZ=UTC, and __DATE__ and
__TIME__ read SOURCE_DATE_EPOCH, the time of the repository's last
commit (0 outside a repository or where git is missing). A source that
uses them gets a -Wdate-time warning, because it ties the ELF to a
commit time rather than to its contents.
Nothing time- or VCS-dependent goes into the ELF. Beside it,
build/<name>_<arch>.elf.build.json records when it was built and the
git state of the repository the benchmark lives in, not of this one:
what a result must be traceable to is the source that produced it,
which is the campaign fork.
{
"benchmark": "fibonacci",
"build_time": "2026-10-21T19:15:53Z",
"git": {"commit": "5b82460db50fa49d3b683c7fd91f1458a69b3731", "dirty": false}
}dirty is true only when git status --porcelain lists something.
Outside a repository git is "not a repository". Where git is not
installed, as in the simulator image hfim builds in, the commit is
read from .git itself and dirty is null, with dirty_unknown
saying why. A repository with no commits yet has "commit": null.