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 <mark@chromium.org>
diff --git a/src/common/language.cc b/src/common/language.cc
index d26e563..440d4de 100644
--- a/src/common/language.cc
+++ b/src/common/language.cc
@@ -79,17 +79,12 @@
     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 =
@@ -111,6 +106,21 @@
     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
+  }
 };
 
 CPPLanguage CPPLanguageSingleton;