[libcxx-commits] [libcxx] [libc++] Don't add reference to system_category when exceptions disabled (PR #67504)

Daniel Thornburgh via libcxx-commits libcxx-commits at lists.llvm.org
Tue Sep 26 16:59:39 PDT 2023


https://github.com/mysterymath created https://github.com/llvm/llvm-project/pull/67504

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.

>From 567313825dbbbe8da7bfc0de802899717f18d12b Mon Sep 17 00:00:00 2001
From: Daniel Thornburgh <dthorn at google.com>
Date: Mon, 25 Sep 2023 14:51:55 -0700
Subject: [PATCH] [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 f187090f75b6ce9..5b6601bad78531d 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



More information about the libcxx-commits mailing list