You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Investigate and address RISC-V-specific JumpStub issues #135607
Not from this PR, but on this line: the inner PCODE jumpStubAddr shadows the one at 12549. So the stub is dropped, the method recompiles, and pc-relative calls are turned off process-wide. Checked with a reduced repro only, not on RISC-V.
The JumpStubs are implemented for RISC-V, but not actually used due to the bug listed above. RISC-V codegen seems to be working around this bug by falling back to indirect calls with long addressing modes.
We should either remove the RISC-V JumpStub implementation entirely, or fix it and remove the corresponding codegen workaround.
TL;DR: From reading the source only, the shadowing means the RISC-V jump-stub path has never used a stub it allocated. Fixing the shadowing alone would switch on a stub that is itself broken, because it leaves ra holding the target; removing the encoder would need per-architecture guards in the shared code that uses it. I would fix the encoder and the assignment first, then drop the codegen workaround. Nothing here was run on RISC-V.
Two data points for the fix-or-remove choice, from reading main at 0d73c1f. I have not built or run anything on RISC-V; the disassembly below is llvm-mc on the constant words in the header.
The shadowing came in with [RISC-V] Synthesizing PC-relative pointer constants #119203, which is also where RISC-V joined JumpStubOverflowCheck and getRelocTypeHint. Here the inner declaration discards the address jumpStub returned, the outer null sets the overflow flag, and the method is recompiled with the absolute form. recordRelocation is the only RISC-V caller of jumpStub, so this path has never used a stub it allocated.
Fixing the shadowing alone switches on a stub that is itself broken. emitBackToBackJump in vm/riscv64/cgencpu.h encodes
auipc ra, 0
ld ra, 16(ra)
ret ; jalr x0, ra, 0
It reaches the target but leaves ra = target. The JIT gets there by auipc ra; jalr ra, ra (ra = return address) or, for a tail jump, auipc t2; jalr x0, t2 (ra = the caller's return address), so a callee returning through that incoming ra re-enters the target. arm64 uses x16 and loongarch64 $r21 here. Of the RISC-V temporaries, t0/t1 carry the profiler-enter arguments, t2 the secret stub parameter and the dispatch token, t3/t4 the write barrier arguments and t5 the indirection cell. t6 (REG_OPT_RSVD) is the one none of those contracts pass across a call; the VSD lookup stub already uses it the same way (auipc t6; ld t2, 24(t6); ld t6, 16(t6); jalr x0, t6), and JIT_WriteBarrier declares it trashed.
On "remove entirely": removing the stub request in recordRelocation is small, though the overflow handling around it also serves the data relocations. The encoder is another matter: it also writes the CLRPersonalityRoutine thunk of every 64-bit code heap that has one, and jumpStub, JumpStubCache and RangeSectionStubManager consume BACK_TO_BACK_JUMP_ALLOCATE_SIZE and decodeBackToBackJump with no per-arch guard, so deleting it means guarding shared code. (loongarch64 is in the same position: its relocation case never asks for a stub.) I did not find anything on Linux that executes that thunk.
On "fix it and remove the codegen workaround": #117196 says it always records the relocation because "it leaves the door open for further code size reductions like arm64, by emitting a single jal instruction and inserting a jump stub". amd64 already works that way for direct calls: genCodeAddrNeedsReloc returns true unconditionally there, and the hint is consulted for data and indirect-call addresses only. RISC-V's emitIns_Call is the one that consults the hint for direct calls and uses li + jalr when IsAddressInRange is false. With a working stub that branch can go, and the recovery when a stub cannot be allocated becomes amd64's: recompile with room reserved for stubs next to the code. The hint stays for the PCREL_I/PCREL_S data relocations. That is the direction I would take, with the encoder and the assignment first; the retry on a failed stub allocation is the part that needs a hardware run.
I found no test that deliberately exercises the stub path; it is reached when the range runs out (±2 GiB here, ±128 MiB on arm64). In Checked builds DOTNET_ForceRelocs sets m_fJumpStubOverflow before the JIT runs, so recordRelocation requests no stub on that pass, and the retry on amd64 and riscv64 turns rel32 off. Once the shadowing is fixed, a Checked-only knob that forces every RISCV64_CALL_PLT through a stub turns the ra defect into a crash the first time a redirected call returns; with the shadowing in place nothing executes the stub at all.
I can put up a PR with the fix, the emitter change and that knob, if that's the direction. It would need someone with hardware to run it: the only linux_riscv64 job I find here builds, and the Helix queue files have no riscv64 entry.
Activity
dotnet-policy-service commentedon Oct 11, 2026
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.
jkotas commentedon Oct 11, 2026
The JumpStubs are implemented for RISC-V, but not actually used due to the bug listed above. RISC-V codegen seems to be working around this bug by falling back to indirect calls with long addressing modes.
We should either remove the RISC-V JumpStub implementation entirely, or fix it and remove the corresponding codegen workaround.
pcshrosbree commentedon Oct 12, 2026
Two data points for the fix-or-remove choice, from reading
mainat 0d73c1f. I have not built or run anything on RISC-V; the disassembly below isllvm-mcon the constant words in the header.The shadowing came in with [RISC-V] Synthesizing PC-relative pointer constants #119203, which is also where RISC-V joined
JumpStubOverflowCheckandgetRelocTypeHint. Here the inner declaration discards the addressjumpStubreturned, the outer null sets the overflow flag, and the method is recompiled with the absolute form.recordRelocationis the only RISC-V caller ofjumpStub, so this path has never used a stub it allocated.Fixing the shadowing alone switches on a stub that is itself broken.
emitBackToBackJumpinvm/riscv64/cgencpu.hencodesIt reaches the target but leaves
ra= target. The JIT gets there byauipc ra; jalr ra, ra(ra= return address) or, for a tail jump,auipc t2; jalr x0, t2(ra= the caller's return address), so a callee returning through that incomingrare-enters the target. arm64 usesx16and loongarch64$r21here. Of the RISC-V temporaries,t0/t1carry the profiler-enter arguments,t2the secret stub parameter and the dispatch token,t3/t4the write barrier arguments andt5the indirection cell.t6(REG_OPT_RSVD) is the one none of those contracts pass across a call; the VSD lookup stub already uses it the same way (auipc t6; ld t2, 24(t6); ld t6, 16(t6); jalr x0, t6), andJIT_WriteBarrierdeclares it trashed.On "remove entirely": removing the stub request in
recordRelocationis small, though the overflow handling around it also serves the data relocations. The encoder is another matter: it also writes theCLRPersonalityRoutinethunk of every 64-bit code heap that has one, andjumpStub,JumpStubCacheandRangeSectionStubManagerconsumeBACK_TO_BACK_JUMP_ALLOCATE_SIZEanddecodeBackToBackJumpwith no per-arch guard, so deleting it means guarding shared code. (loongarch64 is in the same position: its relocation case never asks for a stub.) I did not find anything on Linux that executes that thunk.On "fix it and remove the codegen workaround": #117196 says it always records the relocation because "it leaves the door open for further code size reductions like arm64, by emitting a single
jalinstruction and inserting a jump stub". amd64 already works that way for direct calls:genCodeAddrNeedsRelocreturns true unconditionally there, and the hint is consulted for data and indirect-call addresses only. RISC-V'semitIns_Callis the one that consults the hint for direct calls and usesli+jalrwhenIsAddressInRangeis false. With a working stub that branch can go, and the recovery when a stub cannot be allocated becomes amd64's: recompile with room reserved for stubs next to the code. The hint stays for thePCREL_I/PCREL_Sdata relocations. That is the direction I would take, with the encoder and the assignment first; the retry on a failed stub allocation is the part that needs a hardware run.I found no test that deliberately exercises the stub path; it is reached when the range runs out (±2 GiB here, ±128 MiB on arm64). In Checked builds
DOTNET_ForceRelocssetsm_fJumpStubOverflowbefore the JIT runs, sorecordRelocationrequests no stub on that pass, and the retry on amd64 and riscv64 turns rel32 off. Once the shadowing is fixed, a Checked-only knob that forces everyRISCV64_CALL_PLTthrough a stub turns theradefect into a crash the first time a redirected call returns; with the shadowing in place nothing executes the stub at all.I can put up a PR with the fix, the emitter change and that knob, if that's the direction. It would need someone with hardware to run it: the only linux_riscv64 job I find here builds, and the Helix queue files have no riscv64 entry.
cc @tomeksowi
[RISC-V] Fix jump stubs and emit direct calls PC-relative (dotnet#135610