Index: libcxx/CMakeLists.txt =================================================================== --- libcxx/CMakeLists.txt +++ libcxx/CMakeLists.txt @@ -271,6 +271,9 @@ option(LIBCXX_HERMETIC_STATIC_LIBRARY "Do not export any symbols from the static library." OFF) +option(LIBCXX_ENABLE_DEPENDENT_LIBRARIES + "Embed library dependencies in object files on platforms that support that" OFF) + #=============================================================================== # Check option configurations #=============================================================================== @@ -540,6 +543,10 @@ add_definitions(-D_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS) endif() +if (LIBCXX_ENABLE_DEPENDENT_LIBRARIES) + add_definitions(-D_LIBCPP_ENABLE_DEPENDENT_LIBRARIES) +endif() + # Warning flags =============================================================== add_definitions(-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) add_compile_flags_if_supported( Index: libcxx/include/__threading_support =================================================================== --- libcxx/include/__threading_support +++ libcxx/include/__threading_support @@ -25,6 +25,9 @@ #if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) # include # include +#if defined(__ELF__) && defined(__clang__) && defined(_LIBCPP_ENABLE_DEPENDENT_LIBRARIES) +#pragma comment(lib, "pthread") +#endif #endif _LIBCPP_PUSH_MACROS Index: libcxxabi/CMakeLists.txt =================================================================== --- libcxxabi/CMakeLists.txt +++ libcxxabi/CMakeLists.txt @@ -159,6 +159,9 @@ option(LIBCXXABI_HERMETIC_STATIC_LIBRARY "Do not export any symbols from the static library." OFF) +option(LIBCXXABI_ENABLE_DEPENDENT_LIBRARIES + "Embed library dependencies in object files on platforms that support that" OFF) + #=============================================================================== # Configure System #=============================================================================== @@ -441,6 +444,10 @@ add_definitions(-DLIBCXXABI_BAREMETAL) endif() +if (LIBCXXABI_ENABLE_DEPENDENT_LIBRARIES) + add_definitions(-D_LIBCPP_ENABLE_DEPENDENT_LIBRARIES) +endif() + string(REPLACE ";" " " LIBCXXABI_CXX_FLAGS "${LIBCXXABI_CXX_FLAGS}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LIBCXXABI_CXX_FLAGS}") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LIBCXXABI_C_FLAGS}") Index: libunwind/CMakeLists.txt =================================================================== --- libunwind/CMakeLists.txt +++ libunwind/CMakeLists.txt @@ -171,6 +171,9 @@ option(LIBUNWIND_HERMETIC_STATIC_LIBRARY "Do not export any symbols from the static library." OFF) +option(LIBUNWIND_ENABLE_DEPENDENT_LIBRARIES + "Embed library dependencies in object files on platforms that support that" OFF) + #=============================================================================== # Configure System #=============================================================================== @@ -362,6 +365,10 @@ add_definitions(-D_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS) endif() +if (LIBUNWIND_ENABLE_DEPENDENT_LIBRARIES) + add_definitions(-D_LIBUNWIND_ENABLE_DEPENDENT_LIBRARIES) +endif() + #=============================================================================== # Setup Source Code #=============================================================================== Index: libunwind/src/AddressSpace.hpp =================================================================== --- libunwind/src/AddressSpace.hpp +++ libunwind/src/AddressSpace.hpp @@ -27,6 +27,9 @@ #if _LIBUNWIND_USE_DLADDR #include +#if defined(__ELF__) && defined(__clang__) && defined(_LIBUNWIND_ENABLE_DEPENDENT_LIBRARIES) +#pragma comment(lib, "dl") +#endif #endif #ifdef __APPLE__