Add CFI integer types normalization
authorRamon de C Valle <rcvalle@users.noreply.github.com>
Wed, 1 Feb 2023 16:42:28 +0000 (16:42 +0000)
committerSami Tolvanen <samitolvanen@google.com>
Wed, 1 Feb 2023 17:48:03 +0000 (17:48 +0000)
commitb1e9ab7438a098a18fecda88fc87ef4ccadfcf1e
tree79cb5165645fb92108d943c888a3ed6274ca7cf3
parent6e3d12951dd7d3305f0e33e0aa4038cbd82f245a
Add CFI integer types normalization

This commit adds a new option (i.e.,
`-fsanitize-cfi-icall-normalize-integers`) for normalizing integer types
as vendor extended types for cross-language LLVM CFI/KCFI support with
other languages that can't represent and encode C/C++ integer types.

Specifically, integer types are encoded as their defined representations
(e.g., 8-bit signed integer, 16-bit signed integer, 32-bit signed
integer, ...) for compatibility with languages that define
explicitly-sized integer types (e.g., i8, i16, i32, ..., in Rust).

``-fsanitize-cfi-icall-normalize-integers`` is compatible with
``-fsanitize-cfi-icall-generalize-pointers``.

This helps with providing cross-language CFI support with the Rust
compiler and is an alternative solution for the issue described and
alternatives proposed in the RFC
https://github.com/rust-lang/rfcs/pull/3296.

For more information about LLVM CFI/KCFI and cross-language LLVM
CFI/KCFI support for the Rust compiler, see the design document in the
tracking issue https://github.com/rust-lang/rust/issues/89653.

Reviewed By: pcc, samitolvanen

Differential Revision: https://reviews.llvm.org/D139395
13 files changed:
clang/docs/ControlFlowIntegrity.rst
clang/docs/UsersManual.rst
clang/include/clang/AST/Mangle.h
clang/include/clang/Basic/CodeGenOptions.def
clang/include/clang/Driver/Options.td
clang/include/clang/Driver/SanitizerArgs.h
clang/lib/AST/ItaniumMangle.cpp
clang/lib/AST/MicrosoftMangle.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/Driver/SanitizerArgs.cpp
clang/test/CodeGen/cfi-icall-normalize.c [new file with mode: 0644]
clang/test/CodeGen/cfi-icall-normalize2.c [new file with mode: 0644]
clang/test/CodeGen/kcfi-normalize.c [new file with mode: 0644]