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/BUILD b/BUILD
index 3260a6e..a285be5 100644
--- a/BUILD
+++ b/BUILD
@@ -423,6 +423,14 @@
],
)
+# GN target: //include/perfetto/ext/trace_processor:demangle
+perfetto_filegroup(
+ name = "include_perfetto_ext_trace_processor_demangle",
+ srcs = [
+ "include/perfetto/ext/trace_processor/demangle.h",
+ ],
+)
+
# GN target: //include/perfetto/ext/trace_processor:export_json
perfetto_filegroup(
name = "include_perfetto_ext_trace_processor_export_json",
@@ -1332,6 +1340,20 @@
],
)
+# GN target: //src/trace_processor:demangle
+perfetto_cc_library(
+ name = "src_trace_processor_demangle",
+ srcs = [
+ "src/trace_processor/demangle.cc",
+ ],
+ hdrs = [
+ ":include_perfetto_base_base",
+ ":include_perfetto_ext_base_base",
+ ":include_perfetto_ext_trace_processor_demangle",
+ ],
+ linkstatic = True,
+)
+
# GN target: //src/trace_processor:export_json
perfetto_filegroup(
name = "src_trace_processor_export_json",
@@ -3692,7 +3714,8 @@
PERFETTO_CONFIG.deps.sqlite_ext_percentile +
PERFETTO_CONFIG.deps.zlib + [
":cc_amalgamated_sql_metrics",
- ],
+ ] +
+ PERFETTO_CONFIG.deps.demangle_wrapper,
linkstatic = True,
)
@@ -3790,7 +3813,8 @@
PERFETTO_CONFIG.deps.sqlite_ext_percentile +
PERFETTO_CONFIG.deps.zlib + [
":cc_amalgamated_sql_metrics",
- ],
+ ] +
+ PERFETTO_CONFIG.deps.demangle_wrapper,
)
# GN target: //src/traced/probes:traced_probes
@@ -3974,7 +3998,8 @@
PERFETTO_CONFIG.deps.sqlite_ext_percentile +
PERFETTO_CONFIG.deps.zlib + [
":cc_amalgamated_sql_metrics",
- ],
+ ] +
+ PERFETTO_CONFIG.deps.demangle_wrapper,
)
# Content from BUILD.extras