Skip to content

Conversation

@ldionne
Copy link
Member

@ldionne ldionne commented Dec 3, 2024

Closes #112395

@ldionne ldionne requested a review from a team as a code owner December 3, 2024 18:50
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Dec 3, 2024
@llvmbot
Copy link
Member

llvmbot commented Dec 3, 2024

@llvm/pr-subscribers-libcxx

Author: Louis Dionne (ldionne)

Changes

Closes #112395


Full diff: https://github.com/llvm/llvm-project/pull/118526.diff

1 Files Affected:

  • (modified) libcxx/docs/CodingGuidelines.rst (+16)
diff --git a/libcxx/docs/CodingGuidelines.rst b/libcxx/docs/CodingGuidelines.rst
index 4d3dd12e56bf12..1bb62072e886d1 100644
--- a/libcxx/docs/CodingGuidelines.rst
+++ b/libcxx/docs/CodingGuidelines.rst
@@ -168,3 +168,19 @@ have a recommended practice where to put them, so libc++ applies it whenever it
 Applications of ``[[nodiscard]]`` are code like any other code, so we aim to test them on public interfaces. This can be
 done with a ``.verify.cpp`` test. Many examples are available. Just look for tests with the suffix
 ``.nodiscard.verify.cpp``.
+
+Don't use public API names for symbols on the ABI boundary
+==========================================================
+
+Most functions in libc++ are defined in headers either as templates or as ``inline`` functions. However, we sometimes
+need or want to define functions in the built library. Symbols that are declared in the headers and defined in the
+built library become part of the ABI of libc++, which must be preserved for backwards compatibility. This means that
+we can't easily remove or rename such symbols except in special cases.
+
+When adding a symbol to the built library, make sure not to use a public name directly. Instead, define a
+``_LIBCPP_HIDE_FROM_ABI`` function in the headers with the public name and have it call a private function in the built
+library. This approach makes it easier to make changes to libc++ like move something from the built library to the
+headers (which is sometimes required for ``constexpr`` support).
+
+When defining a function at the ABI boundary, it can also be useful to consider which attributes (like ``[[gnu::pure]]``
+and ``[[clang::noescape]]``) can be added to the function to improve the compiler's ability to optimize.

@ldionne ldionne force-pushed the review/document-abi-boundary-guidelines branch from 61a3604 to a5c3692 Compare December 10, 2024 15:12
@ldionne
Copy link
Member Author

ldionne commented Dec 10, 2024

Merging since documentation build is green.

@ldionne ldionne merged commit 01512d2 into llvm:main Dec 10, 2024
11 of 13 checks passed
@ldionne ldionne deleted the review/document-abi-boundary-guidelines branch December 10, 2024 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[libc++] Document guidelines for dylib boundary symbols

3 participants