Skip to content

Commit

Permalink
As reported in https://llvm.org/bugs/show_bug.cgi?id=25496, on FreeBSD,
Browse files Browse the repository at this point in the history
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

llvm-svn: 260851
  • Loading branch information
DimitryAndric committed Feb 14, 2016
1 parent 24c2a9a commit 6090739
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
16 changes: 16 additions & 0 deletions clang/lib/Driver/ToolChains.cpp
Expand Up @@ -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);
}
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/Driver/ToolChains.h
Expand Up @@ -728,6 +728,8 @@ class LLVM_LIBRARY_VISIBILITY FreeBSD : public Generic_ELF {
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;
Expand Down
11 changes: 9 additions & 2 deletions clang/test/Driver/freebsd.cpp
Expand Up @@ -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"

0 comments on commit 6090739

Please sign in to comment.