[PATCH] D65572: Fix static linking failure with --unwindlib=libunwind

Khem Raj via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 1 06:22:58 PDT 2019

raj.khem created this revision.
raj.khem added a reviewer: rengolin.
raj.khem added a project: clang.
Herald added subscribers: cfe-commits, jfb.

when trying to use llvm libunwind via clang driver option --unwindlib and using -static together, linking fails with missing symbols

  libunwind/src/RWMutex.hpp:68: undefined reference to `pthread_rwlock_wrlock'
  libunwind/src/AddressSpace.hpp:597: undefined reference to `dladdr'

There are missing symbols in linunwind.a which should be coming from libpthread and libdl

  rC Clang



Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1185,6 +1185,10 @@
   case ToolChain::UNW_CompilerRT:
+    if (Args.hasArg(options::OPT_static)) {
+      CmdArgs.push_back("-lpthread");
+      CmdArgs.push_back("-ldl");
+    }

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D65572.212797.patch
Type: text/x-patch
Size: 455 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190801/f471da66/attachment.bin>

More information about the cfe-commits mailing list