From adbdef6a9f39058f390ba285624b0dfb24bad7e8 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Wed, 19 Apr 2023 13:15:33 -0700 Subject: [PATCH] [Driver] Make -fsanitize=kcfi,function incompatible A -fsanitize=kcfi instrumented function has a special instruction/data before the function entry at a fixed offset. A -fsanitize=function instrumented function has special instruction/data after the function entry at a fixed offset (may change to *before* in D148665). The two instrumentations are not intended to be used together and will become incompatible after D148665. Reviewed By: samitolvanen Differential Revision: https://reviews.llvm.org/D148671 --- clang/lib/Driver/SanitizerArgs.cpp | 3 ++- clang/test/Driver/fsanitize.c | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/clang/lib/Driver/SanitizerArgs.cpp b/clang/lib/Driver/SanitizerArgs.cpp index d0dd294..8fe8ef2 100644 --- a/clang/lib/Driver/SanitizerArgs.cpp +++ b/clang/lib/Driver/SanitizerArgs.cpp @@ -517,7 +517,8 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC, std::make_pair(SanitizerKind::MemTag, SanitizerKind::Address | SanitizerKind::KernelAddress | SanitizerKind::HWAddress | - SanitizerKind::KernelHWAddress)}; + SanitizerKind::KernelHWAddress), + std::make_pair(SanitizerKind::KCFI, SanitizerKind::Function)}; // Enable toolchain specific default sanitizers if not explicitly disabled. SanitizerMask Default = TC.getDefaultSanitizers() & ~AllRemove; diff --git a/clang/test/Driver/fsanitize.c b/clang/test/Driver/fsanitize.c index 3b89e13..e12f11b 100644 --- a/clang/test/Driver/fsanitize.c +++ b/clang/test/Driver/fsanitize.c @@ -674,6 +674,9 @@ // RUN: %clang --target=x86_64-linux-gnu -fsanitize=kcfi -fno-sanitize-recover=kcfi %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-KCFI-RECOVER // CHECK-KCFI-RECOVER: error: unsupported argument 'kcfi' to option '-fno-sanitize-recover=' +// RUN: %clang --target=x86_64-linux-gnu -fsanitize=kcfi,function %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-KCFI-FUNCTION +// CHECK-KCFI-FUNCTION: error: invalid argument '-fsanitize=kcfi' not allowed with '-fsanitize=function' + // RUN: %clang_cl -fsanitize=address -c -MDd -### -- %s 2>&1 | FileCheck %s -check-prefix=CHECK-ASAN-DEBUGRTL // RUN: %clang_cl -fsanitize=address -c -MTd -### -- %s 2>&1 | FileCheck %s -check-prefix=CHECK-ASAN-DEBUGRTL // RUN: %clang_cl -fsanitize=address -c -LDd -### -- %s 2>&1 | FileCheck %s -check-prefix=CHECK-ASAN-DEBUGRTL -- 2.7.4