Skip to content

Commit

Permalink
[runtimes] Support ELF dependent libraries feature
Browse files Browse the repository at this point in the history
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

llvm-svn: 362048
  • Loading branch information
petrhosek committed May 30, 2019
1 parent 7e041d6 commit 996e62e
Show file tree
Hide file tree
Showing 15 changed files with 63 additions and 0 deletions.
5 changes: 5 additions & 0 deletions libcxx/src/algorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@

#include "algorithm"
#include "random"
#ifndef _LIBCPP_HAS_NO_THREADS
#include "mutex"
#if defined(__unix__) && defined(__ELF__) && defined(__clang__)
#pragma comment(lib, "pthread")
#endif
#endif

_LIBCPP_BEGIN_NAMESPACE_STD

Expand Down
4 changes: 4 additions & 0 deletions libcxx/src/chrono.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
#endif
#endif

#if defined(__unix__) && defined(__ELF__) && defined(__clang__)
#pragma comment(lib, "rt")
#endif

_LIBCPP_BEGIN_NAMESPACE_STD

namespace chrono
Expand Down
4 changes: 4 additions & 0 deletions libcxx/src/condition_variable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
#include "system_error"
#include "__undef_macros"

#if defined(__unix__) && defined(__ELF__) && defined(__clang__)
#pragma comment(lib, "pthread")
#endif

_LIBCPP_BEGIN_NAMESPACE_STD

condition_variable::~condition_variable()
Expand Down
5 changes: 5 additions & 0 deletions libcxx/src/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@
#include "string"
#include "cstdio"
#include "__hash_table"
#ifndef _LIBCPP_HAS_NO_THREADS
#include "mutex"
#if defined(__unix__) && defined(__ELF__) && defined(__clang__)
#pragma comment(lib, "pthread")
#endif
#endif

_LIBCPP_BEGIN_NAMESPACE_STD

Expand Down
3 changes: 3 additions & 0 deletions libcxx/src/experimental/memory_resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
#include "atomic"
#elif !defined(_LIBCPP_HAS_NO_THREADS)
#include "mutex"
#if defined(__unix__) && defined(__ELF__) && defined(__clang__)
#pragma comment(lib, "pthread")
#endif
#endif

_LIBCPP_BEGIN_NAMESPACE_LFTS_PMR
Expand Down
4 changes: 4 additions & 0 deletions libcxx/src/filesystem/operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
#include <sys/time.h> // for gettimeofday and timeval
#endif // !defined(CLOCK_REALTIME)

#if defined(__unix__) && defined(__ELF__) && defined(__clang__)
#pragma comment(lib, "rt")
#endif

#if defined(_LIBCPP_COMPILER_GCC)
#if _GNUC_VER < 500
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
Expand Down
3 changes: 3 additions & 0 deletions libcxx/src/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#ifndef _LIBCPP_HAS_NO_THREADS
#include "mutex"
#include "thread"
#if defined(__unix__) && defined(__ELF__) && defined(__clang__)
#pragma comment(lib, "pthread")
#endif
#endif
#include "include/atomic_support.h"

Expand Down
6 changes: 6 additions & 0 deletions libcxx/src/mutex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
#include "include/atomic_support.h"
#include "__undef_macros"

#ifndef _LIBCPP_HAS_NO_THREADS
#if defined(__unix__) && defined(__ELF__) && defined(__clang__)
#pragma comment(lib, "pthread")
#endif
#endif

_LIBCPP_BEGIN_NAMESPACE_STD
#ifndef _LIBCPP_HAS_NO_THREADS

Expand Down
3 changes: 3 additions & 0 deletions libcxx/src/shared_mutex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#ifndef _LIBCPP_HAS_NO_THREADS

#include "shared_mutex"
#if defined(__unix__) && defined(__ELF__) && defined(__clang__)
#pragma comment(lib, "pthread")
#endif

_LIBCPP_BEGIN_NAMESPACE_STD

Expand Down
4 changes: 4 additions & 0 deletions libcxx/src/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
#include <windows.h>
#endif

#if defined(__unix__) && defined(__ELF__) && defined(__clang__)
#pragma comment(lib, "pthread")
#endif

_LIBCPP_BEGIN_NAMESPACE_STD

thread::~thread()
Expand Down
5 changes: 5 additions & 0 deletions libcxxabi/src/cxa_guard_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions libcxxabi/src/cxa_thread_atexit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions libcxxabi/src/fallback_malloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions libunwind/src/AddressSpace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@

#if _LIBUNWIND_USE_DLADDR
#include <dlfcn.h>
#if defined(__unix__) && defined(__ELF__) && defined(__clang__)
#pragma comment(lib, "dl")
#endif
#endif

#ifdef __APPLE__
Expand Down
3 changes: 3 additions & 0 deletions libunwind/src/RWMutex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
#include <windows.h>
#elif !defined(_LIBUNWIND_HAS_NO_THREADS)
#include <pthread.h>
#if defined(__unix__) && defined(__ELF__) && defined(__clang__)
#pragma comment(lib, "pthread")
#endif
#endif

namespace libunwind {
Expand Down

0 comments on commit 996e62e

Please sign in to comment.