When exceptions are disabled, avoid their processing altogether.
This avoids pulling in the depenency on demangler significantly
reducing binary size when statically linking against libc++abi
built without exception support.
Details
- Reviewers
ldionne EricWF Bigcheese - Commits
- rCXXA365944: [libcxxabi] Don't process exceptions in cxa_handlers when they're disabled
rG2e398f1895b9: [libcxxabi] Don't process exceptions in cxa_handlers when they're disabled
rL365944: [libcxxabi] Don't process exceptions in cxa_handlers when they're disabled
Diff Detail
- Repository
- rL LLVM
Event Timeline
The only thing iffy about this is that it's not 100% clear to me what _LIBCXXABI_NO_EXCEPTIONS mean. It could either mean (a) that libc++abi itself doesn't use exceptions in its implementation, or (b) that it doesn't provide support for exceptions in the runtime, or both (a) and (b).
It clearly means at least (a) from a quick grep, however it's not clear to me that it also means (b).
We assumed both (a) and (b). This is really valuable for us since we use libc++abi built with _LIBCXXABI_NO_EXCEPTIONS when -fno-exceptions is specified which can save a lot of space in embedded use cases because we can avoid pulling in all the demangling code.
If _LIBCXXABI_NO_EXCEPTIONS is meant to imply just (a), could we introduce a second definition/option for (b), e.g. _LIBCXXABI_NO_EXCEPTIONS and _LIBCXXABI_HAS_NO_EXCEPTIONS?
FYIe, you can also prevent this symbol to be linked in by putting a cxa_demangle function in an obj file that gets linked first, like so: https://cs.chromium.org/chromium/src/third_party/android_crazy_linker/src/src/crazy_linker_wrappers.cpp?type=cs&q=cxa_demangle+file:android&sq=package:chromium&g=0&l=54 – but I agree that since cxa_demangle is so large, it'd be nice if the upstream version was behind some kind of define. Then we could set that and remove that hack in chromium too. I don't have an opinion on if that should be a new define or if _LIBCXXABI_NO_EXCEPTIONS should be reused. Actually, I think we build libcxxabi with exceptions enabled because some of our test code can in theory throw exceptions, but we have an external dumper so we don't need the stack from terminate() – so it'd be somewhat more convenient for us if we could turn off the stack from terminate() (and the pulling in of __cxa_demangle) while still being able to build without setting _LIBCXXABI_NO_EXCEPTIONS.
We have a local libc++abi patch to just disable the demangler altogether under certain configurations because of similar size concerns. I never got around to upstreaming that, but it seems like something that's wanted by multiple people, at least.
_LIBCXXABI_NO_EXCEPTIONS removes the exceptions abi from libc++abi, so I think this change as fine as __cxa_throw isn't even defined if _LIBCXXABI_NO_EXCEPTIONS is defined.
I also think adding a way to just disable demangling is fine, but it should be a separate patch.
Fine with this if @Bigcheese is, however I'd like this patch to include a change to the LIBCXXABI_ENABLE_EXCEPTIONS CMake option, which controls whether _LIBCXXABI_NO_EXCEPTIONS is defined. The option currently says "Use exceptions.", however it should say something along the lines of: "Provide support for exceptions in the runtime. When this is disabled, libc++abi does not support stack unwinding and other exceptions-related features".