<html>
<head>
<base href="https://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - clang++ -pg links with -lc++ instead of -lc++_p"
href="https://llvm.org/bugs/show_bug.cgi?id=25496">25496</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>clang++ -pg links with -lc++ instead of -lc++_p
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>3.7
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Driver
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>yelliott@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>I'm seeing a link failure when using "clang++ -pg" to link a program.
I first saw the problem on FreeBSD 10.1:
$ clang -v
FreeBSD clang version 3.4.1 (tags/RELEASE_34/dot1-final 208032) 20140512
Target: x86_64-unknown-freebsd10.1
I was able to reproduce the problem on FreeBSD 11.0-CURRENT:
$ clang -v
FreeBSD clang version 3.7.0 (tags/RELEASE_370/final 246257) 20150906
Target: x86_64-unknown-freebsd11.0
Here is a small test script to reproduce the problem:
#!/bin/sh -x
clang++ -pg -o foo -x c++ - -pthread <<\!EOF!
#include <pthread.h>
static pthread_mutex_t mutex;
int main(int argc, char **argv) { pthread_mutex_lock(&mutex); return 0; }
!EOF!
The failure looks like this:
+ clang++ -pg -o foo -x c++ - -pthread
/usr/bin/ld: //lib/libgcc_s.so.1: invalid DSO for symbol
`_Unwind_ForcedUnwind@@GCC_3.0' definition
//lib/libgcc_s.so.1: could not read symbols: Bad value
clang++: error: linker command failed with exit code 1 (use -v to see
invocation)
On success, the program compiles and links without any warnings.
If you add -v to the clang++ command line, you can see that it's linking with
-lc++, whereas all the other "system" type libraries that it's linking with
have "_p" tacked onto their names. When I adjusted the driver to use -lc++_p
in this case, the link proceeded without errors. The diff (in the FreeBSD HEAD
tree) looked like this:
Index: contrib/llvm/tools/clang/lib/Driver/ToolChain.cpp
===================================================================
--- contrib/llvm/tools/clang/lib/Driver/ToolChain.cpp (revision 290623)
+++ contrib/llvm/tools/clang/lib/Driver/ToolChain.cpp (working copy)
@@ -451,7 +451,11 @@
switch (Type) {
case ToolChain::CST_Libcxx:
- CmdArgs.push_back("-lc++");
+ if (Args.hasArg(options::OPT_pg)) {
+ CmdArgs.push_back("-lc++_p");
+ } else {
+ CmdArgs.push_back("-lc++");
+ }
break;
case ToolChain::CST_Libstdcxx:
I don't claim that this is a comprehensive solution -- there seem to be quite a
few places in the driver that know about "-lc++" -- but it was enough to solve
the problem that I was seeing on FreeBSD.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>