Sanitizers, e.g. ubsan can uninline this call.
https://godbolt.org/z/s51sfezb5
This holds unused printf parameters and bloats binaries.
Differential D140944
[libc++] Optimize _LIBCPP_HAS_NO_VERBOSE_ABORT_IN_LIBRARY vitalybuka on Jan 3 2023, 7:22 PM. Authored by
Details Sanitizers, e.g. ubsan can uninline this call. This holds unused printf parameters and bloats binaries.
Diff Detail
Event TimelineComment Actions Could you provide some numbers? This doesn't look great, but I don't think we care that much about binary size with sanitizers. It's not great anyways, so it would have to be quite a big difference to make it worth adding _LIBCPP_ALWAYS_INLINE. Also, please add a comment why it is added. We don't do that everywhere we use the attribute currently, but we should. So let's not make it worse. Comment Actions Actually at google we care about size with sanitizers. With asan+ubsan combo _LIBCPP_ENABLE_ASSERTIONS=1 costs us 1.6% Comment Actions actually it's Comment Actions _LIBCPP_HAS_NO_VERBOSE_ABORTIN_LIBRARY exists to make deploying to a target that doesn't have __libcpp_verbose_abort in the dylib possible, not to save size. You can use a custom verbose abort handler for that. I expect that we'll remove the inline version at some point (Not that this will happen soon). Comment Actions Yes, impact of sanitizers is larger, but I don't know anything that can save 1% with as simple as _LIBCPP_ALWAYS_INLINE. Regardless of sanitizers, inlined callback is very desirable. There is ugly workaround with _LIBCPP_AVAILABILITY_CUSTOM_VERBOSE_ABORT_PROVIDED and defining inline libcpp_verbose_abort in config_site. What is your concerns regarding _LIBCPP_ALWAYS_INLINE here, seems like it's going to be inlined in any other possible config anyway?
Probably there is no easy fix in compiler itself. I see two issues with the current __libcpp_verbose_abort:
Comment Actions I'm not a fan of adding macros like _LIBCPP_ALWAYS_INLINE because it easily bit-rots and indicates a problem with the compiler optimizations. Fixing that is generally the better way to achieve these kinds of things.
I think I'd like to have @ldionne's opinion here before approving, but I guess it's indeed simple enough for such a large impact. Comment Actions Thanks for pinging me here, I was OOO when the discussion happened. First, it is true that _LIBCPP_HAS_NO_VERBOSE_ABORT_IN_LIBRARY was meant to allow back-deployment only, and I don't think we should abuse it for other purposes. If you want to have an abort handler that is guaranteed to be inlined, the path forward would be to provide a way that users can define their abort handler with whatever attributes (and signature while we're at it) they want, and allow them to override the default one at compile-time. That approach would be in-line with how this was meant to be used. I fully agree that the current mechanism is lacking in that respect. In fact, it's an open issue I was already aware of and planning to fix before I saw this patch, since we do have codesize-sensitive users that want __libcpp_verbose_abort to boil down to essentially a single instruction. This patch just made me re-bump the priority of fixing this issue, so I just opened D141326 to propose a way to solve this problem. Please let me know what you think. |