[cfe-dev] Bug 25496 - clang++ -pg links with -lc++ instead of -lc++_p
David Sanderson via cfe-dev
cfe-dev at lists.llvm.org
Fri Jan 15 17:20:15 PST 2016
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.
Please see https://llvm.org/bugs/show_bug.cgi?id=25496 and
http://reviews.llvm.org/D16102
I filed the bug report with llvm.org back in November of last year, and it
has received no attention. I would like to see the fix submitted to
llvm.org.
Can someone please help?
Regards,
David Sanderson (yelliott at gmail.com)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160115/ccbe5f45/attachment.html>
More information about the cfe-dev
mailing list