This is an archive of the discontinued LLVM Phabricator instance.

For FreeBSD, use _p variants of libraries for linking C++ programs
ClosedPublic

Authored by dim on Jan 16 2016, 4:08 PM.

Details

Summary

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.

This review is intended to replace D16102.

Diff Detail

Event Timeline

dim updated this revision to Diff 45085.Jan 16 2016, 4:08 PM
dim retitled this revision from to For FreeBSD, use _p variants of libraries for linking C++ programs.
dim updated this object.
dim added reviewers: compnerd, davide, dws, emaste.
dim added subscribers: rpokala, cfe-commits.
dws edited edge metadata.Jan 18 2016, 5:48 PM

I will try this out on a system running FreeBSD HEAD (as of r294306) and see how it does.

compnerd edited edge metadata.Jan 30 2016, 1:01 PM

-p or -pg also effects the math library. Please adjust the tests and the driver to reflect that.

dim added a comment.Jan 30 2016, 1:38 PM

-p or -pg also effects the math library. Please adjust the tests and the driver to reflect that.

This is already handled in lib/Driver/Tools.cpp, in freebsd::Linker::ConstructJob():

if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
  if (D.CCCIsCXX()) {
    getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
    if (Args.hasArg(options::OPT_pg))
      CmdArgs.push_back("-lm_p");
    else
      CmdArgs.push_back("-lm");
  }

I think it would be better if we could actually create a helper to get the profiling library name for a specific library, and use that in both locations.

Do we have a test for the math case at the very least?

dim updated this revision to Diff 47913.Feb 13 2016, 8:34 AM
dim edited edge metadata.

Add checks for -lm and -lm_p, when profiling is on.

compnerd accepted this revision.Feb 13 2016, 7:22 PM
compnerd edited edge metadata.
This revision is now accepted and ready to land.Feb 13 2016, 7:22 PM
This revision was automatically updated to reflect the committed changes.