Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aarch64: Fix AuthenticatedRet when stack bytes are popped #6634

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions cranelift/codegen/src/isa/aarch64/inst/emit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3153,6 +3153,21 @@ impl MachInstEmit for Inst {
}
.emit(&[], sink, emit_info, state);
} else {
if stack_bytes_to_pop != 0 {
// The requirement that `stack_bytes_to_pop` fit in an
// `Imm12` isn't fundamental, but lifting it is left for
// future PRs.
let imm12 = Imm12::maybe_from_u64(u64::from(stack_bytes_to_pop))
.expect("stack bytes to pop must fit in Imm12");
Inst::AluRRImm12 {
alu_op: ALUOp::Add,
size: OperandSize::Size64,
rd: writable_stack_reg(),
rn: stack_reg(),
imm12,
}
.emit(&[], sink, emit_info, state);
}
sink.put4(0xd65f0bff | key << 10); // retaa / retab
}
}
Expand Down
2 changes: 1 addition & 1 deletion cranelift/codegen/src/isa/aarch64/inst/emit_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ fn test_aarch64_binemit() {
rets: vec![],
stack_bytes_to_pop: 16,
},
"FF0B5FD6",
"FF430091FF0B5FD6",
"add sp, sp, #16 ; retaa",
));
insns.push((Inst::Pacisp { key: APIKey::B }, "7F2303D5", "pacibsp"));
Expand Down