Skip to content

Commit

Permalink
[libc++] Define legacy symbols for inline functions at a finer-graine…
Browse files Browse the repository at this point in the history
…d level

When we build the library with the stable ABI, we need to include some
functions in the dylib that were made inline in later versions of the
library (to avoid breaking code that might be relying on those symbols).

However, those methods were made non-inline whenever we'd be building
the library, which means that all translation units would end up using
the old out-of-line definition of these methods, as opposed to the new
inlined version. This patch makes it so that only the translation units
that actually define the out-of-line methods use the old definition,
opening up potential optimization opportunities in other translation
units.

This should solve some of the issues encountered in D65667.

Differential Revision: https://reviews.llvm.org/D123519
  • Loading branch information
ldionne committed Apr 12, 2022
1 parent cfa4fe7 commit 0cc34ca
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
6 changes: 2 additions & 4 deletions libcxx/include/__memory/shared_ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,7 @@ class _LIBCPP_TYPE_VIS __shared_count
explicit __shared_count(long __refs = 0) _NOEXCEPT
: __shared_owners_(__refs) {}

#if defined(_LIBCPP_BUILDING_LIBRARY) && \
defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS)
#if defined(_LIBCPP_SHARED_PTR_DEFINE_LEGACY_INLINE_FUNCTIONS)
void __add_shared() noexcept;
bool __release_shared() noexcept;
#else
Expand Down Expand Up @@ -200,8 +199,7 @@ class _LIBCPP_TYPE_VIS __shared_weak_count
virtual ~__shared_weak_count();

public:
#if defined(_LIBCPP_BUILDING_LIBRARY) && \
defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS)
#if defined(_LIBCPP_SHARED_PTR_DEFINE_LEGACY_INLINE_FUNCTIONS)
void __add_shared() noexcept;
void __add_weak() noexcept;
void __release_shared() noexcept;
Expand Down
3 changes: 1 addition & 2 deletions libcxx/include/system_error
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,7 @@ class _LIBCPP_TYPE_VIS error_category
public:
virtual ~error_category() _NOEXCEPT;

#if defined(_LIBCPP_BUILDING_LIBRARY) && \
defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS)
#if defined(_LIBCPP_ERROR_CATEGORY_DEFINE_LEGACY_INLINE_FUNCTIONS)
error_category() noexcept;
#else
_LIBCPP_INLINE_VISIBILITY
Expand Down
9 changes: 7 additions & 2 deletions libcxx/src/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
//
//===----------------------------------------------------------------------===//

#include <__config>
#ifdef _LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS
# define _LIBCPP_SHARED_PTR_DEFINE_LEGACY_INLINE_FUNCTIONS
#endif

#include <memory>

#ifndef _LIBCPP_HAS_NO_THREADS
Expand Down Expand Up @@ -38,7 +43,7 @@ __shared_weak_count::~__shared_weak_count()
{
}

#if defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS)
#if defined(_LIBCPP_SHARED_PTR_DEFINE_LEGACY_INLINE_FUNCTIONS)
void
__shared_count::__add_shared() noexcept
{
Expand Down Expand Up @@ -75,7 +80,7 @@ __shared_weak_count::__release_shared() noexcept
__release_weak();
}

#endif // _LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS
#endif // _LIBCPP_SHARED_PTR_DEFINE_LEGACY_INLINE_FUNCTIONS

void
__shared_weak_count::__release_weak() noexcept
Expand Down
8 changes: 6 additions & 2 deletions libcxx/src/system_error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
//
//===----------------------------------------------------------------------===//

#include <__assert>
#include <__config>
#ifdef _LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS
# define _LIBCPP_ERROR_CATEGORY_DEFINE_LEGACY_INLINE_FUNCTIONS
#endif

#include <__assert>
#include <cerrno>
#include <cstdio>
#include <cstdlib>
Expand All @@ -26,7 +30,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD

// class error_category

#if defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS)
#if defined(_LIBCPP_ERROR_CATEGORY_DEFINE_LEGACY_INLINE_FUNCTIONS)
error_category::error_category() noexcept
{
}
Expand Down

0 comments on commit 0cc34ca

Please sign in to comment.