[libcxx-commits] [PATCH] D78330: [libc++abi] Add a rate limiter when logging dynamic_cast errors

Louis Dionne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Thu Apr 16 14:31:36 PDT 2020


ldionne created this revision.
Herald added subscribers: libcxx-commits, dexonsmith, jkorous.
Herald added a project: libc++abi.
Herald added a reviewer: libc++abi.
ldionne added a reviewer: Bigcheese.

This upstreams a fix that Howard made a long time ago, where so many
errors would be logged that applications were becoming sluggish. With
this patch, the first three errors will be printed, and after that the
printing frequency decreases exponentially.

_LIBCXX_DYNAMIC_FALLBACK is only enabled on Apple platforms, so this
should be NFC for other platforms.

rdar://14996273


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D78330

Files:
  libcxxabi/src/private_typeinfo.cpp


Index: libcxxabi/src/private_typeinfo.cpp
===================================================================
--- libcxxabi/src/private_typeinfo.cpp
+++ libcxxabi/src/private_typeinfo.cpp
@@ -640,9 +640,12 @@
         {
             // We get here only if there is some kind of visibility problem
             //   in client code.
-            syslog(LOG_ERR, "dynamic_cast error 1: Both of the following type_info's "
-                    "should have public visibility. At least one of them is hidden. %s"
-                    ", %s.\n", static_type->name(), dynamic_type->name());
+            static size_t error_count = 0;
+            if ((error_count & (error_count-1)) == 0)
+                syslog(LOG_ERR, "dynamic_cast error 1: Both of the following type_info's "
+                        "should have public visibility. At least one of them is hidden. %s"
+                        ", %s.\n", static_type->name(), dynamic_type->name());
+            ++error_count;
             // Redo the search comparing type_info's using strcmp
             info = {dst_type, static_ptr, static_type, src2dst_offset, 0};
             info.number_of_dst_type = 1;
@@ -663,11 +666,14 @@
         if (info.path_dst_ptr_to_static_ptr == unknown &&
             info.path_dynamic_ptr_to_static_ptr == unknown)
         {
-            syslog(LOG_ERR, "dynamic_cast error 2: One or more of the following type_info's "
-                            "has hidden visibility or is defined in more than one translation "
-                            "unit. They should all have public visibility. "
-                            "%s, %s, %s.\n", static_type->name(), dynamic_type->name(),
-                    dst_type->name());
+            static size_t error_count = 0;
+            if ((error_count & (error_count-1)) == 0)
+                syslog(LOG_ERR, "dynamic_cast error 2: One or more of the following type_info's "
+                                "has hidden visibility or is defined in more than one translation "
+                                "unit. They should all have public visibility. "
+                                "%s, %s, %s.\n", static_type->name(), dynamic_type->name(),
+                        dst_type->name());
+            ++error_count;
             // Redo the search comparing type_info's using strcmp
             info = {dst_type, static_ptr, static_type, src2dst_offset, 0};
             dynamic_type->search_below_dst(&info, dynamic_ptr, public_path, true);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78330.258168.patch
Type: text/x-patch
Size: 2486 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20200416/1df9ff32/attachment-0001.bin>


More information about the libcxx-commits mailing list