Skip to content
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

Opt into unstable libcxx ABI and add a custom namespace. #49002

Merged
merged 2 commits into from
Dec 18, 2023

Conversation

chinmaygarde
Copy link
Member

We use a statically linked libcxx and don't expose any of the internal symbols. This theoretically allows us to namespace everything to avoid accidentally using the wrong version libcxx. Also, not having to worry about ABI stability allows libcxx to opt into optimized routines.

But, since libcxx uses CMake and we don't, the mechanism to generate the __config_site file doesn't exist in GN. Instead, we check in a file that would have been generated for us by CMake. The file we check in though is a default with additional configuration. This version of the file makes it so that we opt into the unstable ABI (and get optimizations) and also namespace everything for Flutter so collisions are immediately flagged.

@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact "@text-exemption-reviewers" in the #hackers channel in Chat (don't just cc them here, they won't see it! Use Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@chinmaygarde
Copy link
Member Author

Noticed this while answering this thread and seeing _LIBCPP_ABI_NAMESPACE unexpanded in the symbol name. The configuration options change all the time. These options were created from the version of libcxx in our DEPS using guidance mentioned in the README.

@chinmaygarde
Copy link
Member Author

This should also make the output of llvm-cxxfilt less verbose because the macro _LIBCPP_ABI_NAMESPACE will not be expanded.

I don't know how we decided the default __config_site was fine but git blame says I checked it in. So 🤷🏽

@chinmaygarde
Copy link
Member Author

FWIW, the optimizations this opts into are here. Though, the primary reason for the change is the namespacing and avoiding collisions. I don't expect this to move the needle on benchmarks.

@zanderso
Copy link
Member

Are the ASAN and test failures related, or does this need a rebase past a bad commit?

Is there any way to test this? Is there some way to make the build fail if these changes are accidentally backed out?

We use a statically linked libcxx and don't expose any of the internal symbols.
This theoretically allows us to namespace everything to avoid accidentally using
the wrong version libcxx. Also, not having to worry about ABI stability allows
libcxx to opt into optimized routines.

But, since libcxx uses CMake and we don't, the mechanism to generate the
__config_site file doesn't exist in GN. Instead, we check in a file that would
have been generated for us by CMake. The file we check in though is a default
with additional configuration. This version of the file makes it so that we opt
into the unstable ABI (and get optimizations) and also namespace everything for
Flutter so collisions are immediately flagged.
@jason-simmons
Copy link
Member

The flutter_linux_unittests tests are failing because the Linux embedder is placing std::function instances inside GTK GObjects.

Creating a GObject apparently initializes the object with zeros and does not run the C++ constructors for the class members. It looks like the old implementation of libcxx std::function could work with this, but the new one does not.

As a hack workaround I was able to get these tests to run by using placement new to force construction of the std::function instances in the GObject initializers. I'm not familiar with GTK and do not know what the preferred solution is for this issue.

@cbracken
Copy link
Member

/cc @robert-ancell for GTK-side expertise. Any advice on recommended approaches here? Does what @jason-simmons is proposing sound reasonable?

@chinmaygarde
Copy link
Member Author

From what @jason-simmons said, it seems like we were depending undefined behavior in the ABI instead mixing libcxxs (which is what I was primarily concerned about). There are number optimizations that are enabled by when the ABI can be unstable. But we can check this by setting _LIBCPP_ABI_VERSION to 1 and seeing if the tests pass. But we should fix the undefined behavior still though.

@chinmaygarde
Copy link
Member Author

Trying a canary run with version set to 1.

@chinmaygarde
Copy link
Member Author

That did it. @jason-simmons If you had to manually perform a placement new, that also means that the delete was not happening right? So we are leaking std::function guts because the destructors are not being called? We got away with the ctors not being called earlier because presumably the zero initialization was a find ctor.

@chinmaygarde
Copy link
Member Author

FWIW, this version of the patch fixes the namespacing without changing the ABI. Should I land just this with a followup?
Screenshot 2023-12-14 at 1 43 36 PM

@jason-simmons
Copy link
Member

The change to ABI version 1 LGTM

Filed flutter/flutter#140183

@robert-ancell
Copy link
Contributor

If the Linux tests still have issues I think we should just change the use of std::function to function pointers. GTK is a C library so the mixing of C++ code can be somewhat problematic I expect. My C++ knowledge is not extensive but forcing the construction as proposed by @jason-simmons seems like it would be necessary if we want to continue to use C++ objects inside GObject.

@chinmaygarde chinmaygarde added the autosubmit Merge PR when tree becomes green via auto submit App label Dec 18, 2023
@auto-submit auto-submit bot merged commit 45624a7 into flutter:main Dec 18, 2023
25 checks passed
@chinmaygarde chinmaygarde deleted the unstablelibcxx branch December 18, 2023 19:36
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Dec 18, 2023
…140350)

flutter/engine@92d88c7...632103f

2023-12-18 matej.knopp@gmail.com Convert chromium wheel delta to physical pixels on macOS (flutter/engine#49028)
2023-12-18 skia-flutter-autoroll@skia.org Roll Skia from 3de801338767 to 63bed826008e (1 revision) (flutter/engine#49200)
2023-12-18 skia-flutter-autoroll@skia.org Roll Dart SDK from ff7e92c7886d to b21443096387 (1 revision) (flutter/engine#49199)
2023-12-18 skia-flutter-autoroll@skia.org Roll Skia from 83f8fe8bbcee to 3de801338767 (2 revisions) (flutter/engine#49195)
2023-12-18 skia-flutter-autoroll@skia.org Roll Skia from 10e7ee119ea9 to 83f8fe8bbcee (1 revision) (flutter/engine#49193)
2023-12-18 barpac02@gmail.com Delete `SemanticsUpdateBuilderNew` and all references and usages (flutter/engine#49139)
2023-12-18 chinmaygarde@google.com Opt into unstable libcxx ABI and add a custom namespace. (flutter/engine#49002)
2023-12-18 skia-flutter-autoroll@skia.org Roll Skia from 4b2639427e7e to 10e7ee119ea9 (10 revisions) (flutter/engine#49191)
2023-12-18 skia-flutter-autoroll@skia.org Roll Dart SDK from e1a26302800d to ff7e92c7886d (1 revision) (flutter/engine#49185)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC jsimmons@google.com,rmistry@google.com,zra@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
CoderDake pushed a commit to CoderDake/flutter that referenced this pull request Dec 28, 2023
…lutter#140350)

flutter/engine@92d88c7...632103f

2023-12-18 matej.knopp@gmail.com Convert chromium wheel delta to physical pixels on macOS (flutter/engine#49028)
2023-12-18 skia-flutter-autoroll@skia.org Roll Skia from 3de801338767 to 63bed826008e (1 revision) (flutter/engine#49200)
2023-12-18 skia-flutter-autoroll@skia.org Roll Dart SDK from ff7e92c7886d to b21443096387 (1 revision) (flutter/engine#49199)
2023-12-18 skia-flutter-autoroll@skia.org Roll Skia from 83f8fe8bbcee to 3de801338767 (2 revisions) (flutter/engine#49195)
2023-12-18 skia-flutter-autoroll@skia.org Roll Skia from 10e7ee119ea9 to 83f8fe8bbcee (1 revision) (flutter/engine#49193)
2023-12-18 barpac02@gmail.com Delete `SemanticsUpdateBuilderNew` and all references and usages (flutter/engine#49139)
2023-12-18 chinmaygarde@google.com Opt into unstable libcxx ABI and add a custom namespace. (flutter/engine#49002)
2023-12-18 skia-flutter-autoroll@skia.org Roll Skia from 4b2639427e7e to 10e7ee119ea9 (10 revisions) (flutter/engine#49191)
2023-12-18 skia-flutter-autoroll@skia.org Roll Dart SDK from e1a26302800d to ff7e92c7886d (1 revision) (flutter/engine#49185)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC jsimmons@google.com,rmistry@google.com,zra@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants