This is an archive of the discontinued LLVM Phabricator instance.

[JITLink] Fix the incorrect relocation behavior for R_RISCV_BRANCH and extractBits function
ClosedPublic

Authored by StephenFan on Jan 25 2022, 8:09 AM.

Details

Summary

In D116573, the relocation behavior of R_RISCV_BRANCH didn't consider that branch instruction like 'bge' has a branch target address which is given as a PC-relative offset, sign-extend and multiplied by 2.
Although the target address is a 12-bits number, acctually its range is [-4096, 4094].

The previous function extractBits was incorrect due to it would extract one more bit each time.

This patch fix both of these problems.

Diff Detail

Event Timeline

StephenFan created this revision.Jan 25 2022, 8:09 AM
StephenFan requested review of this revision.Jan 25 2022, 8:09 AM
StephenFan retitled this revision from [JITLink] Fix the incorrect relocation behavior for R_RISCV_BRANCH to [JITLink] Fix the incorrect relocation behavior for R_RISCV_BRANCH and extractBits function.Jan 25 2022, 8:12 AM
StephenFan edited the summary of this revision. (Show Details)

Hi, could you please update the code comments on R_RISCV_BRANCH in llvm/include/llvm/ExecutionEngine/JITLink/riscv.h
at the same time?

fix comments in riscv.h

fourdim accepted this revision.Jan 26 2022, 9:01 AM

LGTM

This revision is now accepted and ready to land.Jan 26 2022, 9:01 AM
lhames accepted this revision.Jan 29 2022, 2:59 AM

Patch should be clang-format'd to eliminate the lint warnings, but otherwise LGTM. Thanks Stephen and Siwei!

clang-format and rebase

This revision was landed with ongoing or failed builds.Feb 6 2022, 10:39 PM
This revision was automatically updated to reflect the committed changes.