[libcxx-commits] [libcxxabi] r362048 - [runtimes] Support ELF dependent libraries feature

Petr Hosek via libcxx-commits libcxx-commits at lists.llvm.org
Wed May 29 18:34:42 PDT 2019


Author: phosek
Date: Wed May 29 18:34:41 2019
New Revision: 362048

URL: http://llvm.org/viewvc/llvm-project?rev=362048&view=rev
Log:
[runtimes] Support ELF dependent libraries feature

As of r360984, LLD supports dependent libraries feature for ELF.
libunwind, libc++abi and libc++ have library dependencies: libdl librt
and libpthread, which means that when libunwind and libc++ are being
statically linked (using -static-libstdc++ flag), user has to manually
specify -ldl -lpthread which is onerous.

This change includes the lib pragma to specify the library dependencies
directly in the source that uses those libraries. This doesn't make any
difference when using linkers that don't support dependent libraries.
However, when using LLD that has dependent libraries feature, users no
longer have to manually specifying library dependencies when using
static linking, linker will pick the library automatically.

Differential Revision: https://reviews.llvm.org/D62090

Modified:
    libcxxabi/trunk/src/cxa_guard_impl.h
    libcxxabi/trunk/src/cxa_thread_atexit.cpp
    libcxxabi/trunk/src/fallback_malloc.cpp

Modified: libcxxabi/trunk/src/cxa_guard_impl.h
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/cxa_guard_impl.h?rev=362048&r1=362047&r2=362048&view=diff
==============================================================================
--- libcxxabi/trunk/src/cxa_guard_impl.h (original)
+++ libcxxabi/trunk/src/cxa_guard_impl.h Wed May 29 18:34:41 2019
@@ -49,6 +49,11 @@
 
 #include <stdlib.h>
 #include <__threading_support>
+#ifndef _LIBCXXABI_HAS_NO_THREADS
+#if defined(__unix__) &&  defined(__ELF__) && defined(__clang__)
+#pragma comment(lib, "pthread")
+#endif
+#endif
 
 // To make testing possible, this header is included from both cxa_guard.cpp
 // and a number of tests.

Modified: libcxxabi/trunk/src/cxa_thread_atexit.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/cxa_thread_atexit.cpp?rev=362048&r1=362047&r2=362048&view=diff
==============================================================================
--- libcxxabi/trunk/src/cxa_thread_atexit.cpp (original)
+++ libcxxabi/trunk/src/cxa_thread_atexit.cpp Wed May 29 18:34:41 2019
@@ -9,6 +9,12 @@
 #include "abort_message.h"
 #include "cxxabi.h"
 #include <__threading_support>
+#ifndef _LIBCXXABI_HAS_NO_THREADS
+#if defined(__unix__) &&  defined(__ELF__) && defined(__clang__)
+#pragma comment(lib, "pthread")
+#endif
+#endif
+
 #include <cstdlib>
 
 namespace __cxxabiv1 {

Modified: libcxxabi/trunk/src/fallback_malloc.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/fallback_malloc.cpp?rev=362048&r1=362047&r2=362048&view=diff
==============================================================================
--- libcxxabi/trunk/src/fallback_malloc.cpp (original)
+++ libcxxabi/trunk/src/fallback_malloc.cpp Wed May 29 18:34:41 2019
@@ -12,6 +12,11 @@
 #include "fallback_malloc.h"
 
 #include <__threading_support>
+#ifndef _LIBCXXABI_HAS_NO_THREADS
+#if defined(__unix__) &&  defined(__ELF__) && defined(__clang__)
+#pragma comment(lib, "pthread")
+#endif
+#endif
 
 #include <cstdlib> // for malloc, calloc, free
 #include <cstring> // for memset




More information about the libcxx-commits mailing list