Skip to content

RISC-V: Lifting bug in JALR rd, rs1, imm when rd == rs1 #6003

@jeanmicheldeva

Description

@jeanmicheldeva

See here:

let target = il.add(max_width, Register::from(rs1), imm).build();
match (rd.id(), rs1.id(), imm) {
(0, 1, 0) => il.ret(target).append(), // jalr zero, ra, 0
(1, _, _) => il.call(target).append(), // indirect call
(0, _, _) => il.jump(target).append(), // indirect jump
(_, _, _) => {
// indirect jump with storage of next address to non-`ra` register
il.set_reg(
max_width,
Register::from(rd),
il.const_ptr(addr.wrapping_add(inst_len)),
)
.append();
il.jump(target).append();

If rd == rs1, but is neither zero or ra (x0 or x1 resp.), the above code will lift the jalr rd, rs1, imm instruction as follows:

# let's say rd == rs1 == t1
# target = t1 + imm
t1 = pc + 4            # inst_len==4
jump(target) <=> jump(t1 + imm) <=> jump(pc + 4 + imm)

Whereas the intended code should be lifted as:

tmp_register = t1 + imm
t1 = pc + 4
jump(tmp_register)

Metadata

Metadata

Assignees

Labels

Arch: RISC-VIssues with the RISC-V architecture pluginComponent: ArchitectureIssue needs changes to an architecture pluginEffort: LowIssues require < 1 week of workImpact: LowIssue is a papercut or has a good, supported workaround

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions