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 } };