[libc++] Define legacy symbols for inline functions at a finer-grained 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

NOKEYCHECK=True
GitOrigin-RevId: 0cc34ca7ecfc9d0efee322f60ed6c3169f4f70ca
diff --git a/include/__memory/shared_ptr.h b/include/__memory/shared_ptr.h
index eb52f6e..c1f6248 100644
--- a/include/__memory/shared_ptr.h
+++ b/include/__memory/shared_ptr.h
@@ -162,8 +162,7 @@
     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
@@ -200,8 +199,7 @@
     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;
diff --git a/include/system_error b/include/system_error
index 27e44be..d8ab54c 100644
--- a/include/system_error
+++ b/include/system_error
@@ -202,8 +202,7 @@
 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
diff --git a/src/memory.cpp b/src/memory.cpp
index 1b8c6b7..5ee9cbf 100644
--- a/src/memory.cpp
+++ b/src/memory.cpp
@@ -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
@@ -38,7 +43,7 @@
 {
 }
 
-#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
 {
@@ -75,7 +80,7 @@
         __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
diff --git a/src/system_error.cpp b/src/system_error.cpp
index 66db76c..ba5fa8f 100644
--- a/src/system_error.cpp
+++ b/src/system_error.cpp
@@ -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>
@@ -26,7 +30,7 @@
 
 // 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
 {
 }