From 567313825dbbbe8da7bfc0de802899717f18d12b Mon Sep 17 00:00:00 2001 From: Daniel Thornburgh Date: Mon, 25 Sep 2023 14:51:55 -0700 Subject: [PATCH 1/2] [libc++] Don't add reference to system_category when exceptions disabled This fixes a size regression in Fuchsia when building a static libc++ multilib with exceptions disabled. Referring to system_category in __throw_system_error brings in a relatively large amount of additional exception classes into the link without substantially improving the error message. --- libcxx/src/system_error.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/libcxx/src/system_error.cpp b/libcxx/src/system_error.cpp index f187090f75b6c..5b6601bad7853 100644 --- a/libcxx/src/system_error.cpp +++ b/libcxx/src/system_error.cpp @@ -266,8 +266,16 @@ system_error::~system_error() noexcept { } -void __throw_system_error(int ev, const char* what_arg) { - std::__throw_system_error(error_code(ev, system_category()), what_arg); +void +__throw_system_error(int ev, const char* what_arg) +{ +#ifndef _LIBCPP_HAS_NO_EXCEPTIONS + std::__throw_system_error(error_code(ev, system_category()), what_arg); +#else + // The above could also handle the no-exception case, but for size, avoid referencing system_category() unnecessarily. + _LIBCPP_VERBOSE_ABORT( + "system_error was thrown in -fno-exceptions mode with error %i and message \"%s\"", ev, what_arg); +#endif } _LIBCPP_END_NAMESPACE_STD From f93246ad8a45721b14f4921c232c6817d321cb80 Mon Sep 17 00:00:00 2001 From: Daniel Thornburgh Date: Tue, 26 Sep 2023 17:03:18 -0700 Subject: [PATCH 2/2] Formatting --- libcxx/src/system_error.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libcxx/src/system_error.cpp b/libcxx/src/system_error.cpp index 5b6601bad7853..1cc6b7d7e1e63 100644 --- a/libcxx/src/system_error.cpp +++ b/libcxx/src/system_error.cpp @@ -272,9 +272,8 @@ __throw_system_error(int ev, const char* what_arg) #ifndef _LIBCPP_HAS_NO_EXCEPTIONS std::__throw_system_error(error_code(ev, system_category()), what_arg); #else - // The above could also handle the no-exception case, but for size, avoid referencing system_category() unnecessarily. - _LIBCPP_VERBOSE_ABORT( - "system_error was thrown in -fno-exceptions mode with error %i and message \"%s\"", ev, what_arg); + // The above could also handle the no-exception case, but for size, avoid referencing system_category() unnecessarily. + _LIBCPP_VERBOSE_ABORT("system_error was thrown in -fno-exceptions mode with error %i and message \"%s\"", ev, what_arg); #endif }