|
From: Nicholas N. <nj...@so...> - 2021-11-09 23:19:12
|
https://sourceware.org/git/gitweb.cgi?p=valgrind.git;h=4831385c6706b377851284adc4c4545fff4c6564 commit 4831385c6706b377851284adc4c4545fff4c6564 Author: Nicholas Nethercote <nne...@ap...> Date: Tue Nov 9 12:30:07 2021 +1100 Fix Rust v0 demangling. It's currently broken due to a silly test that prevents the v0 demangling code from even running. The commit also adds a test, to avoid such problems in the future. Diff: --- coregrind/m_demangle/demangle.c | 7 ++++++- memcheck/tests/demangle-rust.c | 31 +++++++++++++++++++++++++++++++ memcheck/tests/demangle-rust.stderr.exp | 6 ++++++ memcheck/tests/demangle-rust.vgtest | 2 ++ 4 files changed, 45 insertions(+), 1 deletion(-) diff --git a/coregrind/m_demangle/demangle.c b/coregrind/m_demangle/demangle.c index 16161da2af..3fd7cb75f5 100644 --- a/coregrind/m_demangle/demangle.c +++ b/coregrind/m_demangle/demangle.c @@ -118,8 +118,13 @@ void VG_(demangle) ( Bool do_cxx_demangling, Bool do_z_demangling, } /* Possibly undo (1) */ + // - C++ mangled symbols start with "_Z" (possibly with exceptions?) + // - Rust "legacy" mangled symbols start with "_Z". + // - Rust "v0" mangled symbols start with "_R". + // XXX: the Java/Rust/Ada demangling here probably doesn't work. See + // https://bugs.kde.org/show_bug.cgi?id=445235 for details. if (do_cxx_demangling && VG_(clo_demangle) - && orig != NULL && orig[0] == '_' && orig[1] == 'Z') { + && orig != NULL && orig[0] == '_' && (orig[1] == 'Z' || orig[1] == 'R')) { /* !!! vvv STATIC vvv !!! */ static HChar* demangled = NULL; /* !!! ^^^ STATIC ^^^ !!! */ diff --git a/memcheck/tests/demangle-rust.c b/memcheck/tests/demangle-rust.c new file mode 100644 index 0000000000..f2a458b2ac --- /dev/null +++ b/memcheck/tests/demangle-rust.c @@ -0,0 +1,31 @@ +// Valgrind supports demangling Rust symbols (both the "v0" and "legacy" +// mangling schemes), but we don't want to add a dependency on the Rust +// compiler for a single test. So this is a C program with function names that +// are mangled Rust symbols. In the output, they become demangled Rust names. +// It's a hack, but a useful one. + +#include <stdlib.h> + +// A v0 symbol that demangles to: <rustc_middle::ty::PredicateKind as rustc_middle::ty::fold::TypeFoldable>::fold_with::<rustc_infer::infer::resolve::OpportunisticVarResolver> +int _RINvYNtNtCs4uGc65yWeeX_12rustc_middle2ty13PredicateKindNtNtB5_4fold12TypeFoldable9fold_withNtNtNtCsgI90OQiJWEs_11rustc_infer5infer7resolve24OpportunisticVarResolverECsdozMG8X9FIu_21rustc_trait_selection(int *p) +{ + return *p ? 1 : 2; +} + +// A v0 symbol that demangles to: rustc_expand::mbe::macro_parser::parse_tt +int _RNvNtNtCsaqSe1lZGvEL_12rustc_expand3mbe12macro_parser8parse_tt(int* p) +{ + return _RINvYNtNtCs4uGc65yWeeX_12rustc_middle2ty13PredicateKindNtNtB5_4fold12TypeFoldable9fold_withNtNtNtCsgI90OQiJWEs_11rustc_infer5infer7resolve24OpportunisticVarResolverECsdozMG8X9FIu_21rustc_trait_selection(p); +} + +// A legacy symbol that demangles to: core::str::lossy::Utf8Lossy::from_bytes +int _ZN4core3str5lossy9Utf8Lossy10from_bytes17heb1677c8cb728b0bE(int* p) +{ + return _RNvNtNtCsaqSe1lZGvEL_12rustc_expand3mbe12macro_parser8parse_tt(p); +} + +int main(void) +{ + return _ZN4core3str5lossy9Utf8Lossy10from_bytes17heb1677c8cb728b0bE(malloc(sizeof(int))); +} + diff --git a/memcheck/tests/demangle-rust.stderr.exp b/memcheck/tests/demangle-rust.stderr.exp new file mode 100644 index 0000000000..f04bb625b1 --- /dev/null +++ b/memcheck/tests/demangle-rust.stderr.exp @@ -0,0 +1,6 @@ +Conditional jump or move depends on uninitialised value(s) + at 0x........: <rustc_middle::ty::PredicateKind as rustc_middle::ty::fold::TypeFoldable>::fold_with::<rustc_infer::infer::resolve::OpportunisticVarResolver> (demangle-rust.c:12) + by 0x........: rustc_expand::mbe::macro_parser::parse_tt (demangle-rust.c:18) + by 0x........: core::str::lossy::Utf8Lossy::from_bytes (demangle-rust.c:24) + by 0x........: main (demangle-rust.c:29) + diff --git a/memcheck/tests/demangle-rust.vgtest b/memcheck/tests/demangle-rust.vgtest new file mode 100644 index 0000000000..d726c6b2e4 --- /dev/null +++ b/memcheck/tests/demangle-rust.vgtest @@ -0,0 +1,2 @@ +prog: demangle-rust +vgopts: -q |
|
From: Paul F. <pj...@wa...> - 2021-11-11 21:01:06
|
On 11/10/21 00:19, Nicholas Nethercote wrote: > https://sourceware.org/git/gitweb.cgi?p=valgrind.git;h=4831385c6706b377851284adc4c4545fff4c6564 > > commit 4831385c6706b377851284adc4c4545fff4c6564 > Author: Nicholas Nethercote <nne...@ap...> > Date: Tue Nov 9 12:30:07 2021 +1100 > > Fix Rust v0 demangling. > > It's currently broken due to a silly test that prevents the v0 > demangling code from even running. > > The commit also adds a test, to avoid such problems in the future. Hi This test fails with clang. I haven't looked as the assembler, but from experience int _RINvYNtNtCs4uGc65yWeeX_12rustc_middle2ty13PredicateKindNtNtB5_4fold12TypeFo ldable9fold_withNtNtNtCsgI90OQiJWEs_11rustc_infer5infer7resolve24OpportunisticVa rResolverECsdozMG8X9FIu_21rustc_trait_selection(int *p) { return *p ? 1 : 2; } probably generates a cmov with clang and test / jump conditional with GCC. This delays the error, so all I get is Syscall param exit(status) contains uninitialised byte(s) ... A+ Paul |
|
From: Nicholas N. <n.n...@gm...> - 2021-11-12 00:14:13
|
I copied the memcheck/tests/demangle.cpp test. Do you get the same failure for that test? Nick On Fri, 12 Nov 2021 at 08:01, Paul Floyd <pj...@wa...> wrote: > > On 11/10/21 00:19, Nicholas Nethercote wrote: > > > https://sourceware.org/git/gitweb.cgi?p=valgrind.git;h=4831385c6706b377851284adc4c4545fff4c6564 > > > > commit 4831385c6706b377851284adc4c4545fff4c6564 > > Author: Nicholas Nethercote <nne...@ap...> > > Date: Tue Nov 9 12:30:07 2021 +1100 > > > > Fix Rust v0 demangling. > > > > It's currently broken due to a silly test that prevents the v0 > > demangling code from even running. > > > > The commit also adds a test, to avoid such problems in the future. > > > Hi > > This test fails with clang. I haven't looked as the assembler, but from > experience > > > int > > _RINvYNtNtCs4uGc65yWeeX_12rustc_middle2ty13PredicateKindNtNtB5_4fold12TypeFo > ldable9fold_withNtNtNtCsgI90OQiJWEs_11rustc_infer5infer7resolve24OpportunisticVa > > > rResolverECsdozMG8X9FIu_21rustc_trait_selection(int *p) > { > return *p ? 1 : 2; > } > > probably generates a cmov with clang and test / jump conditional with GCC. > > This delays the error, so all I get is > > > Syscall param exit(status) contains uninitialised byte(s) > ... > > A+ > > Paul > > > > > > _______________________________________________ > Valgrind-developers mailing list > Val...@li... > https://lists.sourceforge.net/lists/listinfo/valgrind-developers > |
|
From: Paul F. <pj...@wa...> - 2021-11-12 07:03:45
|
On 11/12/21 01:13, Nicholas Nethercote wrote:
> I copied the memcheck/tests/demangle.cpp test. Do you get the same
> failure for that test?
>
> Nick
>
Hi Nick
Indeed that testcase is not really testing much with clang either.
I'll change them both to use double free and mismatch free, like below
but without the commented out code. The actual error isn't important I
suppose - we just want a stack trace with the demangling.
A+
Paul
diff --git a/memcheck/tests/demangle-rust.c b/memcheck/tests/demangle-rust.c
index f2a458b2a..1133563b0 100644
--- a/memcheck/tests/demangle-rust.c
+++ b/memcheck/tests/demangle-rust.c
@@ -9,7 +9,10 @@
// A v0 symbol that demangles to: <rustc_middle::ty::PredicateKind as
rustc_mid
dle::ty::fold::TypeFoldable>::fold_with::<rustc_infer::infer::resolve::Opportuni
sticVarResolver>
int
_RINvYNtNtCs4uGc65yWeeX_12rustc_middle2ty13PredicateKindNtNtB5_4fold12TypeF
oldable9fold_withNtNtNtCsgI90OQiJWEs_11rustc_infer5infer7resolve24OpportunisticV
arResolverECsdozMG8X9FIu_21rustc_trait_selection(int *p)
{
- return *p ? 1 : 2;
+// return *p ? 1 : 2;
+ free(p);
+ free(p);
+ return 1;
}
and
diff --git a/memcheck/tests/demangle.cpp b/memcheck/tests/demangle.cpp
index ff15fe12c..918478a21 100644
--- a/memcheck/tests/demangle.cpp
+++ b/memcheck/tests/demangle.cpp
@@ -1,4 +1,5 @@
// Simple smoke test to see that the demangler is actually working
+#include <cstdlib>
namespace abc {
template <typename T1, typename T2>
@@ -6,7 +7,9 @@class def {
public:
T1 xyzzy(T1 *p, T2 *)
{
- return *p ? 10 : 20;
+// return *p ? 10 : 20;
+ free(p);
+ return 10;
}
};
|