From: Dimitry Andric Date: Sun, 14 Feb 2016 16:08:20 +0000 (+0000) Subject: As reported in https://llvm.org/bugs/show_bug.cgi?id=25496, on FreeBSD, X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3c7f04f6360bef27557212d7c1b4662f6e5aeb76;p=clang As reported in https://llvm.org/bugs/show_bug.cgi?id=25496, on FreeBSD, C++ programs compiled for profiling (using `-pg`) should be linked with `-lc++_p` (or `-lstdc++_p`, depending on the `-stdlib=` setting), not with the regular C++ libraries. Add a `FreeBSD::AddCXXStdlibLibArgs()` override to handle this, and add a test case for it. While here, extend the test case for the proper passing of -lm and -lm_p. Reviewers: compnerd, davide, dws, emaste Reviewed By: compnerd Differential Revision: http://reviews.llvm.org/D16264 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@260851 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Driver/ToolChains.cpp b/lib/Driver/ToolChains.cpp index cb5e7329cd..ae24e4731b 100644 --- a/lib/Driver/ToolChains.cpp +++ b/lib/Driver/ToolChains.cpp @@ -3128,6 +3128,22 @@ void FreeBSD::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, } } +void FreeBSD::AddCXXStdlibLibArgs(const ArgList &Args, + ArgStringList &CmdArgs) const { + CXXStdlibType Type = GetCXXStdlibType(Args); + bool Profiling = Args.hasArg(options::OPT_pg); + + switch (Type) { + case ToolChain::CST_Libcxx: + CmdArgs.push_back(Profiling ? "-lc++_p" : "-lc++"); + break; + + case ToolChain::CST_Libstdcxx: + CmdArgs.push_back(Profiling ? "-lstdc++_p" : "-lstdc++"); + break; + } +} + Tool *FreeBSD::buildAssembler() const { return new tools::freebsd::Assembler(*this); } diff --git a/lib/Driver/ToolChains.h b/lib/Driver/ToolChains.h index 127f37f549..11e4c834b4 100644 --- a/lib/Driver/ToolChains.h +++ b/lib/Driver/ToolChains.h @@ -728,6 +728,8 @@ public: void AddClangCXXStdlibIncludeArgs( const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override; + void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args, + llvm::opt::ArgStringList &CmdArgs) const override; bool UseSjLjExceptions(const llvm::opt::ArgList &Args) const override; bool isPIEDefault() const override; diff --git a/test/Driver/freebsd.cpp b/test/Driver/freebsd.cpp index dea3267233..175b873bf4 100644 --- a/test/Driver/freebsd.cpp +++ b/test/Driver/freebsd.cpp @@ -2,5 +2,12 @@ // RUN: | FileCheck --check-prefix=CHECK-TEN %s // RUN: %clangxx %s -### -o %t.o -target amd64-unknown-freebsd9.2 2>&1 \ // RUN: | FileCheck --check-prefix=CHECK-NINE %s -// CHECK-TEN: -lc++ -// CHECK-NINE: -lstdc++ +// CHECK-TEN: "-lc++" "-lm" +// CHECK-NINE: "-lstdc++" "-lm" + +// RUN: %clangxx %s -### -pg -o %t.o -target amd64-unknown-freebsd10.0 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-PG-TEN %s +// RUN: %clangxx %s -### -pg -o %t.o -target amd64-unknown-freebsd9.2 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-PG-NINE %s +// CHECK-PG-TEN: "-lc++_p" "-lm_p" +// CHECK-PG-NINE: "-lstdc++_p" "-lm_p"