Branch: refs/heads/bbiiggppiigg/amdgpu-branch-offset-fix
Home: https://github.com/dyninst/dyninst
Commit: 1ea07c44ca4bdff08ca5c8d5792d61da27c76489
https://github.com/dyninst/dyninst/commit/1ea07c44ca4bdff08ca5c8d5792d61da27c76489
Author: wuxx1279 <bbiiggppiigg@xxxxxxxxx>
Date: 2026-07-07 (Tue, 07 Jul 2026)
Changed paths:
M dyninstAPI/src/codegen/codegen-amdgpu.C
Log Message:
-----------
AMDGPU: fix SOPP short-branch relocation off-by-one (S_BRANCH PC+4)
gfx908 S_BRANCH / s_cbranch_* (SOPP) compute their destination relative to the
instruction AFTER the branch: target = (PC_of_branch + 4) + SIMM16*4. The
short-branch emitters in codegen-amdgpu.C encoded SIMM16 = disp/4, omitting the
-1 that accounts for that +4, so every displacement-computed short branch landed
one instruction (4 bytes) past its intended target.
Fix the three displacement-based emitters to compute SIMM16 = disp/4 - 1:
- insnCodeGen::generateBranch (short-jump path)
- insnCodeGen::modifyJump
- insnCodeGen::modifyJcc (the jump-to-target of the conditional-branch expansion)
The -1 is direction-agnostic (it is +4 expressed in dword units) and holds for
both forward and backward jumps. emitLongJump already accounts for this
(fromAddress + 4); the literal emitShortJump(1) skip-jumps in modifyJcc are
intentionally SIMM16=1 and are unchanged.
Impact: straight-line code only emits long jumps, so this was latent. Loops and
if/else emit short intra-function branches; a relocated loop back-edge landed on
loop-head+1, dropping the loop head's first instruction (e.g. an induction
variable update) out of the loop -> infinite loop / wrong results.
Co-Authored-By: Claude Opus 4.8 <noreply@xxxxxxxxxxxxx>
To unsubscribe from these emails, change your notification settings at https://github.com/dyninst/dyninst/settings/notifications
|