[PATCH] D65029: [Driver] Support for disabling sanitizer runtime linking
Petr Hosek via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 19 16:37:39 PDT 2019
phosek created this revision.
phosek added reviewers: vitalybuka, morehouse, kcc.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
This change introduces a pair of -fsanitize-link-deps and
-fno-sanitize-link-deps flags which can be used to control linking
of sanitizer runtimes. This is useful in certain environments like
kernels where existing runtime libraries cannot be used.
Repository:
rC Clang
https://reviews.llvm.org/D65029
Files:
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/test/Driver/sanitizer-ld.c
Index: clang/test/Driver/sanitizer-ld.c
===================================================================
--- clang/test/Driver/sanitizer-ld.c
+++ clang/test/Driver/sanitizer-ld.c
@@ -843,3 +843,19 @@
// CHECK-DSO-SHARED-HWASAN-AARCH64-LINUX-NOT: "-ldl"
// CHECK-DSO-SHARED-HWASAN-AARCH64-LINUX-NOT: "--export-dynamic"
// CHECK-DSO-SHARED-HWASAN-AARCH64-LINUX-NOT: "--dynamic-list"
+
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: -target i386-unknown-linux -fuse-ld=ld -fsanitize=address -fsanitize-link-deps \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN: | FileCheck --check-prefix=CHECK-SANITIZE-LINK-DEPS %s
+//
+// CHECK-SANITIZE-LINK-DEPS: libclang_rt.asan-i386.a"
+
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: -target i386-unknown-linux -fuse-ld=ld -fsanitize=address -fno-sanitize-link-deps \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN: | FileCheck --check-prefix=CHECK-NO-SANITIZE-LINK-DEPS %s
+//
+// CHECK-NO-SANITIZE-LINK-DEPS-NOT: libclang_rt.asan-i386.a"
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===================================================================
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -701,6 +701,10 @@
// C runtime, etc). Returns true if sanitizer system deps need to be linked in.
bool tools::addSanitizerRuntimes(const ToolChain &TC, const ArgList &Args,
ArgStringList &CmdArgs) {
+ if (!Args.hasFlag(options::OPT_fsanitize_link_deps,
+ options::OPT_fno_sanitize_link_deps, true))
+ return false;
+
SmallVector<StringRef, 4> SharedRuntimes, StaticRuntimes,
NonWholeStaticRuntimes, HelperStaticRuntimes, RequiredSymbols;
collectSanitizerRuntimes(TC, Args, SharedRuntimes, StaticRuntimes,
Index: clang/include/clang/Driver/Options.td
===================================================================
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1088,6 +1088,15 @@
HelpText<"Strip (or keep only, if negative) a given number of path components "
"when emitting check metadata.">;
+def fsanitize_link_deps : Flag<["-"], "fsanitize-link-deps">,
+ Group<f_Group>,
+ Flags<[CC1Option]>,
+ HelpText<"Enable linking of sanitizer dependencies">;
+def fno_sanitize_link_deps : Flag<["-"], "fno-sanitize-link-deps">,
+ Group<f_Group>,
+ Flags<[CC1Option]>,
+ HelpText<"Disable linking of sanitizer dependencies">;
+
} // end -f[no-]sanitize* flags
def funsafe_math_optimizations : Flag<["-"], "funsafe-math-optimizations">,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D65029.210936.patch
Type: text/x-patch
Size: 2915 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190719/90ee2407/attachment.bin>
More information about the cfe-commits
mailing list