Skip to content

ICE with extern C functions receiving/returning structs by value with f32/f64 members on x86_64 #5874

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
SiegeLord opened this issue Apr 13, 2013 · 5 comments

Comments

@SiegeLord
Copy link
Contributor

Structs that contain f32/f64 and have a total size of <= 128 bytes produce an out of bounds error at src/librustc/middle/trans/cabi_x86_64.rs:259 . Tested with incoming at a9247e0.

Here is a collection of structs that produce an ICE and some that don't. I haven't tested whether the ones that do compile produce correct code.

// rust: task failed at 'index out of bounds: the len is 1 but the index is 1', /home/siege/src/rust2/src/librustc/middle/trans/cabi_x86_64.rs:259
struct f64_1
{
    a : f64,
}

// rust: task failed at 'index out of bounds: the len is 2 but the index is 2', /home/siege/src/rust2/src/librustc/middle/trans/cabi_x86_64.rs:259
struct f64_2
{
    a : f64,
    b : f64
}

// No ICE
struct f64_3
{
    a : f64,
    b : f64,
    c : f64
}

// No ICE
struct f64_4
{
    a : f64,
    b : f64,
    c : f64,
    d : f64
}

// No ICE
struct f64_5
{
    a : f64,
    b : f64,
    c : f64,
    d : f64,
    e : f64
}

// rust: task failed at 'index out of bounds: the len is 1 but the index is 1', /home/siege/src/rust2/src/librustc/middle/trans/cabi_x86_64.rs:259
struct f32_1
{
    a : f32
}

// rust: task failed at 'index out of bounds: the len is 1 but the index is 1', /home/siege/src/rust2/src/librustc/middle/trans/cabi_x86_64.rs:259
struct f32_2
{
    a : f32,
    b : f32
}

// rust: task failed at 'index out of bounds: the len is 2 but the index is 2', /home/siege/src/rust2/src/librustc/middle/trans/cabi_x86_64.rs:259
struct f32_3
{
    a : f32,
    b : f32,
    c : f32
}

// rust: task failed at 'index out of bounds: the len is 2 but the index is 2', /home/siege/src/rust2/src/librustc/middle/trans/cabi_x86_64.rs:259
struct f32_4
{
    a : f32,
    b : f32,
    c : f32,
    d : f32,
}

// No ICE
struct f32_5
{
    a : f32,
    b : f32,
    c : f32,
    d : f32,
    e : f32,
}

type T = f32_1;

extern "C"
{
    fn test1(a : T);
    fn test2() -> T;
}

fn main()
{
}

Here's a representative backtrace, if it's useful:

/usr/local/bin/../lib/librustrt.so(_ZN9rust_task13begin_failureEPKcS1_m+0x4b)[0x7fcb85a20c8b]
/usr/local/bin/../lib/librustrt.so(+0x2aa79)[0x7fcb85a31a79]
/usr/local/bin/../lib/librustrt.so(upcall_fail+0x1a8)[0x7fcb85a22a78]
/usr/local/bin/../lib/libcore-c3ca5d77d81b46c1-0.7-pre.so(+0x10911b)[0x7fcb875f611b]
/usr/local/bin/../lib/libcore-c3ca5d77d81b46c1-0.7-pre.so(+0x4f15e)[0x7fcb8753c15e]
/usr/local/bin/../lib/libcore-c3ca5d77d81b46c1-0.7-pre.so(_ZN8unstable4lang17fail_bounds_check16_6fb13a2fe60974b6_07preE+0x23a)[0x7fcb875454da]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(+0x305e2d)[0x7fcb85f68e2d]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(+0x3066f4)[0x7fcb85f696f4]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(_ZN6middle5trans11cabi_x86_6414__extensions__10meth_3501512compute_info17_63f5244ae590c1b66_07preE+0x11e)[0x7fcb85f698fe]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(+0x309fea)[0x7fcb85f6cfea]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(+0x30b52d)[0x7fcb85f6e52d]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(+0x30b210)[0x7fcb85f6e210]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(_ZN6middle5trans7foreign17trans_foreign_mod17_f7e97aff939386996_07preE+0x11e)[0x7fcb85ee75ee]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(_ZN6middle5trans4base10trans_item17_e83b64764568c7be6_07preE+0x499)[0x7fcb85d7b909]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(_ZN6middle5trans4base9trans_mod17_d740d055c716f9476_07preE+0xa3)[0x7fcb85ee73d3]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(_ZN6middle5trans4base11trans_crate15_4f38ab124cab2e6_07preE+0x13c4)[0x7fcb85f073e4]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(+0x8ddce4)[0x7fcb86540ce4]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(+0x89b8b0)[0x7fcb864fe8b0]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(_ZN6driver6driver12compile_rest15_58068714615f2b6_07preE+0x336a)[0x7fcb864fb90a]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(+0x8ddce4)[0x7fcb86540ce4]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(_ZN6driver6driver12compile_upto17_3ccd839185751c4f6_07preE+0x108)[0x7fcb864feac8]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(_ZN6driver6driver13compile_input17_7bc345e59d22cba06_07preE+0xca)[0x7fcb864fef0a]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(_ZN12run_compiler16_aa88c3dc13843746_07preE+0x20a0)[0x7fcb86531720]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(+0x8db691)[0x7fcb8653e691]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(+0x8d7bba)[0x7fcb8653abba]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(+0x8ddce4)[0x7fcb86540ce4]
/usr/local/bin/../lib/libcore-c3ca5d77d81b46c1-0.7-pre.so(+0xd0fbf)[0x7fcb875bdfbf]
/usr/local/bin/../lib/libcore-c3ca5d77d81b46c1-0.7-pre.so(+0x152264)[0x7fcb8763f264]
/usr/local/bin/../lib/librustrt.so(_Z18task_start_wrapperP10spawn_args+0x24)[0x7fcb85a214d4]
@jdm
Copy link
Contributor

jdm commented Apr 14, 2013

Could you run rustc under gdb, set a breakpoint in rust_task_fail and paste the backtrace here?

@SiegeLord
Copy link
Contributor Author

Sure, here it is. I'm not sure how to compile rustc so I get the line numbers, so there are very few of those present.

#0  rust_task_fail (task=0x7fffec208970, expr=0x7fffe473b4d0 "index out of bounds: the len is 1 but the index is 1", 
    file=0x7ffff6923c20 <str34878> "/home/siege/src/rust2/src/librustc/middle/trans/cabi_x86_64.rs", line=259)
    at /home/siege/src/rust2/src/rt/rust_task.cpp:86
#1  0x00007ffff5e0bb69 in __morestack () from /usr/local/bin/../lib/librustrt.so
#2  0x00007ffff5dfcb68 in call_on_c_stack (fn_ptr=0x7ffff5dfc4a0 <upcall_s_fail(s_fail_args*)>, args=0x7fffe420fe90, this=0x7fffec208970)
    at /home/siege/src/rust2/src/rt/rust_task.h:470
#3  call_upcall_on_c_stack (fn_ptr=0x7ffff5dfc4a0 <upcall_s_fail(s_fail_args*)>, args=0x7fffe420fe90, task=<optimized out>)
    at /home/siege/src/rust2/src/rt/rust_upcall.cpp:45
#4  upcall_fail (expr=<optimized out>, file=0x7ffff6923c20 <str34878> "/home/siege/src/rust2/src/librustc/middle/trans/cabi_x86_64.rs", 
    line=259) at /home/siege/src/rust2/src/rt/rust_upcall.cpp:128
#5  0x00007ffff79d011b in sys::begin_unwind_::_9873ff47b9982218::_07pre () from /usr/local/bin/../lib/libcore-c3ca5d77d81b46c1-0.7-pre.so
#6  0x00007ffff791615e in unstable::lang::fail_::_9873ff47b9982218::_07pre ()
   from /usr/local/bin/../lib/libcore-c3ca5d77d81b46c1-0.7-pre.so
#7  0x00007ffff791f4da in unstable::lang::fail_bounds_check::_6fb13a2fe60974b::_07pre ()
   from /usr/local/bin/../lib/libcore-c3ca5d77d81b46c1-0.7-pre.so
#8  0x00007ffff6342c7d in middle::trans::cabi_x86_64::x86_64_tys::x86_64_ty::_cba3ba6a69dd212b::_07pre ()
   from /usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so
#9  0x00007ffff6343544 in middle::trans::cabi_x86_64::x86_64_tys::anon::expr_fn_34991 ()
   from /usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so
#10 0x00007ffff634374e in middle::trans::cabi_x86_64::__extensions__::meth_35015::compute_info::_63f5244ae590c1b6::_07pre ()
   from /usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so
#11 0x00007ffff6346e3a in middle::trans::foreign::shim_types::_4ddc0485e8ab7a0::_07pre ()
   from /usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so
#12 0x00007ffff634837d in middle::trans::foreign::trans_foreign_mod::build_foreign_fn::_cadbd7f24e409e5f::_07pre ()
   from /usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so
#13 0x00007ffff6348060 in middle::trans::foreign::trans_foreign_mod::anon::expr_fn_35155 ()
   from /usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so
#14 0x00007ffff62c146e in middle::trans::foreign::trans_foreign_mod::_f7e97aff93938699::_07pre ()
   from /usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so
#15 0x00007ffff6155909 in middle::trans::base::trans_item::_e83b64764568c7be::_07pre ()
   from /usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so
#16 0x00007ffff62c1253 in middle::trans::base::trans_mod::_d740d055c716f947::_07pre ()
   from /usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so
#17 0x00007ffff62e1264 in middle::trans::base::trans_crate::_4f38ab124cab2e::_07pre ()
   from /usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so
#18 0x00007ffff691ade4 in __morestack () from /usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so
#19 0x00007ffff68d8c10 in driver::driver::compile_rest::anon::expr_fn_81655 ()
   from /usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so
#20 0x00007ffff68d5c6a in driver::driver::compile_rest::_58068714615f2b::_07pre ()
   from /usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so
#21 0x00007ffff691ade4 in __morestack () from /usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so
#22 0x00007ffff68d8e28 in driver::driver::compile_upto::_3ccd839185751c4f::_07pre ()
   from /usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so
#23 0x00007ffff68d926a in driver::driver::compile_input::_7bc345e59d22cba0::_07pre ()
   from /usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so
#24 0x00007ffff690b820 in run_compiler::_aa88c3dc1384374::_07pre () from /usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so
#25 0x00007ffff6918791 in monitor::anon::expr_fn_83847 () from /usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so
#26 0x00007ffff6914cba in task::__extensions__::try_83368::anon::expr_fn_83631 ()
   from /usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so
#27 0x00007ffff691ade4 in __morestack () from /usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so
#28 0x00007ffff7997fbf in task::spawn::spawn_raw::make_child_wrapper::anon::expr_fn_12061 ()
   from /usr/local/bin/../lib/libcore-c3ca5d77d81b46c1-0.7-pre.so
#29 0x00007ffff7a19264 in __morestack () from /usr/local/bin/../lib/libcore-c3ca5d77d81b46c1-0.7-pre.so
#30 0x00007ffff5dfb5c4 in task_start_wrapper (a=0x7fffec2097b0) at /home/siege/src/rust2/src/rt/rust_task.cpp:162
#31 0x0000000000000000 in ?? ()

@yichoi
Copy link
Contributor

yichoi commented Jun 26, 2013

at efd1438, no ICE but produce below messages

[jet@~/rust_latest/build] rustc test4.rs
error: linking with `cc` failed with code 1
note: cc arguments: -L/usr/local/lib/rustc/x86_64-unknown-linux-gnu/lib -m64 -o test4 test4.o -L/usr/local/lib/rustc/x86_64-unknown-linux-gnu/lib -lstd-6c65cf4b443341b1-0.7-pre -lrustrt -lrt -lpthread -lrt -ldl -lm -lmorestack -lrustrt -Wl,-rpath,$ORIGIN/../../../../usr/local/lib/rustc/x86_64-unknown-linux-gnu/lib -Wl,-rpath,/usr/local/lib/rustc/x86_64-unknown-linux-gnu/lib
note: test4.o: In function `test1__c_stack_shim':
test4.rc:(.text+0xb2): undefined reference to `test1'
test4.o: In function `test2__c_stack_shim':
test4.rc:(.text+0x16a): undefined reference to `test2'
collect2: error: ld returned 1 exit status

@jdm
Copy link
Contributor

jdm commented Jun 26, 2013

Sounds like it's no longer valid, in that case.

@jdm jdm closed this as completed Jun 26, 2013
@SiegeLord
Copy link
Contributor Author

It doesn't ICE, but it does generate wrong code. I submitted a new issue: #7415

flip1995 added a commit to flip1995/rust that referenced this issue Aug 11, 2020
Make the docs clearer for new contributors

It confused me before, so I made it extra obvious that you need to run
a script to set up your toolchain before you can build Clippy.

I also added a note so that new contributors aren't confused when
Clippy doesn't build as a result of a change in rustc's internals.

changelog: make `CONTRIBUTING.md` clearer for new contributors
flip1995 pushed a commit to flip1995/rust that referenced this issue Aug 11, 2020
Rollup of 5 pull requests

Successful merges:

 - rust-lang#5825 (Add the new lint `same_item_push`)
 - rust-lang#5869 (New lint against `Self` as an arbitrary self type)
 - rust-lang#5870 (enable #[allow(clippy::unsafe_derive_deserialize)])
 - rust-lang#5871 (Lint .min(x).max(y) with x < y)
 - rust-lang#5874 (Make the docs clearer for new contributors)

Failed merges:

r? @ghost

changelog: rollup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants