[PATCH] ignore --disable-free in clang when leak detection is enabled

Reid Kleckner rnk at google.com
Thu Dec 26 09:47:56 PST 2013


Does LSan have an LD_PRELOAD mode that works without ASan?  Should this
detect that?  If so, this should be a runtime thing, something like a weak
declaration that we use to detect whether LSan is present, and act
accordingly.


On Thu, Dec 26, 2013 at 2:39 AM, Kostya Serebryany <kcc at google.com> wrote:

> Hi chandlerc, dblaikie,
>
> Disobey --disable-free flag if LEAK_SANITIZER macro is defined, for
> PR18320.
> This way the build for LeakSanitizer will need to use
> -DCMAKE_CXX_FLAGS=-DLEAK_SANITIZER
>
> Alternatives:
> 1. use #if __has_feature(address_sanitizer). This will solve our immediate
> need
> to make asan+lsan bootstrap clean, but will not allow to run lsan-only
> (w/o asan).
>
> 2. Check if we have lsan at run-time instead of build time.
> This may actually be nicer, but the only good way to do that that I know of
> is to use weak functions, which will require more ifdefs.
>
> 3. use getenv("CLANG_IS_RUNNING_UNDER_LEAK_DETECTOR").
>
> 4. probably various others, suggestions are welcome.
>
> http://llvm-reviews.chandlerc.com/D2475
>
> Files:
>   lib/Frontend/CompilerInvocation.cpp
>
> Index: lib/Frontend/CompilerInvocation.cpp
> ===================================================================
> --- lib/Frontend/CompilerInvocation.cpp
> +++ lib/Frontend/CompilerInvocation.cpp
> @@ -283,6 +283,16 @@
>    return Success;
>  }
>
> +static bool LeakDetectionIsOn() {
> +#ifdef LEAK_SANITIZER
> +  // If we want to detect leaks with LeakSanitizer,
> +  // -DLEAK_SANITIZER should be passed at compile time.
> +  return 1;
> +#else
> +  return 0;
> +#endif
> +}
> +
>  static bool ParseMigratorArgs(MigratorOptions &Opts, ArgList &Args) {
>    Opts.NoNSAllocReallocError = Args.hasArg(OPT_migrator_no_nsalloc_error);
>    Opts.NoFinalizeRemoval = Args.hasArg(OPT_migrator_no_finalize_removal);
> @@ -368,7 +378,8 @@
>    Opts.CodeModel = Args.getLastArgValue(OPT_mcode_model);
>    Opts.DebugPass = Args.getLastArgValue(OPT_mdebug_pass);
>    Opts.DisableFPElim = Args.hasArg(OPT_mdisable_fp_elim);
> -  Opts.DisableFree = Args.hasArg(OPT_disable_free);
> +  Opts.DisableFree =
> +      LeakDetectionIsOn() ? false : Args.hasArg(OPT_disable_free);
>    Opts.DisableTailCalls = Args.hasArg(OPT_mdisable_tail_calls);
>    Opts.FloatABI = Args.getLastArgValue(OPT_mfloat_abi);
>    Opts.HiddenWeakVTables = Args.hasArg(OPT_fhidden_weak_vtables);
> @@ -742,7 +753,8 @@
>        Diags.Report(diag::err_drv_invalid_value)
>          << A->getAsString(Args) << A->getValue();
>    }
> -  Opts.DisableFree = Args.hasArg(OPT_disable_free);
> +  Opts.DisableFree =
> +      LeakDetectionIsOn() ? false : Args.hasArg(OPT_disable_free);
>
>    Opts.OutputFile = Args.getLastArgValue(OPT_o);
>    Opts.Plugins = Args.getAllArgValues(OPT_load);
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131226/fa121dea/attachment.html>


More information about the cfe-commits mailing list