Initial forward-edge CFI implementation (#3693)
* Initial forward-edge CFI implementation Give the user the option to start all basic blocks that are targets of indirect branches with the BTI instruction introduced by the Branch Target Identification extension to the Arm instruction set architecture. Copyright (c) 2022, Arm Limited. * Refactor `from_artifacts` to avoid second `make_executable` (#1) This involves "parsing" twice but this is parsing just the header of an ELF file so it's not a very intensive operation and should be ok to do twice. * Address the code review feedback Copyright (c) 2022, Arm Limited. Co-authored-by: Alex Crichton <alex@alexcrichton.com>
This commit is contained in:
@@ -657,18 +657,20 @@ pub(crate) fn lower_branch(
|
||||
// emit_island // this forces an island at this point
|
||||
// // if the jumptable would push us past
|
||||
// // the deadline
|
||||
// subs idx, #jt_size
|
||||
// cmp idx, #jt_size
|
||||
// b.hs default
|
||||
// csel vTmp2, xzr, idx, hs
|
||||
// csdb
|
||||
// adr vTmp1, PC+16
|
||||
// ldr vTmp2, [vTmp1, idx, lsl #2]
|
||||
// add vTmp2, vTmp2, vTmp1
|
||||
// br vTmp2
|
||||
// ldr vTmp2, [vTmp1, vTmp2, uxtw #2]
|
||||
// add vTmp1, vTmp1, vTmp2
|
||||
// br vTmp1
|
||||
// [jumptable offsets relative to JT base]
|
||||
let jt_size = targets.len() - 1;
|
||||
assert!(jt_size <= std::u32::MAX as usize);
|
||||
|
||||
ctx.emit(Inst::EmitIsland {
|
||||
needed_space: 4 * (6 + jt_size) as CodeOffset,
|
||||
needed_space: 4 * (8 + jt_size) as CodeOffset,
|
||||
});
|
||||
|
||||
let ridx = put_input_in_reg(
|
||||
@@ -707,8 +709,10 @@ pub(crate) fn lower_branch(
|
||||
// Emit the compound instruction that does:
|
||||
//
|
||||
// b.hs default
|
||||
// csel rB, xzr, rIndex, hs
|
||||
// csdb
|
||||
// adr rA, jt
|
||||
// ldrsw rB, [rA, rIndex, UXTW 2]
|
||||
// ldrsw rB, [rA, rB, uxtw #2]
|
||||
// add rA, rA, rB
|
||||
// br rA
|
||||
// [jt entries]
|
||||
|
||||
Reference in New Issue
Block a user