Repository navigation
fix(tracer): resolve ELF symbol names via the symtab's sh_link - #1877
Conversation
There was a problem hiding this comment.
The fix is right and the bug is real: setup_program picks the first SHT_STRTAB, which under LLD is .shstrtab. Verified on a local merge with current main: the production hunks apply cleanly, the emulator tests plus the new one pass, and clippy is clean for tracer and jolt-tracer-x86.
The branch conflicts with main now (only the new tests module in tracer/src/emulator/mod.rs, which #1697 also added), so it needs a rebase. Two comments to fold into that rebase.
Note: this reply was written by an AI after it reported the issue to me and I made the decision. If anything here is wrong, reply and I will review it myself.
setup_program resolved every symbol name through the first SHT_STRTAB section. The ELF spec says a symbol table's names live in the section named by its sh_link. LLD emits .symtab, .shstrtab, .strtab, so names were read from .shstrtab and tohost was never found, which made jolt-emu report a failing arch test as a pass. jolt-emu-x86 duplicated the same lookup.
8bfa904 to
0b978ff
Compare
|
Rebased on current main (f830b54), so the conflict is gone, and both comments are folded in. |
Summary
Emulator::setup_programresolved every symbol name through the firstSHT_STRTABsection in the file (the code carried a@TODOabout exactly this assumption). Per the ELF spec, a symbol table's string table is the section named by itssh_link.GNU ld happens to place
.strtabbefore.shstrtab, so this is invisible with binutils. LLD emits.symtab, .shstrtab, .strtab(checked withclang --target=riscv64+ld.lld:[5] .symtab Lk=7,[6] .shstrtab,[7] .strtab), so names were read out of.shstrtabandtohost/begin_signature/end_signaturewere never found.For
jolt-emuthis turns a failing arch test into a silent pass:tohost_addrstays 0,run_testpolls address 0 (which reads as zero), and the program returns 0 once it stalls on its halt loop, whichtests/arch-tests/run.shcounts as a pass. An LLD-linked riscv64 ELF that writes HTIF fail code 3 totohostexits 0 on main andTest Failed with 3(exit 1) with this change; the passing variant still exits 0.jolt-emu-x86duplicated the same lookup and reportedno tohost symbolfor both.Changes
ElfAnalyzer: exposeSectionHeader::sh_link(it was parsed and dropped) and addread_symbol_map, which resolves eachSHT_SYMTABthrough its ownsh_linkand skips an out of range link.Emulator::setup_program: useread_symbol_map; drop the two now unused section vectors.jolt-emu-x86symbol_map: delegate to the same helper instead of its copy of the first-STRTAB lookup.Testing
emulator::tests::resolves_symbols_through_symtab_sh_linkbuilds a minimal RV64 ELF in code with LLD's section order and assertstohostresolves (no binary fixture added). It fails on main (left: None, right: Some(0x80001000)) and passes with the fix.cargo test -p tracer --libis 128 passed; the 12 failures are the same with and without this change (they shell out to thejoltCLI to build guests, which is not installed in my environment).cargo clippy -p tracer --all-targets -- -D warnings,cargo clippy -p jolt-tracer-x86 --bins -- -D warningsandcargo fmt --checkpassSecurity Considerations
Tracer and emulator tooling only; no effect on proving or verification. The fix matters for test harness correctness: with an LLD-built ELF,
jolt-emucould report a failing compliance test as passing.Breaking Changes
None.
SectionHeader::sh_linkbecomes public andElfAnalyzer::read_symbol_mapis added; both are additive.