Skip to content

[libcxx] adds opt out mechanism for using __wrap_iter for array and s… #84226

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

cjdb
Copy link
Contributor

@cjdb cjdb commented Mar 6, 2024

…tring_view

__config was unconditionally opting users into this change, and to opt out required either a manual edit of the header, or getting users to manually define each unstable ABI macro they want to support. This patch strikes a middle-ground by adding an opt-out mechanism.

…tring_view

`__config` was unconditionally opting users into this change, and to opt
out required either a manual edit of the header, or getting users to
manually define each unstable ABI macro they want to support. This patch
strikes a middle-ground by adding an opt-out mechanism.
@cjdb cjdb requested review from ldionne and philnik777 March 6, 2024 20:16
@cjdb cjdb requested a review from a team as a code owner March 6, 2024 20:16
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Mar 6, 2024
@llvmbot
Copy link
Member

llvmbot commented Mar 6, 2024

@llvm/pr-subscribers-libcxx

Author: Christopher Di Bella (cjdb)

Changes

…tring_view

__config was unconditionally opting users into this change, and to opt out required either a manual edit of the header, or getting users to manually define each unstable ABI macro they want to support. This patch strikes a middle-ground by adding an opt-out mechanism.


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

2 Files Affected:

  • (modified) libcxx/docs/ReleaseNotes/19.rst (+3)
  • (modified) libcxx/include/__config (+8-2)
diff --git a/libcxx/docs/ReleaseNotes/19.rst b/libcxx/docs/ReleaseNotes/19.rst
index 04f16610f8117e..955cadaa914439 100644
--- a/libcxx/docs/ReleaseNotes/19.rst
+++ b/libcxx/docs/ReleaseNotes/19.rst
@@ -49,6 +49,9 @@ Improvements and New Features
 -----------------------------
 
 - The performance of growing ``std::vector`` has been improved for trivially relocatable types.
+- ``std::array`` and ``std::string_view`` are no longer pointers in the unstable ABI by default, and
+  can be reverted to raw pointers by defining the macros ``_LIBCPP_ABI_NO_USE_WRAP_ITER_IN_STD_ARRAY``
+  and ``_LIBCPP_ABI_NO_USE_WRAP_ITER_IN_STD_STRING_VIEW``.
 
 Deprecations and Removals
 -------------------------
diff --git a/libcxx/include/__config b/libcxx/include/__config
index 3a438e85a7b819..70f15cce54a309 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -178,8 +178,14 @@
 // pointers, which prevents people from relying on a non-portable implementation
 // detail. This is especially useful because enabling bounded iterators hardening
 // requires code not to make these assumptions.
-#    define _LIBCPP_ABI_USE_WRAP_ITER_IN_STD_ARRAY
-#    define _LIBCPP_ABI_USE_WRAP_ITER_IN_STD_STRING_VIEW
+
+#    if !defined(_LIBCPP_ABI_NO_USE_WRAP_ITER_IN_STD_ARRAY)
+#        define _LIBCPP_ABI_USE_WRAP_ITER_IN_STD_ARRAY
+#    endif
+
+#    if !defined(_LIBCPP_ABI_NO_USE_WRAP_ITER_IN_STD_STRING_VIEW)
+#        define _LIBCPP_ABI_USE_WRAP_ITER_IN_STD_STRING_VIEW
+#    endif
 #  elif _LIBCPP_ABI_VERSION == 1
 #    if !(defined(_LIBCPP_OBJECT_FORMAT_COFF) || defined(_LIBCPP_OBJECT_FORMAT_XCOFF))
 // Enable compiling copies of now inline methods into the dylib to support

@ldionne
Copy link
Member

ldionne commented Mar 6, 2024

It wasn't my impression that anybody was requesting a different mechanism though, so I'd rather not introduce this additional complexity. After all, the requirement of being able to tweak this value without a "vendor" modifying the headers seems arbitrary to me, at that point it's just as good as setting something in the __config_site.

@cjdb
Copy link
Contributor Author

cjdb commented Mar 6, 2024

It wasn't my impression that anybody was requesting a different mechanism though, so I'd rather not introduce this additional complexity. After all, the requirement of being able to tweak this value without a "vendor" modifying the headers seems arbitrary to me, at that point it's just as good as setting something in the __config_site.

Some vendors have a "no custom patches" policy, meaning that they're unable to adjust this without opting into everything manually, which has problems of its own. It's a relatively small maintenance cost for us to make these opt-out, but a potentially large maintenance cost to ask vendors to constantly monitor what's added to the unstable ABI.

I can make it less arbitrary by adding opt-outs for everything, which was going to be my next patch. We could alternatively start it as a Discourse discussion and then move to GitHub if there's consensus.

A good analogy is Clang's warning policy: most are opt-in by default, and all are opt-out with -Wno-foo.

@ldionne
Copy link
Member

ldionne commented Mar 6, 2024

Some vendors have a "no custom patches" policy, meaning that they're unable to adjust this without opting into everything manually, which has problems of its own.

This is an arbitrary policy, though. I totally get the desire to minimize custom patches, but eradicating them entirely is not realistic unless that vendor pushes a lot of its complexities upstream. I'm saying this irrespective of the specific issue we have right here.

It's a relatively small maintenance cost for us to make these opt-out, but a potentially large maintenance cost to ask vendors to constantly monitor what's added to the unstable ABI.

If a vendor finds the need to constantly monitor what's added to the unstable ABI, it means they simply shouldn't be opting into the unstable ABI wholesale by setting _LIBCPP_ABI_VERSION = 2. They should instead be cherry-picking ABI macros via LIBCXX_ABI_DEFINES in the __config_site as they see fit. This is my main point -- it doesn't make sense to opt into "all of the breaks" but then require opt-outs for some breaks. Just don't opt into everything in the first place.

I can make it less arbitrary by adding opt-outs for everything, which was going to be my next patch. We could alternatively start it as a Discourse discussion and then move to GitHub if there's consensus.

For the reason stated above, I don't think it makes sense to do that.

@cjdb
Copy link
Contributor Author

cjdb commented Mar 6, 2024

at that point it's just as good as setting something in the __config_site.

It seems I misread this as __config, and thus unintentionally reframed the conversation. I'm not familiar with how to interact with __config_site: would it be possible to get some pointers on what one should do to customise this file please?

@ldionne
Copy link
Member

ldionne commented Mar 6, 2024

at that point it's just as good as setting something in the __config_site.

It seems I misread this as __config, and thus unintentionally reframed the conversation. I'm not familiar with how to interact with __config_site: would it be possible to get some pointers on what one should do to customise this file please?

It is possible to set arbitrary ABI defines via LIBCXX_ABI_DEFINES here: https://github.com/llvm/llvm-project/blob/main/libcxx/CMakeLists.txt#L225

Those end up in the __config_site generated via this mechanism: https://github.com/llvm/llvm-project/blob/main/libcxx/include/__config_site.in#L48

So the canonical way of cherry-picking ABI flags to enable via e.g. a CMake cache is to set LIBCXX_ABI_DEFINES as desired and let the __config_site pick them up, without setting LIBCXX_ABI_VERSION=2. Setting LIBCXX_ABI_VERSION=2 is basically a way to say "I want to get all the ABI flags whatever they are and I am ready to live on the edge", which is presumably not what most people want.

@cjdb
Copy link
Contributor Author

cjdb commented Mar 7, 2024

That's very clear, thank you for breaking it down!

@cjdb cjdb closed this Mar 7, 2024
@cjdb cjdb deleted the wrap-iter-abi-adjustment branch March 7, 2024 00:21
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.

3 participants