diff options
| author | Sergey Matveev <earthdok@google.com> | 2013-05-27 11:17:01 +0000 |
|---|---|---|
| committer | Sergey Matveev <earthdok@google.com> | 2013-05-27 11:17:01 +0000 |
| commit | 1814e9eae3b97b2402835e7c0e90bd5258487bd1 (patch) | |
| tree | 385360539ed90598b08fa682865fe39271fef584 /clang/lib/Driver/Tools.cpp | |
| parent | 9cda3df8bd100071f947da73acfbac5f54eceb59 (diff) | |
| download | bcm5719-llvm-1814e9eae3b97b2402835e7c0e90bd5258487bd1.tar.gz bcm5719-llvm-1814e9eae3b97b2402835e7c0e90bd5258487bd1.zip | |
Add -fsanitize=leak to driver options.
If -fsanitize=leak is specified, link the program with the
LeakSanitizer runtime. Ignore this option when -fsanitize=address is specified,
because AddressSanitizer has this functionality built in.
llvm-svn: 182729
Diffstat (limited to 'clang/lib/Driver/Tools.cpp')
| -rw-r--r-- | clang/lib/Driver/Tools.cpp | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp index 698990d5095..6d66e4b8161 100644 --- a/clang/lib/Driver/Tools.cpp +++ b/clang/lib/Driver/Tools.cpp @@ -1587,6 +1587,7 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC, const ArgList &Args) bool NeedsAsan = needsAsanRt(); bool NeedsTsan = needsTsanRt(); bool NeedsMsan = needsMsanRt(); + bool NeedsLsan = needsLeakDetection(); if (NeedsAsan && NeedsTsan) D.Diag(diag::err_drv_argument_not_allowed_with) << lastArgumentForKind(D, Args, NeedsAsanRt) @@ -1599,6 +1600,18 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC, const ArgList &Args) D.Diag(diag::err_drv_argument_not_allowed_with) << lastArgumentForKind(D, Args, NeedsTsanRt) << lastArgumentForKind(D, Args, NeedsMsanRt); + if (NeedsLsan && NeedsTsan) + D.Diag(diag::err_drv_argument_not_allowed_with) + << lastArgumentForKind(D, Args, NeedsLeakDetection) + << lastArgumentForKind(D, Args, NeedsTsanRt); + if (NeedsLsan && NeedsMsan) + D.Diag(diag::err_drv_argument_not_allowed_with) + << lastArgumentForKind(D, Args, NeedsLeakDetection) + << lastArgumentForKind(D, Args, NeedsMsanRt); + // FIXME: Currenly -fsanitize=leak is silently ignored in the presence of + // -fsanitize=address. Perhaps it should print an error, or perhaps + // -f(-no)sanitize=leak should change whether leak detection is enabled by + // default in ASan? // If -fsanitize contains extra features of ASan, it should also // explicitly contain -fsanitize=address (probably, turned off later in the @@ -1705,9 +1718,8 @@ static void addAsanRTLinux(const ToolChain &TC, const ArgList &Args, TC.getArchName() + "-android.so")); CmdArgs.insert(CmdArgs.begin(), Args.MakeArgString(LibAsan)); } else { - if (!Args.hasArg(options::OPT_shared)) { + if (!Args.hasArg(options::OPT_shared)) addSanitizerRTLinkFlagsLinux(TC, Args, CmdArgs, "asan", true); - } } } @@ -1715,18 +1727,24 @@ static void addAsanRTLinux(const ToolChain &TC, const ArgList &Args, /// This needs to be called before we add the C run-time (malloc, etc). static void addTsanRTLinux(const ToolChain &TC, const ArgList &Args, ArgStringList &CmdArgs) { - if (!Args.hasArg(options::OPT_shared)) { + if (!Args.hasArg(options::OPT_shared)) addSanitizerRTLinkFlagsLinux(TC, Args, CmdArgs, "tsan", true); - } } /// If MemorySanitizer is enabled, add appropriate linker flags (Linux). /// This needs to be called before we add the C run-time (malloc, etc). static void addMsanRTLinux(const ToolChain &TC, const ArgList &Args, ArgStringList &CmdArgs) { - if (!Args.hasArg(options::OPT_shared)) { + if (!Args.hasArg(options::OPT_shared)) addSanitizerRTLinkFlagsLinux(TC, Args, CmdArgs, "msan", true); - } +} + +/// If LeakSanitizer is enabled, add appropriate linker flags (Linux). +/// This needs to be called before we add the C run-time (malloc, etc). +static void addLsanRTLinux(const ToolChain &TC, const ArgList &Args, + ArgStringList &CmdArgs) { + if (!Args.hasArg(options::OPT_shared)) + addSanitizerRTLinkFlagsLinux(TC, Args, CmdArgs, "lsan", true); } /// If UndefinedBehaviorSanitizer is enabled, add appropriate linker flags @@ -6114,13 +6132,15 @@ void gnutools::Link::ConstructJob(Compilation &C, const JobAction &JA, if (Sanitize.needsUbsanRt()) addUbsanRTLinux(getToolChain(), Args, CmdArgs, D.CCCIsCXX, Sanitize.needsAsanRt() || Sanitize.needsTsanRt() || - Sanitize.needsMsanRt()); + Sanitize.needsMsanRt() || Sanitize.needsLsanRt()); if (Sanitize.needsAsanRt()) addAsanRTLinux(getToolChain(), Args, CmdArgs); if (Sanitize.needsTsanRt()) addTsanRTLinux(getToolChain(), Args, CmdArgs); if (Sanitize.needsMsanRt()) addMsanRTLinux(getToolChain(), Args, CmdArgs); + if (Sanitize.needsLsanRt()) + addLsanRTLinux(getToolChain(), Args, CmdArgs); if (D.CCCIsCXX && !Args.hasArg(options::OPT_nostdlib) && |

