You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
segfault on 'index out of bounds' OS X Yosemite #51794
I get Segmentation Fault on this code when running the debug binary.
Only happens on OS X Yosemite 10.10.5 .
fnmain(){let x = [1];println!("{}", x[1]);}
$ cargo run
Finished dev [unoptimized + debuginfo] target(s) in 0.02s
Running `target/debug/segfault`
Segmentation fault: 11
$ cargo run --release
Finished release [optimized] target(s) in 0.02s
Running `target/release/segfault`
thread 'main' panicked at 'index out of bounds: the len is 1 but the index is 1', src/main.rs:3:20
note: Run with `RUST_BACKTRACE=1`for a backtrace.
$ lldb segfault
(lldb) target create "segfault"
Current executable set to 'segfault' (x86_64).
(lldb) run
Process 57139 launched: '/Users/felipenoris/Documents/src/learnrust/segfault/target/debug/segfault' (x86_64)
segfault was compiled with optimization - stepping may behave oddly; variables may not be available.
Process 57139 stopped
* thread #1: tid = 0x793cbc, 0x0000000100011abf segfault`std::panicking::rust_panic_with_hook::hc2253a5bcda7eda7 [inlined] core::ptr::swap_nonoverlapping_bytes::h90af7d9428701cbf + 16 at ptr.rs:237, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
frame #0: 0x0000000100011abf segfault`std::panicking::rust_panic_with_hook::hc2253a5bcda7eda7 [inlined] core::ptr::swap_nonoverlapping_bytes::h90af7d9428701cbf + 16 at ptr.rs:237 [opt]
@kennytm , with the prebuilt binaries results looks good. It replaces the runtime error with compile-time error.
$ cargo +77a8ed98fc66821a410b0c4696ba99b07b713467 run
Compiling segfault v0.1.0 (file:///Users/felipenoris/Documents/src/learnrust/segfault)
error: index out of bounds: the len is 1 but the index is 1
--> src/main.rs:3:20
|
3 | println!("{}", x[1]);
| ^^^^
|
= note: #[deny(const_err)] on by default
error: aborting due to previous error
error: Could not compile `segfault`.
To learn more, run the command again with --verbose.
Even if I rewrite the program to get a runtime error, the segfault doesn't happen.
fnmain(){let x = [1];let i = 1;println!("{}", x[i]);}
$ cargo +77a8ed98fc66821a410b0c4696ba99b07b713467 run
Compiling segfault v0.1.0 (file:///Users/felipenoris/Documents/src/learnrust/segfault)
Finished dev [unoptimized + debuginfo] target(s) in 0.27s
Running `target/debug/segfault`
thread 'main' panicked at 'index out of bounds: the len is 1 but the index is 1', src/main.rs:4:20
note: Run with `RUST_BACKTRACE=1`for a backtrace.
I got another code example that reproduces the segfault. Again, the solution by @kennytm also covers this.
fnmain(){let i:u8 = 254;println!("{}", i+2);}
$ cargo run
Compiling strings v0.1.0 (file:///Users/felipenoris/Documents/src/learnrust/strings)
Finished dev [unoptimized + debuginfo] target(s) in 0.27s
Running `target/debug/strings`
Segmentation fault: 11
$ cargo +77a8ed98fc66821a410b0c4696ba99b07b713467 run
Compiling strings v0.1.0 (file:///Users/felipenoris/Documents/src/learnrust/strings)
Finished dev [unoptimized + debuginfo] target(s) in 1.57s
Running `target/debug/strings`
thread 'main' panicked at 'attempt to add with overflow', src/main.rs:5:20
note: Run with `RUST_BACKTRACE=1`for a backtrace.
Activity
Mark-Simulacrum commentedon Jun 25, 2018
I cannot reproduce on macOS 10.13.5 (High Sierra).
@rust-lang/release if anyone can reproduce and bisect, that would be amazing.
cc @rust-lang/compiler -- stable regression
kennytm commentedon Jun 26, 2018
I bet it is the same cause as #51758 (misaligned TLS).
Mark-Simulacrum commentedon Jun 26, 2018
Seems likely -- this is in stable, though, so probably not caused by that. Getting confirmation would be good as well.
kennytm commentedon Jun 26, 2018
The use of --release matches #50586
Mark-Simulacrum commentedon Jun 26, 2018
This is the reverse of that PR; this bug seems to only happen without
--releasewhereas that one happens only with it.nikomatsakis commentedon Jun 26, 2018
This does indeed seem quite bad.
nikomatsakis commentedon Jun 26, 2018
I cannot reproduce on my laptop, but it is 10.11.6. I'll have to see if I have a machine running 10.10 anywhere.
kennytm commentedon Jun 26, 2018
@felipenoris Could you load
target/debug/segfaultinto a debugger (gdborlldb) and get the backtrace when it segfault?felipenoris commentedon Jun 27, 2018
Sure. I'll work on that.
felipenoris commentedon Jun 27, 2018
2 remaining items
felipenoris commentedon Jun 27, 2018
felipenoris commentedon Jun 27, 2018
About the toolchain:
kennytm commentedon Jun 27, 2018
@felipenoris Does the prebuilt binary work then?
felipenoris commentedon Jun 27, 2018
@kennytm , with the prebuilt binaries results looks good. It replaces the runtime error with compile-time error.
felipenoris commentedon Jun 27, 2018
Even if I rewrite the program to get a runtime error, the segfault doesn't happen.
$ cargo +77a8ed98fc66821a410b0c4696ba99b07b713467 run Compiling segfault v0.1.0 (file:///Users/felipenoris/Documents/src/learnrust/segfault) Finished dev [unoptimized + debuginfo] target(s) in 0.27s Running `target/debug/segfault` thread 'main' panicked at 'index out of bounds: the len is 1 but the index is 1', src/main.rs:4:20 note: Run with `RUST_BACKTRACE=1` for a backtrace.nikomatsakis commentedon Jun 28, 2018
Assigning to @kennytm, who seems to be making good progress here (cc #51828)
nikomatsakis commentedon Jun 28, 2018
Some discussion on IRC here https://botbot.me/mozilla/rustc/2018-06-28/?msg=101569375&page=2
Auto merge of #51828 - kennytm:no-simd-swap-for-mac, r=<try>
Rollup merge of rust-lang#51828 - kennytm:no-simd-swap-for-mac, r=ale…
felipenoris commentedon Jun 30, 2018
I got another code example that reproduces the segfault. Again, the solution by @kennytm also covers this.
$ cargo run Compiling strings v0.1.0 (file:///Users/felipenoris/Documents/src/learnrust/strings) Finished dev [unoptimized + debuginfo] target(s) in 0.27s Running `target/debug/strings` Segmentation fault: 11 $ cargo +77a8ed98fc66821a410b0c4696ba99b07b713467 run Compiling strings v0.1.0 (file:///Users/felipenoris/Documents/src/learnrust/strings) Finished dev [unoptimized + debuginfo] target(s) in 1.57s Running `target/debug/strings` thread 'main' panicked at 'attempt to add with overflow', src/main.rs:5:20 note: Run with `RUST_BACKTRACE=1` for a backtrace.