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

third_party: Add libcxxabi #1063

Merged
merged 4 commits into from
Jan 8, 2024
Merged

Conversation

trungnt2910
Copy link
Collaborator

@trungnt2910 trungnt2910 commented Jan 6, 2024

Added libcxxabi from LLVM 17.0.6
The library implements the Itanium C++ exception handling ABI.

The upstream library comes with a comprehensive test set, which I did not add in this commit to prevent it from getting too large.

Part of #1065.

@trungnt2910 trungnt2910 requested a review from jart January 6, 2024 08:17
Copy link
Owner

@jart jart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's already bits and pieces of cxxabi in the codebase.

  • libc/cxxabi.h
  • libc/runtime/cxaguard.c
  • libc/thread/__cxa_thread_atexit.c

You need to figure out how to unify things so we don't have multiple implementations.

You also need to write a README.cosmo file for both libcxxabi and libunwind. If you make any changes to the source code, you need to document them in the README.cosmo file, under a section called LOCAL MODIFICATIONS.

@trungnt2910
Copy link
Collaborator Author

You also need to write a README.cosmo file for both libcxxabi and libunwind. If you make any changes to the source code, you need to document them in the README.cosmo file, under a section called LOCAL MODIFICATIONS.

I believe that has already been done for this PR (https://github.com/jart/cosmopolitan/pull/1063/files#diff-023909efd99352e621d59379b348b643ec9309ad023c4ee780b38568c874a77a) as well as libunwind (https://github.com/jart/cosmopolitan/blob/master/third_party/libunwind/README.cosmo)

There's already bits and pieces of cxxabi in the codebase.

This looks hard, unlike the unwind stubs, these implementations here look non-trivial and cannot be simply nuked away.

@trungnt2910 trungnt2910 force-pushed the dev/trungnt2910/libcxxabi branch 4 times, most recently from 73e0fc9 to 934fd65 Compare January 8, 2024 06:19
@trungnt2910
Copy link
Collaborator Author

There's already bits and pieces of cxxabi in the codebase.

Done. The parts with complex implementations in cosmo are for __cxa_thread_atexit_impl and __cxa_atexit. These are also not implemented by libcxxabi.

Other parts are either trivial functions or other third-party code (cxaguard).

Copy link
Owner

@jart jart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OUTSTANDING. I'm loving it!

Added libcxxabi from LLVM 17.0.6
The library implements the Itanium C++ exception handling ABI.
Enable `__cxa_thread_atexit` from libcxxabi.
`__cxa_thread_atexit_impl` is still implemented by the cosmo libc.
The original `__cxa_thread_atexit` has been removed.
Build libcxx with exceptions enabled.

- Removed `_LIBCPP_NO_EXCEPTIONS` from `__config`.
- Switched the exception implementation to `libcxxabi`. These two files
are taken from the same `libcxx` version as mentioned in `README.cosmo`.
- Removed `new_handler_fallback` in favor of `libcxxabi` implementation.
- Enable `-fexceptions` and `-frtti` for `libcxx`.
- Removed `THIRD_PARTY_LIBCXX` dependency from `libcxxabi` and
`libunwind`. These libraries do not use any runtime `libcxx` functions,
just headers.
- `__cxa_pure_virtual` in `libcxxabi` is also a stub similar to the
existing one.
- `__cxa_guard_*` from `libcxxabi` is used instead of the ones from
Android.

Now there should be no more duplicate implementations.
`__cxa_thread_atexit_impl`, `__cxa_atexit`, and related supporting
functions, are still left to other libraries as in `libcxxabi`.

`libcxxabi` is also now added to `cosmopolitan.a` to make up for the
removed functions.

Affected in-tree libraries (`third_party/double-conversion`) have been
updated.
@trungnt2910 trungnt2910 force-pushed the dev/trungnt2910/libcxxabi branch from bc268c6 to 37dfc42 Compare January 8, 2024 16:34
@jart jart merged commit 8b33204 into jart:master Jan 8, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants