N64Recomp/src
Matthew Stanley b792e74a3e recompilation: hoist bss → parent remap above relocatable check
The bss → parent text section remap was happening AFTER the
target_relocatable check. Bss sections are not themselves marked
relocatable; their parent text sections are. So a HI16/LO16 pair
targeting a bss section (e.g. .fragment34_bss) hit
target_relocatable=false and the reloc was silently dropped — the
lui/addiu emitted as link-time literals.

Symptom: producer/consumer asymmetry across fragments. fragment62's
func_8432D5B0 writes to D_8140E720 (in fragment34's bss) using
emitted literal `S32(0x8141 << 16)` — i.e., the canonical link
addr 0x8140E720. fragment34's func_8140C204 reads D_8140E720 via
RELOC_HI16(147, 0xE720) against the RUNTIME base. When fragment34
is loaded at a non-canonical runtime address (e.g. 0x80114C10),
the writer hits canonical RDRAM[0x40E720] while the reader hits
runtime+0xE720 = RDRAM[0x123330] — different locations. Reader
sees uninitialized memory (observed value 3, near-NULL deref at
0xD3 in func_8140C204).

Two changes:

1. Hoist the bss-remap above the target_relocatable check so the
   parent's relocatable flag is what gates emit, not the bss
   section's.
2. When remapping, add (bss_vram - parent_vram) to
   target_section_offset so it stays relative to the new (parent)
   base. The reloc's stored target_section_offset is computed
   relative to the bss section's vram in elf.cpp; the parent text
   section starts before bss in the link layout, so the offset
   needs the bss-vs-parent vram delta added (typically equal to
   the parent text size).

Verified: Stadium attract demo now runs without the
func_8140C204:0xD3 crash. Reaches frame 2138 cleanly through
fragment62 + fragment34 dispatch.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-05 21:17:58 -07:00
..
analysis.cpp PIC Jump Table Support (#120) 2025-01-16 00:40:50 -05:00
analysis.h Implement live recompiler (#114) 2024-12-31 16:11:40 -05:00
cgenerator.cpp Mod function hooking (#124) 2025-01-26 21:52:46 -05:00
config.cpp Implement mdebug parsing for static symbols in IDO elfs (#155) 2025-09-06 18:44:18 -04:00
config.h Implement mdebug parsing for static symbols in IDO elfs (#155) 2025-09-06 18:44:18 -04:00
elf.cpp Fix empty bss section name mapping (#167) 2025-12-11 10:53:10 -05:00
main.cpp Fix out of bounds access when searching for statics at the end of a section (#171) 2026-01-16 20:54:43 -05:00
mdebug.cpp Implement mdebug parsing for static symbols in IDO elfs (#155) 2025-09-06 18:44:18 -04:00
mdebug.h Implement mdebug parsing for static symbols in IDO elfs (#155) 2025-09-06 18:44:18 -04:00
mod_symbols.cpp Add mod merger tool (#168) 2025-12-31 22:17:44 -05:00
operations.cpp Implement remaining float comparisons in the op table (ordered/unordered and signaling/non-signaling still unimplemented) (#144) 2025-07-17 22:50:15 -04:00
recompilation.cpp recompilation: hoist bss → parent remap above relocatable check 2026-05-05 21:17:58 -07:00
symbol_lists.cpp Add open and close to renamed function list 2025-12-03 01:41:55 -05:00