Update Rust demangling to use rustc-demangle

The rust-demangle-capi crate hasn't been updated since 2016 and
out-of-date. Instead, Breakpad needs to use C API offered by the
rustc-demangle to demangle Rust symbols.

*** TESTING ***

1) Set up rustc-demangle

> git clone https://github.com/rust-lang/rustc-demangle.git
> cd rustc-demangle
> cargo build -p rustc-demangle-capi --release

2) Breakpad

> ./configure --with-rustc-demangle=<path to rustc-demangle>
> make check src/common/dward_cu_to_module

Change-Id: Ib68b62ef329f1397bc379a1d04c632781e4b2069
Reviewed-on: https://chromium-review.googlesource.com/c/breakpad/breakpad/+/3273324
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
This commit is contained in:
Alex Pankhurst 2021-11-10 13:25:30 -08:00 committed by Joshua Peraza
parent fe35cd43f2
commit 38ee0be4d1
6 changed files with 56 additions and 55 deletions

View file

@ -623,9 +623,9 @@ src_tools_linux_dump_syms_dump_syms_SOURCES = \
src/common/linux/safe_readlink.cc \ src/common/linux/safe_readlink.cc \
src/tools/linux/dump_syms/dump_syms.cc src/tools/linux/dump_syms/dump_syms.cc
src_tools_linux_dump_syms_dump_syms_CXXFLAGS = \ src_tools_linux_dump_syms_dump_syms_CXXFLAGS = \
$(RUST_DEMANGLE_CFLAGS) $(RUSTC_DEMANGLE_CFLAGS)
src_tools_linux_dump_syms_dump_syms_LDADD = \ src_tools_linux_dump_syms_dump_syms_LDADD = \
$(RUST_DEMANGLE_LIBS) $(RUSTC_DEMANGLE_LIBS)
src_tools_linux_md2core_minidump_2_core_SOURCES = \ src_tools_linux_md2core_minidump_2_core_SOURCES = \
src/common/linux/memory_mapped_file.cc \ src/common/linux/memory_mapped_file.cc \
@ -683,10 +683,10 @@ src_tools_mac_dump_syms_dump_syms_mac_SOURCES = \
src/tools/mac/dump_syms/dump_syms_tool.cc src/tools/mac/dump_syms/dump_syms_tool.cc
src_tools_mac_dump_syms_dump_syms_mac_CXXFLAGS= \ src_tools_mac_dump_syms_dump_syms_mac_CXXFLAGS= \
-I$(top_srcdir)/src/third_party/mac_headers \ -I$(top_srcdir)/src/third_party/mac_headers \
$(RUST_DEMANGLE_CFLAGS) \ $(RUSTC_DEMANGLE_CFLAGS) \
-DHAVE_MACH_O_NLIST_H -DHAVE_MACH_O_NLIST_H
src_tools_mac_dump_syms_dump_syms_mac_LDADD= \ src_tools_mac_dump_syms_dump_syms_mac_LDADD= \
$(RUST_DEMANGLE_LIBS) $(RUSTC_DEMANGLE_LIBS)
src_common_dumper_unittest_SOURCES = \ src_common_dumper_unittest_SOURCES = \
src/common/byte_cursor_unittest.cc \ src/common/byte_cursor_unittest.cc \
@ -748,11 +748,11 @@ src_common_dumper_unittest_SOURCES = \
src/common/tests/file_utils.cc src/common/tests/file_utils.cc
src_common_dumper_unittest_CPPFLAGS = \ src_common_dumper_unittest_CPPFLAGS = \
$(AM_CPPFLAGS) $(TEST_CFLAGS) \ $(AM_CPPFLAGS) $(TEST_CFLAGS) \
$(RUST_DEMANGLE_CFLAGS) \ $(RUSTC_DEMANGLE_CFLAGS) \
$(PTHREAD_CFLAGS) $(PTHREAD_CFLAGS)
src_common_dumper_unittest_LDADD = \ src_common_dumper_unittest_LDADD = \
$(TEST_LIBS) \ $(TEST_LIBS) \
$(RUST_DEMANGLE_LIBS) \ $(RUSTC_DEMANGLE_LIBS) \
$(PTHREAD_CFLAGS) $(PTHREAD_LIBS) $(PTHREAD_CFLAGS) $(PTHREAD_LIBS)
src_common_mac_macho_reader_unittest_SOURCES = \ src_common_mac_macho_reader_unittest_SOURCES = \

View file

@ -2371,8 +2371,8 @@ PTHREAD_CC = @PTHREAD_CC@
PTHREAD_CFLAGS = @PTHREAD_CFLAGS@ PTHREAD_CFLAGS = @PTHREAD_CFLAGS@
PTHREAD_LIBS = @PTHREAD_LIBS@ PTHREAD_LIBS = @PTHREAD_LIBS@
RANLIB = @RANLIB@ RANLIB = @RANLIB@
RUST_DEMANGLE_CFLAGS = @RUST_DEMANGLE_CFLAGS@ RUSTC_DEMANGLE_CFLAGS = @RUSTC_DEMANGLE_CFLAGS@
RUST_DEMANGLE_LIBS = @RUST_DEMANGLE_LIBS@ RUSTC_DEMANGLE_LIBS = @RUSTC_DEMANGLE_LIBS@
SET_MAKE = @SET_MAKE@ SET_MAKE = @SET_MAKE@
SHELL = @SHELL@ SHELL = @SHELL@
STRIP = @STRIP@ STRIP = @STRIP@
@ -2833,10 +2833,10 @@ TESTS = $(check_PROGRAMS) $(check_SCRIPTS)
@DISABLE_TOOLS_FALSE@@LINUX_HOST_TRUE@ src/tools/linux/dump_syms/dump_syms.cc @DISABLE_TOOLS_FALSE@@LINUX_HOST_TRUE@ src/tools/linux/dump_syms/dump_syms.cc
@DISABLE_TOOLS_FALSE@@LINUX_HOST_TRUE@src_tools_linux_dump_syms_dump_syms_CXXFLAGS = \ @DISABLE_TOOLS_FALSE@@LINUX_HOST_TRUE@src_tools_linux_dump_syms_dump_syms_CXXFLAGS = \
@DISABLE_TOOLS_FALSE@@LINUX_HOST_TRUE@ $(RUST_DEMANGLE_CFLAGS) @DISABLE_TOOLS_FALSE@@LINUX_HOST_TRUE@ $(RUSTC_DEMANGLE_CFLAGS)
@DISABLE_TOOLS_FALSE@@LINUX_HOST_TRUE@src_tools_linux_dump_syms_dump_syms_LDADD = \ @DISABLE_TOOLS_FALSE@@LINUX_HOST_TRUE@src_tools_linux_dump_syms_dump_syms_LDADD = \
@DISABLE_TOOLS_FALSE@@LINUX_HOST_TRUE@ $(RUST_DEMANGLE_LIBS) @DISABLE_TOOLS_FALSE@@LINUX_HOST_TRUE@ $(RUSTC_DEMANGLE_LIBS)
@DISABLE_TOOLS_FALSE@@LINUX_HOST_TRUE@src_tools_linux_md2core_minidump_2_core_SOURCES = \ @DISABLE_TOOLS_FALSE@@LINUX_HOST_TRUE@src_tools_linux_md2core_minidump_2_core_SOURCES = \
@DISABLE_TOOLS_FALSE@@LINUX_HOST_TRUE@ src/common/linux/memory_mapped_file.cc \ @DISABLE_TOOLS_FALSE@@LINUX_HOST_TRUE@ src/common/linux/memory_mapped_file.cc \
@ -2895,11 +2895,11 @@ TESTS = $(check_PROGRAMS) $(check_SCRIPTS)
@DISABLE_TOOLS_FALSE@@LINUX_HOST_TRUE@src_tools_mac_dump_syms_dump_syms_mac_CXXFLAGS = \ @DISABLE_TOOLS_FALSE@@LINUX_HOST_TRUE@src_tools_mac_dump_syms_dump_syms_mac_CXXFLAGS = \
@DISABLE_TOOLS_FALSE@@LINUX_HOST_TRUE@ -I$(top_srcdir)/src/third_party/mac_headers \ @DISABLE_TOOLS_FALSE@@LINUX_HOST_TRUE@ -I$(top_srcdir)/src/third_party/mac_headers \
@DISABLE_TOOLS_FALSE@@LINUX_HOST_TRUE@ $(RUST_DEMANGLE_CFLAGS) \ @DISABLE_TOOLS_FALSE@@LINUX_HOST_TRUE@ $(RUSTC_DEMANGLE_CFLAGS) \
@DISABLE_TOOLS_FALSE@@LINUX_HOST_TRUE@ -DHAVE_MACH_O_NLIST_H @DISABLE_TOOLS_FALSE@@LINUX_HOST_TRUE@ -DHAVE_MACH_O_NLIST_H
@DISABLE_TOOLS_FALSE@@LINUX_HOST_TRUE@src_tools_mac_dump_syms_dump_syms_mac_LDADD = \ @DISABLE_TOOLS_FALSE@@LINUX_HOST_TRUE@src_tools_mac_dump_syms_dump_syms_mac_LDADD = \
@DISABLE_TOOLS_FALSE@@LINUX_HOST_TRUE@ $(RUST_DEMANGLE_LIBS) @DISABLE_TOOLS_FALSE@@LINUX_HOST_TRUE@ $(RUSTC_DEMANGLE_LIBS)
@DISABLE_TOOLS_FALSE@@LINUX_HOST_TRUE@src_common_dumper_unittest_SOURCES = \ @DISABLE_TOOLS_FALSE@@LINUX_HOST_TRUE@src_common_dumper_unittest_SOURCES = \
@DISABLE_TOOLS_FALSE@@LINUX_HOST_TRUE@ src/common/byte_cursor_unittest.cc \ @DISABLE_TOOLS_FALSE@@LINUX_HOST_TRUE@ src/common/byte_cursor_unittest.cc \
@ -2962,12 +2962,12 @@ TESTS = $(check_PROGRAMS) $(check_SCRIPTS)
@DISABLE_TOOLS_FALSE@@LINUX_HOST_TRUE@src_common_dumper_unittest_CPPFLAGS = \ @DISABLE_TOOLS_FALSE@@LINUX_HOST_TRUE@src_common_dumper_unittest_CPPFLAGS = \
@DISABLE_TOOLS_FALSE@@LINUX_HOST_TRUE@ $(AM_CPPFLAGS) $(TEST_CFLAGS) \ @DISABLE_TOOLS_FALSE@@LINUX_HOST_TRUE@ $(AM_CPPFLAGS) $(TEST_CFLAGS) \
@DISABLE_TOOLS_FALSE@@LINUX_HOST_TRUE@ $(RUST_DEMANGLE_CFLAGS) \ @DISABLE_TOOLS_FALSE@@LINUX_HOST_TRUE@ $(RUSTC_DEMANGLE_CFLAGS) \
@DISABLE_TOOLS_FALSE@@LINUX_HOST_TRUE@ $(PTHREAD_CFLAGS) @DISABLE_TOOLS_FALSE@@LINUX_HOST_TRUE@ $(PTHREAD_CFLAGS)
@DISABLE_TOOLS_FALSE@@LINUX_HOST_TRUE@src_common_dumper_unittest_LDADD = \ @DISABLE_TOOLS_FALSE@@LINUX_HOST_TRUE@src_common_dumper_unittest_LDADD = \
@DISABLE_TOOLS_FALSE@@LINUX_HOST_TRUE@ $(TEST_LIBS) \ @DISABLE_TOOLS_FALSE@@LINUX_HOST_TRUE@ $(TEST_LIBS) \
@DISABLE_TOOLS_FALSE@@LINUX_HOST_TRUE@ $(RUST_DEMANGLE_LIBS) \ @DISABLE_TOOLS_FALSE@@LINUX_HOST_TRUE@ $(RUSTC_DEMANGLE_LIBS) \
@DISABLE_TOOLS_FALSE@@LINUX_HOST_TRUE@ $(PTHREAD_CFLAGS) $(PTHREAD_LIBS) @DISABLE_TOOLS_FALSE@@LINUX_HOST_TRUE@ $(PTHREAD_CFLAGS) $(PTHREAD_LIBS)
@DISABLE_TOOLS_FALSE@@LINUX_HOST_TRUE@src_common_mac_macho_reader_unittest_SOURCES = \ @DISABLE_TOOLS_FALSE@@LINUX_HOST_TRUE@src_common_mac_macho_reader_unittest_SOURCES = \

40
configure vendored
View file

@ -628,8 +628,8 @@ LTLIBOBJS
LIBOBJS LIBOBJS
TESTS_AS_ROOT_FALSE TESTS_AS_ROOT_FALSE
TESTS_AS_ROOT_TRUE TESTS_AS_ROOT_TRUE
RUST_DEMANGLE_LIBS RUSTC_DEMANGLE_LIBS
RUST_DEMANGLE_CFLAGS RUSTC_DEMANGLE_CFLAGS
SELFTEST_FALSE SELFTEST_FALSE
SELFTEST_TRUE SELFTEST_TRUE
GTEST_LIBS GTEST_LIBS
@ -781,7 +781,7 @@ enable_processor
enable_tools enable_tools
enable_system_test_libs enable_system_test_libs
enable_selftest enable_selftest
with_rust_demangle with_rustc_demangle
with_tests_as_root with_tests_as_root
' '
ac_precious_vars='build_alias ac_precious_vars='build_alias
@ -802,8 +802,8 @@ GMOCK_CFLAGS
GMOCK_LIBS GMOCK_LIBS
GTEST_CFLAGS GTEST_CFLAGS
GTEST_LIBS GTEST_LIBS
RUST_DEMANGLE_CFLAGS RUSTC_DEMANGLE_CFLAGS
RUST_DEMANGLE_LIBS' RUSTC_DEMANGLE_LIBS'
# Initialize some variables set by options. # Initialize some variables set by options.
@ -1455,8 +1455,8 @@ Optional Features:
Optional Packages: Optional Packages:
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes] --with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
--without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no)
--with-rust-demangle=/path/to/rust-demangle-capi --with-rustc-demangle=/path/to/rustc-demangle
Link against the rust-demangle library to demangle Link against the rustc-demangle library to demangle
Rust language symbols during symbol dumping (default Rust language symbols during symbol dumping (default
is no) Pass the path to the crate root. is no) Pass the path to the crate root.
--with-tests-as-root Run the tests as root. Use this on platforms like --with-tests-as-root Run the tests as root. Use this on platforms like
@ -1482,10 +1482,10 @@ Some influential environment variables:
GTEST_CFLAGS GTEST_CFLAGS
Compiler flags for gtest Compiler flags for gtest
GTEST_LIBS Linker flags for gtest GTEST_LIBS Linker flags for gtest
RUST_DEMANGLE_CFLAGS RUSTC_DEMANGLE_CFLAGS
Compiler flags for rust-demangle Compiler flags for rustc-demangle
RUST_DEMANGLE_LIBS RUSTC_DEMANGLE_LIBS
Linker flags for rust-demangle Linker flags for rustc-demangle
Use these variables to override the choices made by `configure' or to help Use these variables to override the choices made by `configure' or to help
it to find libraries and programs with nonstandard names/locations. it to find libraries and programs with nonstandard names/locations.
@ -7690,25 +7690,25 @@ fi
# Check whether --with-rust-demangle was given. # Check whether --with-rustc-demangle was given.
if test "${with_rust_demangle+set}" = set; then : if test "${with_rustc_demangle+set}" = set; then :
withval=$with_rust_demangle; case "${withval}" in withval=$with_rustc_demangle; case "${withval}" in
yes) yes)
as_fn_error $? "You must pass the path to the rust-demangle-capi crate for --with-rust-demangle" "$LINENO" 5 as_fn_error $? "You must pass the path to the rustc-demangle crate for --with-rustc-demangle" "$LINENO" 5
;; ;;
no) no)
rust_demangle=false rustc_demangle=false
;; ;;
*) *)
if ! test -f "${withval}/Cargo.toml"; then if ! test -f "${withval}/Cargo.toml"; then
as_fn_error $? "You must pass the path to the rust-demangle-capi crate for --with-rust-demangle" "$LINENO" 5 as_fn_error $? "You must pass the path to the rustc-demangle crate for --with-rustc-demangle" "$LINENO" 5
fi fi
RUST_DEMANGLE_CFLAGS="-DHAVE_RUST_DEMANGLE -I${withval}/target/include" RUSTC_DEMANGLE_CFLAGS="-DHAVE_RUSTC_DEMANGLE -I${withval}/crates/capi/include"
RUST_DEMANGLE_LIBS="-L${withval}/target/release -lrust_demangle -lpthread -ldl" RUSTC_DEMANGLE_LIBS="-L${withval}/target/release -lrustc_demangle -lpthread -ldl"
;; ;;
esac esac
else else
rust_demangle=false rustc_demangle=false
fi fi

View file

@ -219,30 +219,30 @@ AC_ARG_ENABLE(selftest,
[selftest=false]) [selftest=false])
AM_CONDITIONAL(SELFTEST, test x$selftest = xtrue) AM_CONDITIONAL(SELFTEST, test x$selftest = xtrue)
AC_ARG_WITH(rust-demangle, AC_ARG_WITH(rustc-demangle,
AS_HELP_STRING([--with-rust-demangle=/path/to/rust-demangle-capi], AS_HELP_STRING([--with-rustc-demangle=/path/to/rustc-demangle],
[Link against the rust-demangle library] [Link against the rustc-demangle library]
[to demangle Rust language symbols during] [to demangle Rust language symbols during]
[symbol dumping (default is no)] [symbol dumping (default is no)]
[Pass the path to the crate root.]), [Pass the path to the crate root.]),
[case "${withval}" in [case "${withval}" in
yes) yes)
AC_MSG_ERROR(You must pass the path to the rust-demangle-capi crate for --with-rust-demangle) AC_MSG_ERROR(You must pass the path to the rustc-demangle crate for --with-rustc-demangle)
;; ;;
no) no)
rust_demangle=false rustc_demangle=false
;; ;;
*) *)
if ! test -f "${withval}/Cargo.toml"; then if ! test -f "${withval}/Cargo.toml"; then
AC_MSG_ERROR(You must pass the path to the rust-demangle-capi crate for --with-rust-demangle) AC_MSG_ERROR(You must pass the path to the rustc-demangle crate for --with-rustc-demangle)
fi fi
RUST_DEMANGLE_CFLAGS="-DHAVE_RUST_DEMANGLE -I${withval}/target/include" RUSTC_DEMANGLE_CFLAGS="-DHAVE_RUSTC_DEMANGLE -I${withval}/crates/capi/include"
RUST_DEMANGLE_LIBS="-L${withval}/target/release -lrust_demangle -lpthread -ldl" RUSTC_DEMANGLE_LIBS="-L${withval}/target/release -lrustc_demangle -lpthread -ldl"
;; ;;
esac], esac],
[rust_demangle=false]) [rustc_demangle=false])
AC_ARG_VAR([RUST_DEMANGLE_CFLAGS], [Compiler flags for rust-demangle]) AC_ARG_VAR([RUSTC_DEMANGLE_CFLAGS], [Compiler flags for rustc-demangle])
AC_ARG_VAR([RUST_DEMANGLE_LIBS], [Linker flags for rust-demangle]) AC_ARG_VAR([RUSTC_DEMANGLE_LIBS], [Linker flags for rustc-demangle])
AC_ARG_WITH(tests-as-root, AC_ARG_WITH(tests-as-root,
AS_HELP_STRING([--with-tests-as-root], AS_HELP_STRING([--with-tests-as-root],

View file

@ -1268,12 +1268,12 @@ TEST_F(Specifications, MangledNameRust) {
TestFunctionCount(1); TestFunctionCount(1);
TestFunction(0, TestFunction(0,
#ifndef HAVE_RUST_DEMANGLE #ifndef HAVE_RUSTC_DEMANGLE
// Rust mangled names should pass through untouched if not // Rust mangled names should pass through untouched if not
// using rust-demangle. // using rustc-demangle.
kName, kName,
#else #else
// If rust-demangle is available this should be properly // If rustc-demangle is available this should be properly
// demangled. // demangled.
"rustc_demangle::demangle", "rustc_demangle::demangle",
#endif #endif

View file

@ -35,13 +35,14 @@
#include "common/language.h" #include "common/language.h"
#include <stdlib.h> #include <stdlib.h>
#include <array>
#if !defined(__ANDROID__) #if !defined(__ANDROID__)
#include <cxxabi.h> #include <cxxabi.h>
#endif #endif
#if defined(HAVE_RUST_DEMANGLE) #if defined(HAVE_RUSTC_DEMANGLE)
#include <rust_demangle.h> #include <rustc_demangle.h>
#endif #endif
#include <limits> #include <limits>
@ -178,13 +179,13 @@ class RustLanguage: public Language {
// abi_demangle doesn't produce stellar results due to them having // abi_demangle doesn't produce stellar results due to them having
// another layer of encoding. // another layer of encoding.
// If callers provide rustc-demangle, use that. // If callers provide rustc-demangle, use that.
#if defined(HAVE_RUST_DEMANGLE) #if defined(HAVE_RUSTC_DEMANGLE)
char* rust_demangled = rust_demangle(mangled.c_str()); std::array<char, 1 * 1024 * 1024> rustc_demangled;
if (rust_demangled == nullptr) { if (rustc_demangle(mangled.c_str(), rustc_demangled.data(),
rustc_demangled.size()) == 0) {
return kDemangleFailure; return kDemangleFailure;
} }
demangled->assign(rust_demangled); demangled->assign(rustc_demangled.data());
free_rust_demangled_name(rust_demangled);
#else #else
// Otherwise, pass through the mangled name so callers can demangle // Otherwise, pass through the mangled name so callers can demangle
// after the fact. // after the fact.