This is a (IMO superior) alternative to https://reviews.llvm.org/D119969.
This patch is more involved than D119969, but it has the benefit of being
cleaner in the long run, especially since we know our current Debug mode
doesn't work -- so perhaps we shouldn't try to reuse too many of its
mechanisms.
In particular, this is better than reusing the existing debug mode because
we now have the ability to set the assertion handler at compile-time,
which means that assertions can be enabled even in code that targets
platforms on which the debug mode support had not been shipped yet.
As-is, this patch provides backwards compatibility with any user that
might have been setting _LIBCPP_DEBUG=0 in order to get basic assertions
in their code. Hence, this patch should be entirely backwards compatible.
However, given that our debug mode has been broken since day 1, I think
we'll need a discussion around either fixing it or removing it, since the
status quo is good for nobody. In particular, an immediate next step to
simplify the library would be to remove __libcpp_debug_info and friends.
We can keep the symbols in the dylib to avoid linker errors, but we should
not support two distinct ways of setting an assertion handler.
A point of discussion I expect is whether LIBCXX_ENABLE_ASSERTIONS at CMake configure-time should control *both* whether the dylib contains assertions and what the default is for user code. I've done it that way for now because I didn't really expect the need for additional customizeability, but I could be convinced otherwise.
TLDR, the one thing you can't do with the current design is build libc++.dylib with assertions enabled, but have assertions disabled inside user code by default (or the other way around, i.e. no assertions in the dylib, but user code builds with assertions by default).