r215252 - Add -link-cxx-sanitizer driver flag.
Alexey Samsonov
vonosmas at gmail.com
Fri Aug 8 16:29:13 PDT 2014
Actual flag name is -fsanitize-link-c++-runtime. Sorry for wrong commit
message.
On Fri, Aug 8, 2014 at 3:47 PM, Alexey Samsonov <vonosmas at gmail.com> wrote:
> Author: samsonov
> Date: Fri Aug 8 17:47:17 2014
> New Revision: 215252
>
> URL: http://llvm.org/viewvc/llvm-project?rev=215252&view=rev
> Log:
> Add -link-cxx-sanitizer driver flag.
>
> Summary:
> This flag can be used to force linking of CXX-specific parts
> of sanitizer runtimes into the final executable. It gives more precise
> control than --driver-mode=g++ and comes handy when user links several
> object files with sanitized C++ code into an executable, but wants
> to provide libstdc++ himself, instead of relying on Clang dirver's
> behavior.
>
> Test Plan: clang regression test suite
>
> Reviewers: chandlerc, rsmith
>
> Reviewed By: rsmith
>
> Subscribers: cfe-commits
>
> Differential Revision: http://reviews.llvm.org/D4824
>
> Modified:
> cfe/trunk/include/clang/Driver/Options.td
> cfe/trunk/include/clang/Driver/SanitizerArgs.h
> cfe/trunk/lib/Driver/SanitizerArgs.cpp
> cfe/trunk/lib/Driver/Tools.cpp
> cfe/trunk/test/Driver/sanitizer-ld.c
>
> Modified: cfe/trunk/include/clang/Driver/Options.td
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=215252&r1=215251&r2=215252&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang/Driver/Options.td (original)
> +++ cfe/trunk/include/clang/Driver/Options.td Fri Aug 8 17:47:17 2014
> @@ -535,6 +535,8 @@ def fsanitize_undefined_trap_on_error :
> Group<f_clang_Group>,
> Flags<[CC1Option]>;
> def fno_sanitize_undefined_trap_on_error : Flag<["-"],
> "fno-sanitize-undefined-trap-on-error">,
> Group<f_clang_Group>;
> +def fsanitize_link_cxx_runtime : Flag<["-"],
> "fsanitize-link-c++-runtime">,
> + Group<f_clang_Group>;
> def funsafe_math_optimizations : Flag<["-"],
> "funsafe-math-optimizations">,
> Group<f_Group>;
> def fno_unsafe_math_optimizations : Flag<["-"],
> "fno-unsafe-math-optimizations">,
>
> Modified: cfe/trunk/include/clang/Driver/SanitizerArgs.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/SanitizerArgs.h?rev=215252&r1=215251&r2=215252&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang/Driver/SanitizerArgs.h (original)
> +++ cfe/trunk/include/clang/Driver/SanitizerArgs.h Fri Aug 8 17:47:17 2014
> @@ -52,9 +52,9 @@ class SanitizerArgs {
> bool AsanZeroBaseShadow;
> bool UbsanTrapOnError;
> bool AsanSharedRuntime;
> + bool LinkCXXRuntimes;
>
> public:
> - SanitizerArgs();
> /// Parses the sanitizer arguments from an argument list.
> SanitizerArgs(const ToolChain &TC, const llvm::opt::ArgList &Args);
>
> @@ -77,6 +77,7 @@ class SanitizerArgs {
> return (Kind & HasZeroBaseShadow) || AsanZeroBaseShadow;
> }
> bool needsUnwindTables() const { return Kind & NeedsUnwindTables; }
> + bool linkCXXRuntimes() const { return LinkCXXRuntimes; }
> void addArgs(const llvm::opt::ArgList &Args,
> llvm::opt::ArgStringList &CmdArgs) const;
>
>
> Modified: cfe/trunk/lib/Driver/SanitizerArgs.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/SanitizerArgs.cpp?rev=215252&r1=215251&r2=215252&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Driver/SanitizerArgs.cpp (original)
> +++ cfe/trunk/lib/Driver/SanitizerArgs.cpp Fri Aug 8 17:47:17 2014
> @@ -28,10 +28,7 @@ void SanitizerArgs::clear() {
> AsanZeroBaseShadow = false;
> UbsanTrapOnError = false;
> AsanSharedRuntime = false;
> -}
> -
> -SanitizerArgs::SanitizerArgs() {
> - clear();
> + LinkCXXRuntimes = false;
> }
>
> SanitizerArgs::SanitizerArgs(const ToolChain &TC,
> @@ -168,6 +165,10 @@ SanitizerArgs::SanitizerArgs(const ToolC
> AsanZeroBaseShadow =
> (TC.getTriple().getEnvironment() == llvm::Triple::Android);
> }
> +
> + // Parse -link-cxx-sanitizer flag.
> + LinkCXXRuntimes =
> + Args.hasArg(options::OPT_fsanitize_link_cxx_runtime) ||
> D.CCCIsCXX();
> }
>
> void SanitizerArgs::addArgs(const llvm::opt::ArgList &Args,
>
> Modified: cfe/trunk/lib/Driver/Tools.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=215252&r1=215251&r2=215252&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Driver/Tools.cpp (original)
> +++ cfe/trunk/lib/Driver/Tools.cpp Fri Aug 8 17:47:17 2014
> @@ -2273,13 +2273,13 @@ static void addDfsanRT(const ToolChain &
> static void addSanitizerRuntimes(const ToolChain &TC, const ArgList &Args,
> ArgStringList &CmdArgs) {
> const SanitizerArgs &Sanitize = TC.getSanitizerArgs();
> - const Driver &D = TC.getDriver();
> if (Sanitize.needsUbsanRt())
> - addUbsanRT(TC, Args, CmdArgs, D.CCCIsCXX(),
> - Sanitize.needsAsanRt() || Sanitize.needsTsanRt() ||
> - Sanitize.needsMsanRt() || Sanitize.needsLsanRt());
> + addUbsanRT(TC, Args, CmdArgs, Sanitize.linkCXXRuntimes(),
> + Sanitize.needsAsanRt() || Sanitize.needsTsanRt() ||
> + Sanitize.needsMsanRt() || Sanitize.needsLsanRt());
> if (Sanitize.needsAsanRt())
> - addAsanRT(TC, Args, CmdArgs, Sanitize.needsSharedAsanRt(),
> D.CCCIsCXX());
> + addAsanRT(TC, Args, CmdArgs, Sanitize.needsSharedAsanRt(),
> + Sanitize.linkCXXRuntimes());
> if (Sanitize.needsTsanRt())
> addTsanRT(TC, Args, CmdArgs);
> if (Sanitize.needsMsanRt())
>
> Modified: cfe/trunk/test/Driver/sanitizer-ld.c
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/sanitizer-ld.c?rev=215252&r1=215251&r2=215252&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/Driver/sanitizer-ld.c (original)
> +++ cfe/trunk/test/Driver/sanitizer-ld.c Fri Aug 8 17:47:17 2014
> @@ -195,6 +195,14 @@
> // CHECK-UBSAN-LINUX: "-lpthread"
> // CHECK-UBSAN-LINUX-NOT: "-lstdc++"
>
> +// RUN: %clang -fsanitize=undefined -fsanitize-link-c++-runtime %s -###
> -o %t.o 2>&1 \
> +// RUN: -target i386-unknown-linux \
> +// RUN: --sysroot=%S/Inputs/basic_linux_tree \
> +// RUN: | FileCheck --check-prefix=CHECK-UBSAN-LINUX-LINK-CXX %s
> +// CHECK-UBSAN-LINUX-LINK-CXX-NOT: "-lstdc++"
> +// CHECK-UBSAN-LINUX-LINK-CXX: "-whole-archive"
> "{{.*}}libclang_rt.ubsan_cxx-i386.a" "-no-whole-archive"
> +// CHECK-UBSAN-LINUX-LINK-CXX-NOT: "-lstdc++"
> +
> // RUN: %clangxx -fsanitize=undefined %s -### -o %t.o 2>&1 \
> // RUN: -target i386-unknown-linux \
> // RUN: -resource-dir=%S/Inputs/resource_dir \
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
--
Alexey Samsonov
vonosmas at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140808/48fa4dac/attachment.html>
More information about the cfe-commits
mailing list