trace_processor: use llvm frame demangling in standalone builds

This changes the Demangle() SQL function offered by trace processor to,
depending on build config, demangle function names using a small subset
of sources pulled from llvm-project (as a buildtools dependency). The
benefits are: demangling is no longer dependent on the platform that
trace processor runs on, and support for non-Itanium mangling schemes
(notably, Rust's _R v0 mangling). By default, this is enabled in
standalone GN builds, and can be turned off using
gn/perfetto.gni. The fallback implementation is the
current cpp runtime function (abi::__cxa_demangle).

One odd thing that this changes for standalone builds: in debug builds,
the llvm sources require c++14 (which is the project's natural standard
level, so the release logic might require it as well in the future). So
we build them using -std=c++14, and link the results into the rest of
the build that is using -std=c++11. This relies on the compiler being
ABI compatible across the two standards, and we assume that's the case
for the compilers we target in standalone builds. For example, I've read
that for GCC keeping such configurations sane is an explicit goal.

All wiring for standalone Bazel build is done and works if you make
tools/gen_bazel set enable_perfetto_llvm_demangle=true. Planning to make
that the default soon, but it's simpler for the google-internal
embedding if we do that separately.

The Bazel wiring introduces two indirections in PERFETTO_CONFIG, to
allow for the entire demangling target to be swapped out if necessary.
This will be used in google-internal builds, but all other embedders are
expected to stick to the default implementation.

Side-change: the nop fallback implementation (if on Windows and not
using llvm demangling) now returns nullptr to indicate that demangling
always fails, which is more consistent with the codepaths that attempt
demangling. Previously it returned the input string.

Bug: 204297290
Change-Id: Ic7844d02cce1418f11869a4ed32a4c59f866a766
diff --git a/Android.bp b/Android.bp
index 6a66249..0db1aae 100644
--- a/Android.bp
+++ b/Android.bp
@@ -1586,6 +1586,11 @@
     name: "perfetto_include_perfetto_ext_ipc_ipc",
 }
 
+// GN: //include/perfetto/ext/trace_processor:demangle
+filegroup {
+    name: "perfetto_include_perfetto_ext_trace_processor_demangle",
+}
+
 // GN: //include/perfetto/ext/trace_processor:export_json
 filegroup {
     name: "perfetto_include_perfetto_ext_trace_processor_export_json",
@@ -1855,6 +1860,7 @@
         "libgmock",
         "libgtest",
         "libperfetto_client_experimental",
+        "perfetto_src_trace_processor_demangle",
     ],
     whole_static_libs: [
         "perfetto_gtest_logcat_printer",
@@ -8110,6 +8116,21 @@
     ],
 }
 
+// GN: //src/trace_processor:demangle
+cc_library_static {
+    name: "perfetto_src_trace_processor_demangle",
+    srcs: [
+        ":perfetto_include_perfetto_base_base",
+        ":perfetto_include_perfetto_ext_base_base",
+        ":perfetto_include_perfetto_ext_trace_processor_demangle",
+        "src/trace_processor/demangle.cc",
+    ],
+    host_supported: true,
+    defaults: [
+        "perfetto_defaults",
+    ],
+}
+
 // GN: //src/trace_processor:export_json
 filegroup {
     name: "perfetto_src_trace_processor_export_json",
@@ -9776,6 +9797,7 @@
     static_libs: [
         "libgmock",
         "libgtest",
+        "perfetto_src_trace_processor_demangle",
     ],
     whole_static_libs: [
         "perfetto_gtest_logcat_printer",
@@ -10013,6 +10035,9 @@
         "src/trace_processor/trace_processor_shell.cc",
         "src/trace_processor/util/proto_to_json.cc",
     ],
+    static_libs: [
+        "perfetto_src_trace_processor_demangle",
+    ],
     host_supported: true,
     generated_headers: [
         "perfetto_protos_perfetto_common_zero_gen_headers",
@@ -10172,6 +10197,7 @@
     static_libs: [
         "libsqlite",
         "libz",
+        "perfetto_src_trace_processor_demangle",
     ],
     generated_headers: [
         "perfetto_protos_perfetto_common_zero_gen_headers",