The runtime leaves through plat_exit_now() (src/nx/runtime/platform/plat_posix.c), which calls _exit on
purpose, so that no atexit handler runs against threads that are still going. Both LLVM's profile runtime and gcov
write their counters from an atexit handler, so an instrumented runtime that ends normally writes an empty
profile. Amberlith's launcher also kills a launch that hangs, which writes nothing either.
LLVM's continuous mode solves both. The counters live in a memory-mapped file from the program's start, so what
ran is on disk however the process ends: _exit, a crash, SIGKILL. It takes %c in LLVM_PROFILE_FILE, and on
ELF hosts other than Linux and Fuchsia the counters must be relocatable at run time, which
-mllvm -runtime-counter-relocation asks for. A plain instrumented build run through _exit left a 0-byte
.profraw; the same with continuous mode left the counts.
A build folder of its own, with the instrumentation in CMAKE_C_FLAGS/CMAKE_CXX_FLAGS. The game modules'
runtime library (rtlib.c) is compiled with its own flag list (src/common/cpu/recompiler/CMakeLists.txt),
so it is not instrumented and the modules still link with no imports.
F="-fprofile-instr-generate -fcoverage-mapping -mllvm -runtime-counter-relocation"
cmake -S . -B build/cov -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ \
-DSNX_DEPLOY=OFF -DSNX_JEMALLOC=OFF \
"-DCMAKE_C_FLAGS=$F" "-DCMAKE_CXX_FLAGS=$F" \
-DCMAKE_EXE_LINKER_FLAGS=-fprofile-instr-generate \
-DCMAKE_SHARED_LINKER_FLAGS=-fprofile-instr-generate \
-DCMAKE_MODULE_LINKER_FLAGS=-fprofile-instr-generate
cmake --build build/cov --target scarletnx # the runtime and driver; add the test targets for ctest
clang, llvm-profdata and llvm-cov: the raw profile format changes between versions.
On FreeBSD, take the two tools from the folder of the Clang that built it (/usr/local/llvm23/bin for clang23).SNX_DEPLOY=OFF keeps the instrumented runtime from being copied over every game in your data folder, as the
Tracy preset does. A run through build/cov/scarletnx still puts it beside the game it runs.-runtime-counter-relocation is unused at link time. The warning is harmless.-runtime-counter-relocation on every ELF host. Without it, continuous mode is refused where the profile
runtime cannot map the counters in place.Made from docs/dev/coverage.md at 69237645142c. GPL-3.0-or-later.