Index: lib/Driver/ToolChains.h =================================================================== --- lib/Driver/ToolChains.h +++ lib/Driver/ToolChains.h @@ -728,6 +728,8 @@ 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; Index: lib/Driver/ToolChains.cpp =================================================================== --- lib/Driver/ToolChains.cpp +++ lib/Driver/ToolChains.cpp @@ -3128,6 +3128,22 @@ } } +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); } Index: test/Driver/freebsd.cpp =================================================================== --- test/Driver/freebsd.cpp +++ 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"