This is an archive of the discontinued LLVM Phabricator instance.

[libcxx][libcxxabi] Decouple no-exceptions libcpp variant from cxa_exception.cpp and cxa_personality.cpp of libcxxabi
AbandonedPublic

Authored by rmaprath on May 29 2016, 5:39 PM.

Details

Summary

This is a pre-requisite to address a review comment on D20677; The no-exceptions variant of libcxxabi should not be allowed to be linked against code that requires exceptions.

In order to do this, we need to rip off some exceptions-related symbols from the no-exceptions libcxxabi build. We can get rid of both cxa_exception.cpp and cxa_personality.cpp to meet the said requirement, but this needs a small surgery to the no-exception libcpp variant; we must #ifdef out the dependency on these two libcxxabi sources from the exception.cpp of libcxx.

Diff Detail

Event Timeline

rmaprath updated this revision to Diff 58925.May 29 2016, 5:39 PM
rmaprath retitled this revision from to [libcxx][libcxxabi] Decouple no-exceptions libcpp variant from cxa_exception.cpp and cxa_personality.cpp of libcxxabi.
rmaprath updated this object.
rmaprath added reviewers: EricWF, mclow.lists.
rmaprath added a subscriber: cfe-commits.
EricWF edited edge metadata.May 30 2016, 10:24 AM

I don't like the direction of this patch, and it seems like the wrong direction for what your trying to achieve as well.
If your trying to support a system with two variants of libc++abi, one that throws and the other that does not, then you'll want libc++ to remain unmodified so it can depend on the selected libc++abi to provide the correct exception handling behavior.

I think these particular symbols should always be defined within libc++abi (sorry if I said otherwise earlier, I didn't understand the implementation). The -fno-exceptions build of libc++abi can build these symbols with very simple definitions that is detached from the rest of the exception handling machinery.

My preference would be to create a new file cxa_no_exception_definitions.cpp (bike shedding welcome) which builds inplace of cxa_exception.cpp and contains definitions for these symbols. For example.

  • __cxa_uncaugh_exception()/__cxa_uncaught_exceptions() always returns zero.
  • __cxa_decrement_exception_refcount(ptr)/__cxa_increment_refcount(ptr) terminate if ptr != nullptr.
  • __cxa_primary_exception() returns nullptr.
  • __cxa_rethrow_primary_exception(ptr) returns as to hit the terminate call in libc++.

This way we are not conflating building libc++ without exceptions with building libc++ against an ABI library which doesn't provide the exception handling API.

I don't like the direction of this patch, and it seems like the wrong direction for what your trying to achieve as well.
If your trying to support a system with two variants of libc++abi, one that throws and the other that does not, then you'll want libc++ to remain unmodified so it can depend on the selected libc++abi to provide the correct exception handling behavior.

We do not allow linking a with-exceptions libc++ library with a no-exceptions libc++abi library, that is not a use-case for us. We have either with-exceptions libraries or no-exceptions libraries, there is no overlap. This is why I went with the current approach (modify the no-exceptions libc++ variant to match the no-exceptions libc++abi variant).

Note that our use-case is about code-size, we do not want exception handling routines (as well as exception tables) in our final image. We are not after a system where you can swap out the exceptions behaviour. Sorry if I wasn't clear about this.

I think these particular symbols should always be defined within libc++abi (sorry if I said otherwise earlier, I didn't understand the implementation). The -fno-exceptions build of libc++abi can build these symbols with very simple definitions that is detached from the rest of the exception handling machinery.

My preference would be to create a new file cxa_no_exception_definitions.cpp (bike shedding welcome) which builds inplace of cxa_exception.cpp and contains definitions for these symbols. For example.

  • __cxa_uncaugh_exception()/__cxa_uncaught_exceptions() always returns zero.
  • __cxa_decrement_exception_refcount(ptr)/__cxa_increment_refcount(ptr) terminate if ptr != nullptr.
  • __cxa_primary_exception() returns nullptr.
  • __cxa_rethrow_primary_exception(ptr) returns as to hit the terminate call in libc++.

This way we are not conflating building libc++ without exceptions with building libc++ against an ABI library which doesn't provide the exception handling API.

That too would work for us. I agree this is a bit more cleaner since it does not involve changes to libc++, so I will spin a patch for it on top of D20677.

/ Asiri

rmaprath abandoned this revision.May 30 2016, 2:13 PM

Updated D20677 with the necessary changes. This patch is no longer required.