Bug 432440 - Valgrind always crashes Rust programs on FreeBSD with "failed to allocate a guard page"
Summary: Valgrind always crashes Rust programs on FreeBSD with "failed to allocate a g...
Status: RESOLVED DOWNSTREAM
Alias: None
Product: valgrind
Classification: Developer tools
Component: general (show other bugs)
Version: unspecified
Platform: Other FreeBSD
: NOR normal
Target Milestone: ---
Assignee: Julian Seward
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-02-02 23:24 UTC by asomers
Modified: 2021-02-03 22:36 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description asomers 2021-02-02 23:24:50 UTC
SUMMARY
Every Rust program will crash on FreeBSD when run with Valgrind with the error "failed to allocate a guard page".  This affects literally every single Rust program.  For example, ripgrep.  It affects every tool: memcheck, cachegrind, callgrind, helgrind, drd, massif, lackey, exp-bbv, and even none.

STEPS TO REPRODUCE
1. pkg install ripgrep
2. valgrind --tool=callgrind /usr/local/bin/rg

OBSERVED RESULT
$ valgrind --tool=memcheck /usr/local/bin/rg
==10062== Memcheck, a memory error detector
==10062== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==10062== Using Valgrind-3.17.0.GIT and LibVEX; rerun with -h for copyright info
==10062== Command: /usr/local/bin/rg
==10062== 
thread '<unnamed>' panicked at 'failed to allocate a guard page', library/std/src/sys/unix/thread.rs:364:17
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
fatal runtime error: failed to initiate panic, error 5
==10062== 
==10062== Process terminating with default action of signal 6 (SIGABRT): dumping core


EXPECTED RESULT
The program should run normally.

SOFTWARE/OS VERSIONS
FreeBSD.  Reproduced on 14.0-CURRENT, 12.2-RELEASE, 11.2-RELEASE, and 11.4-RELEASE amd64.
Reproduced with Valgrind 3.10.1 and 3.17.0.GIT, 

ADDITIONAL INFORMATION

Rust bug entry.  The Rust team believes this to be a Valgrind bug, however.
https://github.com/rust-lang/rust/issues/67153

Rust code that allocates the guard page on startup of every program.
https://doc.rust-lang.org/src/std/sys/unix/thread.rs.html#346
Comment 1 Tom Hughes 2021-02-03 00:01:48 UTC
The FreeBSD port of valgrind is currently a separate fork that is not maintained as part of the core project.

You can find an issue tracker for it at https://github.com/paulfloyd/freebsd_valgrind/issues.
Comment 2 asomers 2021-02-03 00:14:36 UTC
Thanks for the pointer Tom.  However, I should add that the Rust code in question is identical on every platform except Linux.  So this bug might affect Solaris and OSX in addition to FreeBSD.  However, I don't have the ability to test on those platforms.
Comment 3 Tom Hughes 2021-02-03 00:37:40 UTC
That error won't be anything to do with the code as such though, it will be to do with the OS integration and how the system calls and memory management are emulated and the details of that will likely vary even among different BSD derived platforms.
Comment 4 Paul Floyd 2021-02-03 10:05:01 UTC
(In reply to asomers from comment #2)
> Thanks for the pointer Tom.  However, I should add that the Rust code in
> question is identical on every platform except Linux.  So this bug might
> affect Solaris and OSX in addition to FreeBSD.  However, I don't have the
> ability to test on those platforms.

I can test Solaris if I can get my hands on a rust executable. macOS is rather more difficult to test, even though I do have a MacBook.

I'll try to figure what is going on with FreeBSD.
Comment 5 asomers 2021-02-03 22:36:12 UTC
(In reply to Paul Floyd from comment #4)
> (In reply to asomers from comment #2)
> > Thanks for the pointer Tom.  However, I should add that the Rust code in
> > question is identical on every platform except Linux.  So this bug might
> > affect Solaris and OSX in addition to FreeBSD.  However, I don't have the
> > ability to test on those platforms.
> 
> I can test Solaris if I can get my hands on a rust executable. macOS is
> rather more difficult to test, even though I do have a MacBook.
> 
> I'll try to figure what is going on with FreeBSD.

I don't have an easy way to build you an executable, but the following commands should work if you have an Illumos machine.

$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
$ . ~/.cargo/env
$ cargo new hello
$ cd hello
$ cargo build
$ target/debug/hello