[PATCH] D105726: Added fsanitize-address-instrument-via-callback, which controls if address sanitizer will always use a callback.
Kirill Stoimenov via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 9 12:47:13 PDT 2021
kstoimenov created this revision.
kstoimenov added reviewers: kda, vitalybuka.
Herald added a subscriber: dang.
kstoimenov requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Summary This option can be used to reduce the size of the binary. The trade-off in this case would be the run-time performance.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D105726
Files:
clang/include/clang/Driver/Options.td
clang/include/clang/Driver/SanitizerArgs.h
clang/lib/Driver/SanitizerArgs.cpp
clang/test/Driver/fsanitize.c
Index: clang/test/Driver/fsanitize.c
===================================================================
--- clang/test/Driver/fsanitize.c
+++ clang/test/Driver/fsanitize.c
@@ -247,6 +247,13 @@
// CHECK-ASAN-GLOBALS: -cc1{{.*}}-fsanitize-address-globals-dead-stripping
// CHECK-NO-ASAN-GLOBALS-NOT: -cc1{{.*}}-fsanitize-address-globals-dead-stripping
+// RUN: %clang -target x86_64-linux-gnu -fsanitize-address-instrument-via-callback %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ASAN-CALLBACK-WARN
+// CHECK-ASAN-CALLBACK-WARN: warning: argument unused during compilation: '-fsanitize-address-instrument-via-callback'
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=address -fsanitize-address-instrument-via-callback %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ASAN-CALLBACK-OK
+// CHECK-ASAN-CALLBACK-OK: "-mllvm" "-asan-instrumentation-with-call-threshold=0"
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=address -fnosanitize-address-instrument-via-callback %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ASAN-NOCALLBACK
+// CHECK-ASAN-NOCALLBACK-NOT: "-mllvm" "-asan-instrumentation-with-call-threshold=0"
+
// RUN: %clang -target x86_64-linux-gnu -fsanitize=address -fsanitize-address-use-odr-indicator %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ASAN-ODR-INDICATOR
// RUN: %clang_cl --target=x86_64-windows -fsanitize=address -fsanitize-address-use-odr-indicator -### -- %s 2>&1 | FileCheck %s --check-prefix=CHECK-ASAN-ODR-INDICATOR
// CHECK-ASAN-ODR-INDICATOR: -cc1{{.*}}-fsanitize-address-use-odr-indicator
Index: clang/lib/Driver/SanitizerArgs.cpp
===================================================================
--- clang/lib/Driver/SanitizerArgs.cpp
+++ clang/lib/Driver/SanitizerArgs.cpp
@@ -805,6 +805,11 @@
options::OPT_fno_sanitize_address_poison_custom_array_cookie,
AsanPoisonCustomArrayCookie);
+ AsanInstrumentViaCallback =
+ Args.hasFlag(options::OPT_fsanitize_address_instrument_via_callback,
+ options::OPT_fnosanitize_address_instrument_via_callback,
+ AsanInstrumentViaCallback);
+
// As a workaround for a bug in gold 2.26 and earlier, dead stripping of
// globals in ASan is disabled by default on ELF targets.
// See https://sourceware.org/bugzilla/show_bug.cgi?id=19002
@@ -1118,6 +1123,11 @@
CmdArgs.push_back("-asan-detect-invalid-pointer-sub");
}
+ if (AsanInstrumentViaCallback) {
+ CmdArgs.push_back("-mllvm");
+ CmdArgs.push_back("-asan-instrumentation-with-call-threshold=0");
+ }
+
// Only pass the option to the frontend if the user requested,
// otherwise the frontend will just use the codegen default.
if (AsanDtorKind != llvm::AsanDtorKind::Invalid) {
Index: clang/include/clang/Driver/SanitizerArgs.h
===================================================================
--- clang/include/clang/Driver/SanitizerArgs.h
+++ clang/include/clang/Driver/SanitizerArgs.h
@@ -44,6 +44,7 @@
bool AsanUseOdrIndicator = false;
bool AsanInvalidPointerCmp = false;
bool AsanInvalidPointerSub = false;
+ bool AsanInstrumentViaCallback = false;
llvm::AsanDtorKind AsanDtorKind = llvm::AsanDtorKind::Invalid;
std::string HwasanAbi;
bool LinkRuntimes = true;
Index: clang/include/clang/Driver/Options.td
===================================================================
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1558,6 +1558,12 @@
Group<f_clang_Group>,
Flags<[CoreOption, NoXarchOption]>,
HelpText<"Disable origins tracking in MemorySanitizer">;
+def fsanitize_address_instrument_via_callback : Flag<["-"], "fsanitize-address-instrument-via-callback">,
+ Group<f_clang_Group>,
+ HelpText<"Always use callback for the address sanitizer">;
+def fnosanitize_address_instrument_via_callback : Flag<["-"], "fnosanitize-address-instrument-via-callback">,
+ Group<f_clang_Group>,
+ HelpText<"Use default logic for code inlining for the address sanitizer">;
def fsanitize_hwaddress_experimental_aliasing
: Flag<["-"], "fsanitize-hwaddress-experimental-aliasing">,
Group<f_clang_Group>,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105726.357603.patch
Type: text/x-patch
Size: 4442 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210709/22beae56/attachment-0001.bin>
More information about the cfe-commits
mailing list