I worked with the bots a bit and worked on a QEMU code coverage tool.
I have not reviewed this, but its a non intrusive qemu plugin that I was able to aggregate the code coverage from the rtems test suite.
This allows me to use the flight binary that would get linked, and the current the tests.
This should be general purpose for any processor.
master ← code-coverage
opened 11:10PM - 02 Jul 26 UTC
When running QEMU you would add this extra line
PLUGIN=$QEMU_SRC/contrib/plugins/libqemu_rtems_cov.so
COV=./coverage
mkdir -p "$COV/raw"
ELF=/abs/path/to/mytest.exe
NAME=mytest
When calling QEMU you would add the plugin line. Each test would get its own NAME / elf file.
-plugin "$PLUGIN,out=$COV/raw/$NAME.cov,mode=tb-insn,counts=1,test_id=$NAME,elf=$ELF" \
-kernel "$ELF"
Once you have all your test coverage files you can combine them all together.
PATH="/path/to/toolchain/bin:$PATH" \ # dir with <prefix>addr2line / <prefix>objdump
"$TOOLS/rtqcov_report.sh" \
--raw-dir "$COV/raw" \
--source-root "$RTEMS_SRC" \
--out-dir "$COV" \
--toolchain-prefix <prefix> \
--arch <label>
I have generated full coverage reports for the microblaze test suite.
I would be interested in comparing against the full version.
Also I have only looked at branch coverage.
This was more of an idea experiment. I have not tried to cleanup the LLM output.
A more detailed guide for this is provided here.
code-coverage-guide.txt (14.8 KB)
I did some follow up work on this.
Updates to rtems tools would be
Updates to rsb
I also split the qemu coverage analysis off as a standalone repo.
Non-intrusive line and branch code coverage for binaries running under QEMU, via a TCG plugin. No guest instrumentation, no recompilation, no third-party Python dependencies.
I am not 100% happy with how branch coverage is done on this.
There is a current bug in binutils for addr2line that needs fixed for this to run also, will upstream that next week hopefully.
master ← addr2line-equal-range-tiebreak
opened 12:31PM - 12 Aug 26 UTC
Two commits. **1/2 is the fix and stands alone. 2/2 is an optional test that can… not reproduce the bug — drop it if you would rather not carry it.**
## The bug
`lookup_address_in_function_table` picks, among the functions whose range contains the address, the one with the smallest range. When two have the **same range length** — a function whose whole body came from one inlined call, so the `DW_TAG_inlined_subroutine` covers exactly the same range as the `DW_TAG_subprogram` containing it — the tie was broken by comparing two `struct funcinfo *`:
```c
|| (arange->high - arange->low == best_fit_len
&& funcinfo > best_fit))
```
Those come from `bfd_zalloc`. Addresses increase within an objalloc chunk, but a new chunk can land below the old one, so which function won depended on where malloc happened to put things, and **addr2line reported a different function from run to run on the same binary**.
Introduced in 2016 by `089e3718bd8`, which replaced a linked-list walk with a sorted binary-search table and used pointer order to emulate the old list order.
## Evidence
200 runs of `addr2line -a -f -C -i -e hello.exe < addrs` on an RTEMS riscv32 image:
| build | distinct outputs of 200 |
|---|---|
| unpatched | **12** (23 runs differed) |
| patched | **1** |
The file and line columns never differ — only which function is named, and how many inlined frames `-i` then unwinds. It reproduces **sequentially** too, about 1 run in 200; concurrency only makes the heap vary more.
**Not memory unsafety.** An ASan build reports nothing across 100 concurrent runs, and `MallocScribble`/`MallocPreScribble`/`MallocGuardEdges` change nothing — the pointers compared are perfectly valid. ASan also *masks* it: its allocator is regular enough that the tie resolves consistently, so an ASan build is the wrong control.
`addr2line -a -C`, with neither `-f` nor `-i`, is stable — only the function/inline path is affected.
## The fix (1/2)
Order by `unit_offset`, the DIE offset. The comment said the comparison existed to match the pre-`089e3718bd8` algorithm, which walked `unit->function_table`; that list is built by prepending, so among equals it kept the one parsed last — the one with the greater DW_AT offset. `unit_offset` says that directly and does not move with the heap. All candidates in this loop belong to one `comp_unit`, so the offsets are unique.
It also picks the *right* one: an inlined subroutine's DIE is a child of the subprogram's, hence always later, so the innermost routine now wins every time — what the comment above the loop says the code should do.
## The test (2/2), and why it is optional
It does **not** reproduce the bug, and cannot. Allocation order and DIE order normally agree; they diverge only when an objalloc chunk boundary falls between the two tied entries *and* the new chunk lands lower. Whether a given pair straddles a boundary is fixed by the DWARF, not the heap, so pinning a test to one address removes the very thing that made the result vary — confirmed by a C harness that re-opened the file 800 times in one process while deliberately leaving 4064-byte holes (objalloc's chunk size): one distinct answer, patched and unpatched alike. Reproducing it needs many addresses across many CUs, in separate processes.
What it does do is pin the rule — the innermost routine must be reported at every address in the shared range — which had no coverage before. Inverting the comparison makes it fail.
## Testing
`make check-binutils`, target riscv64-unknown-elf, host aarch64-apple-darwin:
| | passes | failures |
|---|---|---|
| unpatched | 236 | 1 |
| patched + test | 237 | 1 |
The single failure (`Check if efi app format is recognized`) is present in the unpatched baseline; result lines were otherwise byte-identical. Also built with ASan on Linux (Ubuntu 24.04, default `ASAN_OPTIONS`, so LeakSanitizer enabled): correct output, empty stderr, no leak report.
Not yet sent to binutils@sourceware.org.