From f2679262acfb576f72d464e999cdac0950f92afc Mon Sep 17 00:00:00 2001 From: Mikhail Borisov Date: Tue, 26 May 2020 21:44:01 +0300 Subject: [PATCH] Avoid calling demangler for non-C++ symbols on Linux Bogus demangler warnings should be suppressed on both Mac and Linux platforms, so there is no reason to keep this filter behind __APPLE__ gate. Bug: chromium:1062556 Change-Id: Idf28db0b527c3cd6dd91510fcf7d9040aaa64694 Reviewed-on: https://chromium-review.googlesource.com/c/breakpad/breakpad/+/2210684 Reviewed-by: Mark Mentovai --- src/common/language.cc | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/common/language.cc b/src/common/language.cc index d26e5638..440d4de1 100644 --- a/src/common/language.cc +++ b/src/common/language.cc @@ -79,17 +79,12 @@ class CPPLanguage: public Language { demangled->clear(); return kDontDemangle; #else -#if defined(__APPLE__) - // Mac C++ symbols can have up to 4 underscores, followed by a "Z". - // Non-C++ symbols are not coded that way, but may have leading underscores. // Attempting to demangle non-C++ symbols with the C++ demangler would print // warnings and fail, so return kDontDemangle for these. - size_t i = mangled.find_first_not_of('_'); - if (i == 0 || i == string::npos || i > 4 || mangled[i] != 'Z') { + if (!IsMangledName(mangled)) { demangled->clear(); return kDontDemangle; } -#endif int status; char* demangled_c = @@ -109,6 +104,21 @@ class CPPLanguage: public Language { } return result; +#endif + } + + private: + static bool IsMangledName(const string &name) { + // NOTE: For proper cross-compilation support, this should depend on target + // binary's platform, not current build platform. +#if defined(__APPLE__) + // Mac C++ symbols can have up to 4 underscores, followed by a "Z". + // Non-C++ symbols are not coded that way, but may have leading underscores. + size_t i = name.find_first_not_of('_'); + return i > 0 && i != string::npos && i <= 4 && name[i] == 'Z'; +#else + // Linux C++ symbols always start with "_Z". + return name.size() > 2 && name[0] == '_' && name[1] == 'Z'; #endif } };