bheisler / criterion.rs

Statistics-driven benchmarking library for Rust
Apache License 2.0
4.62k stars 310 forks source link

Segfault in code that passes valgrind/asan #779

Closed ephraimfeldblum closed 6 months ago

ephraimfeldblum commented 6 months ago

Hi,

I'm currently attempting to run benchmarks on some code that passes valgrind and asan with no issues. (Since the code reaches out across an ffi, I cannot use miri.)

When running a benchmark, I get this output

     Running benches/my_bench.rs (target/x86_64-unknown-linux-gnu/release/deps/my_bench-7ae86f1f06c70778)
Gnuplot not found, using plotters backend
Benchmarking my_bench: Warming up for 3.0000 serror: bench failed, to rerun pass `--bench my_bench`

Caused by:
  process didn't exit successfully: `./target/x86_64-unknown-linux-gnu/release/deps/my_bench-7ae86f1f06c70778 --bench` (signal: 11, SIGSEGV: invalid memory reference)

and in valgrind

     Running benches/my_bench.rs (target/x86_64-unknown-linux-gnu/release/deps/my_bench-7ae86f1f06c70778)
error: invalid valgrind usage: Gnuplot not found or not usable, using plotters backend
`gnuplot --version` failed with error message:

Benchmarking my_bench: Warming up for 3.0000 svex amd64->IR: unhandled instruction bytes: 0x60 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0xA1 0xB2
vex amd64->IR:   REX=0 REX.W=0 REX.R=0 REX.X=0 REX.B=0
vex amd64->IR:   VEX=0 VEX.L=0 VEX.nVVVV=0x0 ESC=NONE
vex amd64->IR:   PFX.66=0 PFX.F2=0 PFX.F3=0
==2137291== valgrind: Unrecognised instruction at address 0x4cced58.
==2137291== Your program just tried to execute an instruction that Valgrind
==2137291== did not recognise.  There are two possible reasons for this.
==2137291== 1. Your program has a bug and erroneously jumped to a non-code
==2137291==    location.  If you are running Memcheck and you just saw a
==2137291==    warning about a bad jump, it's probably your program's fault.
==2137291== 2. The instruction is legitimate but Valgrind doesn't handle it,
==2137291==    i.e. it's Valgrind's fault.  If you think this is the case or
==2137291==    you are not sure, please let us know and we'll try to fix it.
==2137291== Either way, Valgrind will now raise a SIGILL signal which will
==2137291== probably kill your program.

error: bench failed, to rerun pass `--bench my_bench`

Caused by:
  process didn't exit successfully: `~/.cargo/bin/cargo-valgrind ./target/x86_64-unknown-linux-gnu/release/deps/my_bench-7ae86f1f06c70778 --bench` (exit status: 1)

however it runs perfectly fine in asan:

     Running benches/my_bench.rs (target/x86_64-unknown-linux-gnu/release/deps/my_bench-d0496f8c871d05a6)
Gnuplot not found, using plotters backend
my_bench                time:   [1.0089 µs 1.0412 µs 1.0735 µs]
                        change: [-15.885% -8.1616% +0.6376%] (p = 0.06 > 0.05)
                        No change in performance detected.
Found 4 outliers among 100 measurements (4.00%)
  3 (3.00%) high mild
  1 (1.00%) high severe
ephraimfeldblum commented 6 months ago

Upon further inspection in gdb, the segfault is coming from the C library I'm calling. though why it doesn't occur in non-bench cases, idk.