[UBSan] Disable the function and kcfi sanitizers on an execute-only target.
authorYing Yi <ying.yi@sony.com>
Tue, 29 Aug 2023 19:02:13 +0000 (20:02 +0100)
committerTobias Hieta <tobias@hieta.se>
Fri, 1 Sep 2023 06:26:36 +0000 (08:26 +0200)
commitc138c8a72e360c65da7cfe0cd4b716d78cdc428d
treed8d8ddb1d5a9c030f3246dbbba654ce102e1e48d
parente9eaf3dc64a62f3991c03f4176eb7f92034469a3
[UBSan] Disable the function and kcfi sanitizers on an execute-only target.

An execute-only target disallows data access to code sections.
-fsanitize=function and -fsanitize=kcfi instrument indirect function
calls to load a type hash before the function label. This results in a
non-execute access to the code section and a runtime error.

To solve the issue, -fsanitize=function should not be included in any
check group (e.g. undefined) on an execute-only target. If a user passes
-fsanitize=undefined, there is no error and no warning. However, if the
user explicitly passes -fsanitize=function or -fsanitize=kcfi on an
execute-only target, an error will be emitted.

Fixes: https://github.com/llvm/llvm-project/issues/64931.
Reviewed By: MaskRay, probinson, simon_tatham

Differential Revision: https://reviews.llvm.org/D158614
clang/include/clang/Basic/Sanitizers.h
clang/lib/Basic/CMakeLists.txt
clang/lib/Basic/Sanitizers.cpp
clang/lib/Driver/SanitizerArgs.cpp
clang/test/CodeGenObjCXX/crash-function-type.mm
clang/test/Driver/fsanitize.c