{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/34877","repository_url":"https://api.github.com/repos/rust-lang/rust","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/34877/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/34877/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/34877/events","html_url":"https://github.com/rust-lang/rust/issues/34877","id":165957682,"number":34877,"title":"large stack arrays cause segfaults in safe code (even with ulimit unlimited)","user":{"login":"m4b","id":1920204,"avatar_url":"https://avatars.githubusercontent.com/u/1920204?v=3","gravatar_id":"","url":"https://api.github.com/users/m4b","html_url":"https://github.com/m4b","followers_url":"https://api.github.com/users/m4b/followers","following_url":"https://api.github.com/users/m4b/following{/other_user}","gists_url":"https://api.github.com/users/m4b/gists{/gist_id}","starred_url":"https://api.github.com/users/m4b/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/m4b/subscriptions","organizations_url":"https://api.github.com/users/m4b/orgs","repos_url":"https://api.github.com/users/m4b/repos","events_url":"https://api.github.com/users/m4b/events{/privacy}","received_events_url":"https://api.github.com/users/m4b/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/rust-lang/rust/labels/A-llvm","name":"A-llvm","color":"d7e102"},{"url":"https://api.github.com/repos/rust-lang/rust/labels/I-crash","name":"I-crash","color":"e10c02"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":10,"created_at":"2016-07-17T02:59:12Z","updated_at":"2016-07-18T16:37:15Z","closed_at":null,"body":"Note, first make sure to set `ulimit -s unlimited` before running the program below.\r\n\r\nSomething like the following has problems with bad ASM stack offsets/accesses being generated due to 32-bit overflow.\r\n\r\nLooks like this is something known in LLVM: https://groups.google.com/forum/#!topic/llvm-dev/g4sF46a47_w\r\n\r\nThis also only seems to cause segfaults in `--release` mode\r\n\r\nNote however, it's not entirely clear how to easily get a directly heap allocated, large fixed size array without resorting to unsafe, box syntax, or using the vec hack.\r\n\r\nI suspect this will come up often as a result, since many people and beginners will attempt to stack allocate a large object only to have it segfault.\r\n\r\nVarious values can be tweaked to make it not segfault in release or debug, in an entirely unintuitive way, which lends the language a less user friendly feeling, along with violating the principle of least surprise in many cases, imho.\r\n\r\n```rust\r\n#![feature(box_syntax)]\r\n\r\nuse std::ops::Index;\r\nuse std::ops::IndexMut;\r\nuse std::boxed::Box;\r\n\r\n// causes problems\r\n//const SIZE: usize = 1300;\r\nconst SIZE: usize = 1255;\r\nconst BOUND: usize = SIZE;\r\npub const ARR_SIZE: usize = SIZE * SIZE * BOUND;\r\n\r\nstruct Arr {\r\n    arr: [[[u8; SIZE]; SIZE]; BOUND]\r\n}\r\n\r\nimpl Arr {\r\n    pub fn create () -> Arr {\r\n        let x = [0u8; SIZE];\r\n        let y = [x; SIZE];\r\n        let z = [y; BOUND];\r\n// won't cause problems in release\r\n//        Arr { arr: [[[1u8; SIZE]; SIZE]; SIZE] }\r\n        Arr { arr: z }\r\n    }\r\n}\r\n\r\nimpl Index<usize> for Arr {\r\n    type Output = [[u8; SIZE]; SIZE];\r\n\r\n    fn index(&self, _index: usize) -> &Self::Output {\r\n        &self.arr[_index]\r\n    }\r\n}\r\n\r\nimpl IndexMut<usize> for Arr {\r\n    fn index_mut(&mut self, _index: usize) -> &mut [[u8; SIZE]; SIZE] {\r\n        &mut self.arr[_index]\r\n    }\r\n}\r\n\r\nfn main() {\r\n// let mut arr = box Arr::create();\r\n    let mut arr = Arr::create();\r\n\r\n    for i in 0..BOUND {\r\n        for j in 0..SIZE {\r\n            for k in 0..SIZE {\r\n                arr[i][j][k] = (i+j+k) as u8;\r\n            }\r\n        }\r\n    }\r\n/*\r\n    for i in 0..SIZE {\r\n        for j in 0..SIZE {\r\n            for k in 0..SIZE {\r\n                println!(\"{}\", arr[i][j][k])\r\n            }\r\n        }\r\n    }\r\n*/\r\n    println!(\"res: {}\", arr[1][0][0]);\r\n    println!(\"res: {}\", arr[1][SIZE-1][SIZE-1]);\r\n    println!(\"res: {}\", arr[1][SIZE-1][SIZE-1]);\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/rust-lang/rust/issues/comments/233384135","html_url":"https://github.com/rust-lang/rust/issues/34877#issuecomment-233384135","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/34877","id":233384135,"user":{"login":"eddyb","id":77424,"avatar_url":"https://avatars.githubusercontent.com/u/77424?v=3","gravatar_id":"","url":"https://api.github.com/users/eddyb","html_url":"https://github.com/eddyb","followers_url":"https://api.github.com/users/eddyb/followers","following_url":"https://api.github.com/users/eddyb/following{/other_user}","gists_url":"https://api.github.com/users/eddyb/gists{/gist_id}","starred_url":"https://api.github.com/users/eddyb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eddyb/subscriptions","organizations_url":"https://api.github.com/users/eddyb/orgs","repos_url":"https://api.github.com/users/eddyb/repos","events_url":"https://api.github.com/users/eddyb/events{/privacy}","received_events_url":"https://api.github.com/users/eddyb/received_events","type":"User","site_admin":false},"created_at":"2016-07-18T16:37:15Z","updated_at":"2016-07-18T16:37:15Z","body":"I can't find a LLVM bug report matching this, although who knows how, if ever, this was reported.\r\ncc @rust-lang/compiler"}}
{"actor":{"display_login":"eddyb"}}