diff options
author | Sami Tolvanen <samitolvanen@google.com> | 2023-06-23 16:31:42 +0000 |
---|---|---|
committer | Sami Tolvanen <samitolvanen@google.com> | 2023-06-23 18:25:24 +0000 |
commit | 62fa708ceb027713b386c7e0efda994f8bdc27e2 (patch) | |
tree | f900248495a0a429b1c336b1570cfe1a2f15280b /llvm/lib/Object/ObjectFile.cpp | |
parent | fd65b8da8045a48da0e844d8c31d32af3b9fd882 (diff) | |
download | llvm-62fa708ceb027713b386c7e0efda994f8bdc27e2.zip llvm-62fa708ceb027713b386c7e0efda994f8bdc27e2.tar.gz llvm-62fa708ceb027713b386c7e0efda994f8bdc27e2.tar.bz2 |
[RISCV] Implement KCFI operand bundle lowering
With `-fsanitize=kcfi` (Kernel Control-Flow Integrity), Clang emits
"kcfi" operand bundles to indirect call instructions. Similarly to
the target-specific lowering added in D119296, implement KCFI operand
bundle lowering for RISC-V.
This patch disables the generic KCFI pass for RISC-V in Clang, and
adds the KCFI machine function pass in `RISCVPassConfig::addPreSched`
to emit target-specific `KCFI_CHECK` pseudo instructions before calls
that have KCFI operand bundles. The machine function pass also bundles
the instructions to ensure we emit the checks immediately before the
calls, which is not possible with the generic pass.
`KCFI_CHECK` instructions are lowered in `RISCVAsmPrinter` to a
contiguous code sequence that traps if the expected hash in the
operand bundle doesn't match the hash before the target function
address. This patch emits an `ebreak` instruction for error handling
to match the Linux kernel's `BUG()` implementation. Just like for X86,
we also emit trap locations to a `.kcfi_traps` section to support
error handling, as we cannot embed additional information to the trap
instruction itself.
Reviewed By: MaskRay
Differential Revision: https://reviews.llvm.org/D148385
Diffstat (limited to 'llvm/lib/Object/ObjectFile.cpp')
0 files changed, 0 insertions, 0 deletions