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
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.
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.
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.
(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.
(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