[PATCH] D24048: [Driver] [Darwin] Add sanitizer libraries even if -nodefaultlibs is passed

Filipe Cabecinhas via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 30 12:26:11 PDT 2016


I don't think so. "No default libs" should mean "no default libs", not
"some default libs". Maybe you're using an alternate sanitizer lib or
something, hence usage of that flag.

Thank you,

 Filipe

On Tuesday, 30 August 2016, Chris Bieneman via cfe-commits <
cfe-commits at lists.llvm.org> wrote:

> beanz created this revision.
> beanz added reviewers: zaks.anna, kubabrecka, bogner.
> beanz added a subscriber: cfe-commits.
>
> The -nodefaultlibs and -nostdlib flags suppress all the runtime libraries
> that the driver puts on the link line. This feels wrong. If a user
> specifies "-fsanitize=<blah>" I think it is expected that the sanitizer
> library would be included on the link line.
>
> https://reviews.llvm.org/D24048
>
> Files:
>   lib/Driver/ToolChains.cpp
>   lib/Driver/ToolChains.h
>   lib/Driver/Tools.cpp
>
> Index: lib/Driver/Tools.cpp
> ===================================================================
> --- lib/Driver/Tools.cpp
> +++ lib/Driver/Tools.cpp
> @@ -8032,6 +8032,8 @@
>
>      // Let the tool chain choose which runtime library to link.
>      getMachOToolChain().AddLinkRuntimeLibArgs(Args, CmdArgs);
> +  } else {
> +    getMachOToolChain().AddLinkSanitizerLibArgs(Args, CmdArgs);
>    }
>
>    if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
> Index: lib/Driver/ToolChains.h
> ===================================================================
> --- lib/Driver/ToolChains.h
> +++ lib/Driver/ToolChains.h
> @@ -282,6 +282,10 @@
>    virtual void AddLinkRuntimeLibArgs(const llvm::opt::ArgList &Args,
>                                       llvm::opt::ArgStringList &CmdArgs)
> const;
>
> +  virtual void
> +  AddLinkSanitizerLibArgs(const llvm::opt::ArgList &Args,
> +                          llvm::opt::ArgStringList &CmdArgs) const {}
> +
>    virtual void addStartObjectFileArgs(const llvm::opt::ArgList &Args,
>                                        llvm::opt::ArgStringList &CmdArgs)
> const {
>    }
> @@ -571,6 +575,10 @@
>
>    RuntimeLibType GetRuntimeLibType(const llvm::opt::ArgList &Args) const
> override;
>
> +  void
> +  AddLinkSanitizerLibArgs(const llvm::opt::ArgList &Args,
> +                          llvm::opt::ArgStringList &CmdArgs) const
> override;
> +
>    void AddLinkRuntimeLibArgs(const llvm::opt::ArgList &Args,
>                               llvm::opt::ArgStringList &CmdArgs) const
> override;
>
> Index: lib/Driver/ToolChains.cpp
> ===================================================================
> --- lib/Driver/ToolChains.cpp
> +++ lib/Driver/ToolChains.cpp
> @@ -425,22 +425,7 @@
>      return;
>    }
>
> -  const SanitizerArgs &Sanitize = getSanitizerArgs();
> -  if (Sanitize.needsAsanRt())
> -    AddLinkSanitizerLibArgs(Args, CmdArgs, "asan");
> -  if (Sanitize.needsUbsanRt())
> -    AddLinkSanitizerLibArgs(Args, CmdArgs, "ubsan");
> -  if (Sanitize.needsTsanRt())
> -    AddLinkSanitizerLibArgs(Args, CmdArgs, "tsan");
> -  if (Sanitize.needsStatsRt()) {
> -    StringRef OS = isTargetMacOS() ? "osx" : "iossim";
> -    AddLinkRuntimeLib(Args, CmdArgs,
> -                      (Twine("libclang_rt.stats_client_") + OS +
> ".a").str(),
> -                      /*AlwaysLink=*/true);
> -    AddLinkSanitizerLibArgs(Args, CmdArgs, "stats");
> -  }
> -  if (Sanitize.needsEsanRt())
> -    AddLinkSanitizerLibArgs(Args, CmdArgs, "esan");
> +  AddLinkSanitizerLibArgs(Args, CmdArgs);
>
>    // Otherwise link libSystem, then the dynamic runtime library, and
> finally any
>    // target specific static runtime library.
> @@ -495,6 +480,26 @@
>    }
>  }
>
> +void DarwinClang::AddLinkSanitizerLibArgs(
> +    const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs)
> const {
> +  const SanitizerArgs &Sanitize = getSanitizerArgs();
> +  if (Sanitize.needsAsanRt())
> +    AddLinkSanitizerLibArgs(Args, CmdArgs, "asan");
> +  if (Sanitize.needsUbsanRt())
> +    AddLinkSanitizerLibArgs(Args, CmdArgs, "ubsan");
> +  if (Sanitize.needsTsanRt())
> +    AddLinkSanitizerLibArgs(Args, CmdArgs, "tsan");
> +  if (Sanitize.needsStatsRt()) {
> +    StringRef OS = isTargetMacOS() ? "osx" : "iossim";
> +    AddLinkRuntimeLib(Args, CmdArgs,
> +                      (Twine("libclang_rt.stats_client_") + OS +
> ".a").str(),
> +                      /*AlwaysLink=*/true);
> +    AddLinkSanitizerLibArgs(Args, CmdArgs, "stats");
> +  }
> +  if (Sanitize.needsEsanRt())
> +    AddLinkSanitizerLibArgs(Args, CmdArgs, "esan");
> +}
> +
>  void Darwin::AddDeploymentTarget(DerivedArgList &Args) const {
>    const OptTable &Opts = getDriver().getOpts();
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160830/a33b49f3/attachment.html>


More information about the cfe-commits mailing list