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

Std support #146

Open
bjorn3 opened this Issue Nov 13, 2018 · 27 comments

Comments

2 participants
@bjorn3
Copy link
Owner

bjorn3 commented Nov 13, 2018

Unimplemented stuff

     14 Drop for trait object
      1 load_value_pair TyLayout { ty: alloc_crate::boxed::Box<dyn alloc_crate::boxed::FnBox<(), Output=()>>, details: LayoutDetails { variants: Single { index: 0 }, fields: Arbitrary { offsets: [Size { raw: 0 }], memory_index: [0] }, abi: ScalarPair(Scalar { value: Pointer, valid_range: 1..=18446744073709551615 }, Scalar { value: Pointer, valid_range: 1..=18446744073709551615 }), align: Align { abi_pow2: 3, pref_pow2: 3 }, size: Size { raw: 16 } } }
      1 Non scalars are not yet supported for "C" abi (core::option::Option<unsafe extern "C" fn(*mut libc::c_void)>) is_return: false
Edit: hiding this because it is fixed in 1717cc4
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: IncompatibleDeclaration("__rdl_alloc")', libcore/result.rs:1009:5
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::_print
             at libstd/sys_common/backtrace.rs:71
   2: std::panicking::default_hook::{{closure}}
             at libstd/sys_common/backtrace.rs:59
             at libstd/panicking.rs:211
   3: std::panicking::default_hook
             at libstd/panicking.rs:227
   4: rustc::util::common::panic_hook
   5: std::panicking::rust_panic_with_hook
             at libstd/panicking.rs:480
   6: std::panicking::continue_panic_fmt
             at libstd/panicking.rs:390
   7: rust_begin_unwind
             at libstd/panicking.rs:325
   8: core::panicking::panic_fmt
             at libcore/panicking.rs:77
   9: core::result::unwrap_failed
             at /rustc/65204a97d4876b897df0a70c0b9248b57e2bf057/src/libcore/macros.rs:26
  10: <core::result::Result<T, E>>::unwrap
             at /rustc/65204a97d4876b897df0a70c0b9248b57e2bf057/src/libcore/result.rs:808
  11: rustc_codegen_cranelift::allocator::codegen
             at src/allocator.rs:52
  12: rustc_codegen_cranelift::codegen_mono_items
             at src/lib.rs:498
  13: <rustc_codegen_cranelift::CraneliftCodegenBackend as rustc_codegen_utils::codegen_backend::CodegenBackend>::codegen_crate
             at src/lib.rs:395

Edit2: Patched out variadic functions

@bjorn3 bjorn3 added the enhancement label Nov 13, 2018

@bjorn3 bjorn3 added this to the MVP milestone Nov 16, 2018

@bjorn3 bjorn3 removed the enhancement label Nov 16, 2018

@bjorn3

This comment has been minimized.

Copy link
Owner

bjorn3 commented Dec 18, 2018

This is now blocked on #209.

@bjorn3 bjorn3 pinned this issue Dec 18, 2018

@bjorn3 bjorn3 unpinned this issue Dec 18, 2018

@bjorn3 bjorn3 pinned this issue Dec 19, 2018

@bjorn3

This comment has been minimized.

Copy link
Owner

bjorn3 commented Dec 20, 2018

#209 has been fixed. alloc_example as of 468a959 from the wip_fix_libstd branch now compiles and links, but it segfaults during libstd initialization.

@bjorn3

This comment has been minimized.

Copy link
Owner

bjorn3 commented Dec 20, 2018

The segfault happens after returning from _$LT$std..thread..local..LocalKey$LT$T$GT$$GT$::try_with::h4fd75c76394cfdb9 it should return to _$LT$std..thread..local..LocalKey$LT$T$GT$$GT$::with::heb211e3cfd701dc4, but it returns to an unknown symbol.

Backtrace at the first inst ([...] means a lot of ?? frames combined with some frames with the name of the function):

#0  0x00005613b1839100 in _$LT$std..thread..local..LocalKey$LT$T$GT$$GT$::try_with::h4fd75c76394cfdb9 ()
#1  0x00005613b183e535 in _$LT$std..thread..local..LocalKey$LT$T$GT$$GT$::with::heb211e3cfd701dc4 ()
[...]

Backtrace at the second inst:

#0  0x00005613b1839102 in _$LT$std..thread..local..LocalKey$LT$T$GT$$GT$::try_with::h4fd75c76394cfdb9 ()
#1  0x00007ffc6b5af730 in ?? ()
#2  0x00005613b183e535 in _$LT$std..thread..local..LocalKey$LT$T$GT$$GT$::with::heb211e3cfd701dc4 ()
[...]

Backtrace at the fourth inst:

#0  0x00005613b183910c in _$LT$std..thread..local..LocalKey$LT$T$GT$$GT$::try_with::h4fd75c76394cfdb9 ()
#1  0x00005613b39ac0a0 in ?? ()
#2  0x00005613b39ac0a0 in ?? ()
[...]
clif and asm of `try_with`
function u0:0(i64, i64, i64) system_v {
    ss0 = explicit_slot 0
    ss1 = explicit_slot 8
    ss2 = explicit_slot 8
    ss3 = explicit_slot 8
    ss4 = explicit_slot 0
    ss5 = explicit_slot 0
    ss6 = explicit_slot 0
    ss7 = explicit_slot 0
    ss8 = explicit_slot 0
    ss9 = explicit_slot 0
    ss10 = explicit_slot 0
    ss11 = explicit_slot 8
    ss12 = explicit_slot 8
    ss13 = explicit_slot 8
    sig0 = (i64) system_v
    sig1 = (i64, i64, i64) system_v
    sig2 = (i64, i64, i64) system_v
    sig3 = (i64, i64) system_v
    sig4 = (i64, i64) system_v
    sig5 = (i64) -> i64 system_v
    sig6 = (i64) -> i64 system_v
    sig7 = (i64, i64) system_v
    sig8 = (i64, i64) system_v
    sig9 = (i64, i64) system_v
    sig10 = (i64, i64) system_v
    sig11 = (i64, i64) -> i64 system_v
    sig12 = (i64, i64) -> i64 system_v
    sig13 = (i64, i64) system_v
    sig14 = (i64, i64) system_v
    fn0 = colocated u0:3591 sig2
    fn1 = u0:3592 sig4
    fn2 = u0:2722 sig6
    fn3 = u0:233 sig8
    fn4 = u0:3999 sig10
    fn5 = u0:3594 sig12
    fn6 = u0:4306 sig14
    jt0 = jump_table [ebb6, ebb7]
    jt1 = jump_table [ebb12, ebb13]

ebb0(v0: i64, v1: i64, v2: i64):
    v17 -> v1
    v46 -> v1
    v37 -> v46
    nop 
; ssa {_20: NOT_SSA, _3: (empty), _25: (empty), _11: (empty), _0: NOT_SSA, _1: (empty), _23: (empty), _10: NOT_SSA, _18: (empty), _8: NOT_SSA, _5: NOT_SSA, _4: NOT_SSA, _6: NOT_SSA, _26: (empty), _21: (empty), _2: NOT_SSA, _7: (empty), _12: (empty), _22: (empty), _13: NOT_SSA, _17: NOT_SSA, _15: NOT_SSA, _19: (empty), _9: NOT_SSA, _14: NOT_SSA, _16: NOT_SSA, _24: NOT_SSA}
; pass _1: &thread::local::LocalKey<core::cell::RefCell<core::option::Option<sys_common::thread_info::ThreadInfo>>> ByVal(types::I64)
; pass _2: [closure@sysroot_src/src/libstd/sys_common/thread_info.rs:47:22: 47:55] ByRef
    v3 = stack_addr.i64 ss0
    v4 = stack_addr.i64 ss1
    v5 = stack_addr.i64 ss2
    v6 = stack_addr.i64 ss3
    v7 = stack_addr.i64 ss4
    v8 = stack_addr.i64 ss5
    v9 = stack_addr.i64 ss6
    v10 = stack_addr.i64 ss7
    v11 = stack_addr.i64 ss8
    v12 = stack_addr.i64 ss9
    v13 = stack_addr.i64 ss10
    v14 = stack_addr.i64 ss11
    v15 = stack_addr.i64 ss12
    v16 = stack_addr.i64 ss13
    jump ebb1

ebb1:
    nop 
; _7 = ((*_1).0: unsafe fn() -> core::option::Option<&core::cell::UnsafeCell<core::option::Option<T>>>)
    v18 = load.i64 v17
; 
; _6 = move _7()
    call_indirect sig0, v18(v6)
    jump ebb2

ebb2:
    nop 
; (_8.0: ()) = move _9
; 
; _5 = const <core::option::Option<T>>::ok_or(move _6, move _8)
    call fn0(v5, v6, v7)
    jump ebb3

ebb3:
    nop 
; 
; _4 = const core::ops::Try::into_result(move _5)
    call fn1(v4, v5)
    jump ebb4

ebb4:
    nop 
; _12 = discriminant(_4)
    v19 = load.i64 v4
    v20 = icmp_imm eq v19, 0
    v21 = iconst.i64 1
    v22 = iconst.i64 0
    v23 = select v20, v21, v22
; 
; switchInt(move _12)
    v24 = icmp_imm uge v23, 0
    brnz v24, ebb17
    jump ebb5

ebb17:
    v25 = iadd_imm.i64 v23, 0
    br_table v25, ebb5, jt0

ebb5:
    nop 
; 
; unreachable
    trap user65535

ebb6:
    nop 
; _11 = ((_4 as Ok).0: &core::cell::UnsafeCell<core::option::Option<T>>)
    v26 = load.i64 v4
    v47 -> v26
    v38 -> v47
; _3 = _11
; _16 = move _2
; _21 = _3
; 
; _20 = const <core::cell::UnsafeCell<T>>::get(move _21)
    v27 = call fn2(v26)
    store v27, v15
    jump ebb11

ebb7:
    nop 
; _10 = move ((_4 as Err).0: thread::local::AccessError)
; _14 = move _10
; 
; _13 = const core::convert::From::from(move _14)
    call fn3(v10, v11)
    jump ebb8

ebb8:
    nop 
; 
; _0 = const core::ops::Try::from_error(move _13)
    call fn4(v0, v10)
    jump ebb9

ebb9:
    nop 
; 
; drop(_2)
    jump ebb10

ebb10:
    nop 
; 
; return
    return

ebb11:
    nop 
; _23 = discriminant((*_20))
    v28 = load.i64 v15
    v29 = iadd_imm v28, 8
    v30 = load.i64 v29
    v31 = icmp_imm eq v30, 3
    v32 = iconst.i64 0
    v33 = iconst.i64 1
    v34 = select v31, v32, v33
; 
; switchInt(move _23)
    v35 = icmp_imm uge v34, 0
    brnz v35, ebb18
    jump ebb5

ebb18:
    v36 = iadd_imm.i64 v34, 0
    br_table v36, ebb5, jt1

ebb12:
    nop 
; _25 = _1
; _26 = _3
; 
; _24 = const <thread::local::LocalKey<T>>::init(move _25, move _26)
    v39 = call fn5(v37, v38)
    store v39, v16
    jump ebb15

ebb13:
    nop 
; _22 = &(((*_20) as Some).0: T)
    v40 = load.i64 v15
; _19 = _22
; 
; goto
    jump ebb14(v40)

ebb14(v41: i64):
    nop 
; _18 = _19
; (_17.0: &T) = move _18
    store v41, v14
; 
; _15 = const core::ops::FnOnce::call_once(move _16, move _17)
    v42 = load.i64 v14
    call fn6(v13, v42)
    jump ebb16

ebb15:
    nop 
; _19 = _24
    v43 = load.i64 v16
; 
; goto
    jump ebb14(v43)

ebb16:
    nop 
; ((_0 as Ok).0: R) = move _15
    v44 = iadd_imm.i64 v0, 1
; discriminant(_0) = 0
    v45 = iconst.i8 0
    store v45, v0
; 
; goto
    jump ebb10
}
0000000000023200 <_ZN46_$LT$std..thread..local..LocalKey$LT$T$GT$$GT$8try_with17h36cfa393b9d2739bE>:
   23200:       40 55                   rex push %rbp
   23202:       48 89 e5                mov    %rsp,%rbp
   23205:       48 81 ec a0 00 00 00    sub    $0xa0,%rsp
   2320c:       48 89 bc 24 68 00 00    mov    %rdi,0x68(%rsp)
   23213:       00 
   23214:       48 89 b4 24 60 00 00    mov    %rsi,0x60(%rsp)
   2321b:       00 
   2321c:       48 8d 84 24 00 00 00    lea    0x0(%rsp),%rax
   23223:       00 
   23224:       48 8d 84 24 98 00 00    lea    0x98(%rsp),%rax
   2322b:       00 
   2322c:       48 89 84 24 58 00 00    mov    %rax,0x58(%rsp)
   23233:       00 
   23234:       48 8d 84 24 90 00 00    lea    0x90(%rsp),%rax
   2323b:       00 
   2323c:       48 89 84 24 50 00 00    mov    %rax,0x50(%rsp)
   23243:       00 
   23244:       48 8d 84 24 88 00 00    lea    0x88(%rsp),%rax
   2324b:       00 
   2324c:       48 89 84 24 48 00 00    mov    %rax,0x48(%rsp)
   23253:       00 
   23254:       48 8d 84 24 00 00 00    lea    0x0(%rsp),%rax
   2325b:       00 
   2325c:       48 89 84 24 40 00 00    mov    %rax,0x40(%rsp)
   23263:       00 
   23264:       48 8d 84 24 00 00 00    lea    0x0(%rsp),%rax
   2326b:       00 
   2326c:       48 8d 84 24 00 00 00    lea    0x0(%rsp),%rax
   23273:       00 
   23274:       48 8d 84 24 00 00 00    lea    0x0(%rsp),%rax
   2327b:       00 
   2327c:       48 89 84 24 38 00 00    mov    %rax,0x38(%rsp)
   23283:       00 
   23284:       48 8d 84 24 00 00 00    lea    0x0(%rsp),%rax
   2328b:       00 
   2328c:       48 89 84 24 30 00 00    mov    %rax,0x30(%rsp)
   23293:       00 
   23294:       48 8d 84 24 00 00 00    lea    0x0(%rsp),%rax
   2329b:       00 
   2329c:       48 8d 84 24 00 00 00    lea    0x0(%rsp),%rax
   232a3:       00 
   232a4:       48 89 84 24 28 00 00    mov    %rax,0x28(%rsp)
   232ab:       00 
   232ac:       48 8d 84 24 80 00 00    lea    0x80(%rsp),%rax
   232b3:       00 
   232b4:       48 89 84 24 20 00 00    mov    %rax,0x20(%rsp)
   232bb:       00 
   232bc:       48 8d 84 24 78 00 00    lea    0x78(%rsp),%rax
   232c3:       00 
   232c4:       48 89 84 24 18 00 00    mov    %rax,0x18(%rsp)
   232cb:       00 
   232cc:       48 8d 84 24 70 00 00    lea    0x70(%rsp),%rax
   232d3:       00 
   232d4:       48 89 84 24 10 00 00    mov    %rax,0x10(%rsp)
   232db:       00 
   232dc:       48 8b 84 24 60 00 00    mov    0x60(%rsp),%rax
   232e3:       00 
   232e4:       48 8b 00                mov    (%rax),%rax
   232e7:       48 8b 8c 24 48 00 00    mov    0x48(%rsp),%rcx
   232ee:       00 
   232ef:       48 89 cf                mov    %rcx,%rdi
   232f2:       40 ff d0                rex callq *%rax
   232f5:       48 8b 84 24 50 00 00    mov    0x50(%rsp),%rax
   232fc:       00 
   232fd:       48 8b 8c 24 48 00 00    mov    0x48(%rsp),%rcx
   23304:       00 
   23305:       48 8b 94 24 40 00 00    mov    0x40(%rsp),%rdx
   2330c:       00 
   2330d:       48 89 c7                mov    %rax,%rdi
   23310:       48 89 ce                mov    %rcx,%rsi
   23313:       e8 f8 01 00 00          callq  23510 <_ZN38_$LT$core..option..Option$LT$T$GT$$GT$5ok_or17hc08dcc56df316dd4E>
   23318:       48 8b 84 24 58 00 00    mov    0x58(%rsp),%rax
   2331f:       00 
   23320:       48 8b 8c 24 50 00 00    mov    0x50(%rsp),%rcx
   23327:       00 
   23328:       48 89 c7                mov    %rax,%rdi
   2332b:       48 89 ce                mov    %rcx,%rsi
   2332e:       e8 0d 03 00 00          callq  23640 <_ZN78_$LT$core..result..Result$LT$T$C$$u20$E$GT$$u20$as$u20$core..ops..try..Try$GT$11into_result17h020ad5f0907363fdE>
   23333:       48 8b 84 24 58 00 00    mov    0x58(%rsp),%rax
   2333a:       00 
   2333b:       48 8b 00                mov    (%rax),%rax
   2333e:       48 83 f8 00             cmp    $0x0,%rax
   23342:       0f 94 c0                sete   %al
   23345:       40 b9 01 00 00 00       rex mov $0x1,%ecx
   2334b:       40 ba 00 00 00 00       rex mov $0x0,%edx
   23351:       40 84 c0                test   %al,%al
   23354:       75 06                   jne    2335c <_ZN46_$LT$std..thread..local..LocalKey$LT$T$GT$$GT$8try_with17h36cfa393b9d2739bE+0x15c>
   23356:       48 89 d0                mov    %rdx,%rax
   23359:       48 89 c1                mov    %rax,%rcx
   2335c:       48 83 f9 00             cmp    $0x0,%rcx
   23360:       0f 93 c0                setae  %al
   23363:       40 84 c0                test   %al,%al
   23366:       75 03                   jne    2336b <_ZN46_$LT$std..thread..local..LocalKey$LT$T$GT$$GT$8try_with17h36cfa393b9d2739bE+0x16b>
   23368:       40 eb 21                rex jmp 2338c <_ZN46_$LT$std..thread..local..LocalKey$LT$T$GT$$GT$8try_with17h36cfa393b9d2739bE+0x18c>
   2336b:       48 83 c1 00             add    $0x0,%rcx
   2336f:       48 83 f9 02             cmp    $0x2,%rcx
   23373:       0f 93 c0                setae  %al
   23376:       40 84 c0                test   %al,%al
   23379:       75 11                   jne    2338c <_ZN46_$LT$std..thread..local..LocalKey$LT$T$GT$$GT$8try_with17h36cfa393b9d2739bE+0x18c>
   2337b:       48 8d 05 79 01 00 00    lea    0x179(%rip),%rax        # 234fb <_ZN46_$LT$std..thread..local..LocalKey$LT$T$GT$$GT$8try_with17h36cfa393b9d2739bE+0x2fb>
   23382:       48 63 0c 88             movslq (%rax,%rcx,4),%rcx
   23386:       48 01 c8                add    %rcx,%rax
   23389:       40 ff e0                rex jmpq *%rax
   2338c:       0f 0b                   ud2    
   2338e:       48 8b 84 24 58 00 00    mov    0x58(%rsp),%rax
   23395:       00 
   23396:       48 8b 00                mov    (%rax),%rax
   23399:       48 89 84 24 08 00 00    mov    %rax,0x8(%rsp)
   233a0:       00 
   233a1:       48 8b 84 24 08 00 00    mov    0x8(%rsp),%rax
   233a8:       00 
   233a9:       48 89 c7                mov    %rax,%rdi
   233ac:       e8 7f 83 ff ff          callq  1b730 <_ZN40_$LT$core..cell..UnsafeCell$LT$T$GT$$GT$3get17hdeb583042ffbf290E>
   233b1:       48 8b 8c 24 18 00 00    mov    0x18(%rsp),%rcx
   233b8:       00 
   233b9:       48 89 01                mov    %rax,(%rcx)
   233bc:       40 eb 40                rex jmp 233ff <_ZN46_$LT$std..thread..local..LocalKey$LT$T$GT$$GT$8try_with17h36cfa393b9d2739bE+0x1ff>
   233bf:       48 8b 84 24 38 00 00    mov    0x38(%rsp),%rax
   233c6:       00 
   233c7:       48 8b 8c 24 30 00 00    mov    0x30(%rsp),%rcx
   233ce:       00 
   233cf:       48 89 c7                mov    %rax,%rdi
   233d2:       48 89 ce                mov    %rcx,%rsi
   233d5:       e8 26 4c ff ff          callq  18000 <_ZN50_$LT$T$u20$as$u20$core..convert..From$LT$T$GT$$GT$4from17h9bd35ba97d141524E>
   233da:       48 8b 84 24 68 00 00    mov    0x68(%rsp),%rax
   233e1:       00 
   233e2:       48 8b 8c 24 38 00 00    mov    0x38(%rsp),%rcx
   233e9:       00 
   233ea:       48 89 c7                mov    %rax,%rdi
   233ed:       48 89 ce                mov    %rcx,%rsi
   233f0:       e8 1b 4c ff ff          callq  18010 <_ZN78_$LT$core..result..Result$LT$T$C$$u20$E$GT$$u20$as$u20$core..ops..try..Try$GT$10from_error17h39d75f165c72b959E>
   233f5:       48 81 c4 a0 00 00 00    add    $0xa0,%rsp
   233fc:       40 5d                   rex pop %rbp
   233fe:       c3                      retq   
   233ff:       48 8b 84 24 18 00 00    mov    0x18(%rsp),%rax
   23406:       00 
   23407:       48 8b 00                mov    (%rax),%rax
   2340a:       48 83 c0 08             add    $0x8,%rax
   2340e:       48 8b 00                mov    (%rax),%rax
   23411:       48 83 f8 03             cmp    $0x3,%rax
   23415:       0f 94 c0                sete   %al
   23418:       40 b9 00 00 00 00       rex mov $0x0,%ecx
   2341e:       40 ba 01 00 00 00       rex mov $0x1,%edx
   23424:       40 84 c0                test   %al,%al
   23427:       75 06                   jne    2342f <_ZN46_$LT$std..thread..local..LocalKey$LT$T$GT$$GT$8try_with17h36cfa393b9d2739bE+0x22f>
   23429:       48 89 d0                mov    %rdx,%rax
   2342c:       48 89 c1                mov    %rax,%rcx
   2342f:       48 83 f9 00             cmp    $0x0,%rcx
   23433:       0f 93 c0                setae  %al
   23436:       40 84 c0                test   %al,%al
   23439:       75 06                   jne    23441 <_ZN46_$LT$std..thread..local..LocalKey$LT$T$GT$$GT$8try_with17h36cfa393b9d2739bE+0x241>
   2343b:       40 e9 4b ff ff ff       rex jmpq 2338c <_ZN46_$LT$std..thread..local..LocalKey$LT$T$GT$$GT$8try_with17h36cfa393b9d2739bE+0x18c>
   23441:       48 83 c1 00             add    $0x0,%rcx
   23445:       48 83 f9 02             cmp    $0x2,%rcx
   23449:       0f 93 c0                setae  %al
   2344c:       40 84 c0                test   %al,%al
   2344f:       0f 85 37 ff ff ff       jne    2338c <_ZN46_$LT$std..thread..local..LocalKey$LT$T$GT$$GT$8try_with17h36cfa393b9d2739bE+0x18c>
   23455:       48 8d 05 a7 00 00 00    lea    0xa7(%rip),%rax        # 23503 <_ZN46_$LT$std..thread..local..LocalKey$LT$T$GT$$GT$8try_with17h36cfa393b9d2739bE+0x303>
   2345c:       48 63 0c 88             movslq (%rax,%rcx,4),%rcx
   23460:       48 01 c8                add    %rcx,%rax
   23463:       40 ff e0                rex jmpq *%rax
   23466:       48 8b 84 24 60 00 00    mov    0x60(%rsp),%rax
   2346d:       00 
   2346e:       48 8b 8c 24 08 00 00    mov    0x8(%rsp),%rcx
   23475:       00 
   23476:       48 89 c7                mov    %rax,%rdi
   23479:       48 89 ce                mov    %rcx,%rsi
   2347c:       e8 ef 01 00 00          callq  23670 <_ZN46_$LT$std..thread..local..LocalKey$LT$T$GT$$GT$4init17h46b41a9e98f5bef7E>
   23481:       48 8b 8c 24 10 00 00    mov    0x10(%rsp),%rcx
   23488:       00 
   23489:       48 89 01                mov    %rax,(%rcx)
   2348c:       40 eb 37                rex jmp 234c6 <_ZN46_$LT$std..thread..local..LocalKey$LT$T$GT$$GT$8try_with17h36cfa393b9d2739bE+0x2c6>
   2348f:       48 8b 84 24 18 00 00    mov    0x18(%rsp),%rax
   23496:       00 
   23497:       48 8b 00                mov    (%rax),%rax
   2349a:       48 8b 8c 24 20 00 00    mov    0x20(%rsp),%rcx
   234a1:       00 
   234a2:       48 89 01                mov    %rax,(%rcx)
   234a5:       48 8b 84 24 20 00 00    mov    0x20(%rsp),%rax
   234ac:       00 
   234ad:       48 8b 00                mov    (%rax),%rax
   234b0:       48 8b 8c 24 28 00 00    mov    0x28(%rsp),%rcx
   234b7:       00 
   234b8:       48 89 cf                mov    %rcx,%rdi
   234bb:       48 89 c6                mov    %rax,%rsi
   234be:       e8 2d d5 fe ff          callq  109f0 <_ZN3std10sys_common11thread_info3set28_$u7b$$u7b$closure$u7d$$u7d$17h70f50255323bfa80E>
   234c3:       40 eb 0e                rex jmp 234d4 <_ZN46_$LT$std..thread..local..LocalKey$LT$T$GT$$GT$8try_with17h36cfa393b9d2739bE+0x2d4>
   234c6:       48 8b 84 24 10 00 00    mov    0x10(%rsp),%rax
   234cd:       00 
   234ce:       48 8b 00                mov    (%rax),%rax
   234d1:       40 eb c6                rex jmp 2349a <_ZN46_$LT$std..thread..local..LocalKey$LT$T$GT$$GT$8try_with17h36cfa393b9d2739bE+0x29a>
   234d4:       48 8b 84 24 68 00 00    mov    0x68(%rsp),%rax
   234db:       00 
   234dc:       48 83 c0 01             add    $0x1,%rax
   234e0:       40 b8 00 00 00 00       rex mov $0x0,%eax
   234e6:       40 0f b6 c0             movzbl %al,%eax
   234ea:       48 8b 8c 24 68 00 00    mov    0x68(%rsp),%rcx
   234f1:       00 
   234f2:       40 88 01                mov    %al,(%rcx)
   234f5:       40 e9 fa fe ff ff       rex jmpq 233f5 <_ZN46_$LT$std..thread..local..LocalKey$LT$T$GT$$GT$8try_with17h36cfa393b9d2739bE+0x1f5>
   234fb:       93                      xchg   %eax,%ebx
   234fc:       fe                      (bad)  
   234fd:       ff                      (bad)  
   234fe:       ff c4                   inc    %esp
   23500:       fe                      (bad)  
   23501:       ff                      (bad)  
   23502:       ff 63 ff                jmpq   *-0x1(%rbx)
   23505:       ff                      (bad)  
   23506:       ff 8c ff ff ff 0f 1f    decl   0x1f0fffff(%rdi,%rdi,8)
   2350d:       44 00 00                add    %r8b,(%rax)

cc @sunfishcode (I believe this is a miscompilation from cranelift)

@bjorn3

This comment has been minimized.

Copy link
Owner

bjorn3 commented Dec 21, 2018

One thing I noticed is that cranelift emits a rex prefix for the push rbp, while gcc doesn't. (Changing it to nop doesn't fix the crash though)

@bjorn3

This comment has been minimized.

Copy link
Owner

bjorn3 commented Dec 21, 2018

Every single function created by cranelift has the backtrace behavior described above:

$ gdb target/out/mini_core_hello_world # a non crashing program
(gdb) break main
Breakpoint 1 at 0x1c40
(gdb) run
Starting program: /home/bjorn/Documenten/rustc_codegen_cranelift/target/out/mini_core_hello_world 

Breakpoint 1, 0x0000555555555c40 in main ()
(gdb) disassemble 
Dump of assembler code for function main:
=> 0x0000555555555c40 <+0>:     rex push %rbp
   0x0000555555555c42 <+2>:     mov    %rsp,%rbp
   0x0000555555555c45 <+5>:     lea    -0xf3c(%rip),%rax        # 0x555555554d10 <_ZN21mini_core_hello_world4main17he1655d58f9d91204E>
   0x0000555555555c4c <+12>:    mov    %rsi,%rdx
   0x0000555555555c4f <+15>:    mov    %rdi,%rsi
   0x0000555555555c52 <+18>:    mov    %rax,%rdi
   0x0000555555555c55 <+21>:    callq  0x555555554b10 <_ZN21mini_core_hello_world5start17h1e715bf6fab28115E>
   0x0000555555555c5a <+26>:    rex pop %rbp
   0x0000555555555c5c <+28>:    retq   
End of assembler dump.
(gdb) si 7
0x0000555555554b10 in mini_core_hello_world::start::h1e715bf6fab28115 ()
(gdb) disassemble 
Dump of assembler code for function _ZN21mini_core_hello_world5start17h1e715bf6fab28115E:
=> 0x0000555555554b10 <+0>:     rex push %rbp
   0x0000555555554b12 <+2>:     mov    %rsp,%rbp
   0x0000555555554b15 <+5>:     sub    $0x20,%rsp
   0x0000555555554b19 <+9>:     lea    0x1c(%rsp),%rax
   0x0000555555554b21 <+17>:    mov    %rax,0x8(%rsp)
   0x0000555555554b29 <+25>:    lea    0x0(%rsp),%rax
   0x0000555555554b31 <+33>:    mov    %rax,0x10(%rsp)
   0x0000555555554b39 <+41>:    rex callq *%rdi
   0x0000555555554b3c <+44>:    mov    0x10(%rsp),%rax
   0x0000555555554b44 <+52>:    mov    %rax,%rdi
   0x0000555555554b47 <+55>:    callq  0x555555554b70 <_ZN63_$LT$$LP$$RP$$u20$as$u20$mini_core_hello_world..Termination$GT$6report17hdb0778df210e78ccE>
   0x0000555555554b4c <+60>:    mov    0x8(%rsp),%rcx
   0x0000555555554b54 <+68>:    rex mov %eax,(%rcx)
   0x0000555555554b57 <+71>:    mov    0x8(%rsp),%rax
   0x0000555555554b5f <+79>:    rex mov (%rax),%eax
   0x0000555555554b62 <+82>:    movslq %eax,%rax
   0x0000555555554b65 <+85>:    add    $0x20,%rsp
   0x0000555555554b69 <+89>:    rex pop %rbp
   0x0000555555554b6b <+91>:    retq   
End of assembler dump.
(gdb) bt
#0  0x0000555555554b10 in mini_core_hello_world::start::h1e715bf6fab28115 ()
#1  0x0000555555555c5a in main ()
(gdb) si
0x0000555555554b12 in mini_core_hello_world::start::h1e715bf6fab28115 ()
(gdb) bt
#0  0x0000555555554b12 in mini_core_hello_world::start::h1e715bf6fab28115 ()
#1  0x00007fffffffdd80 in ?? ()
#2  0x0000555555555c5a in main ()
(gdb) si
0x0000555555554b15 in mini_core_hello_world::start::h1e715bf6fab28115 ()
(gdb) bt
#0  0x0000555555554b15 in mini_core_hello_world::start::h1e715bf6fab28115 ()
#1  0x00007fffffffdd80 in ?? ()
#2  0x0000555555555c5a in main ()
(gdb) si
0x0000555555554b19 in mini_core_hello_world::start::h1e715bf6fab28115 ()
(gdb) bt
#0  0x0000555555554b19 in mini_core_hello_world::start::h1e715bf6fab28115 ()
#1  0x0000000000000000 in ?? ()

I suspect there is a stack alignment problem. (didn't investigate it though)

@bjorn3

This comment has been minimized.

Copy link
Owner

bjorn3 commented Dec 21, 2018

I am almost sure the problem of at least gdb backtraces is stack alignment. While gcc always does sub $(x*16+8), %rsp, cranelift does sub $(x*16), $rsp, which violates the System V abi requirement that the stack is 16 byte aligned. (call pushes 8 bytes, then you need to add another 8 bytes to align the stack again)

Edit: filled CraneStation/cranelift#630

@bjorn3 bjorn3 referenced this issue Dec 21, 2018

Closed

Stack misaligned #630

@sunfishcode

This comment has been minimized.

Copy link
Contributor

sunfishcode commented Dec 21, 2018

The extra rex is harmless, and is an artifact of the way Cranelift's register allocator works. We optimize away many of the rex prefixes with opt-level=best right now, and in the future I expect we'll do something similar to CraneStation/cranelift#552 to avoid generating unnecessary rex prefixes in the first place.

I think the reason why GCC does x*16+8 is that it's doing frame-pointer elimination, so it needs the extra +8 to compensate for the space where the frame pointer would have been pushed. Cranelift currently always pushes the frame pointer, so it doesn't need the extra +8. Can you test whether %rsp is actually misaligned within the body?

@bjorn3

This comment has been minimized.

Copy link
Owner

bjorn3 commented Dec 21, 2018

First: oops meant rustc + llvm not gcc :)

rustc:

0000000000005dc0 <_ZN11simple_main4main17hb13a4a470fc2f2b2E>:
    5dc0:       48 83 ec 38             sub    $0x38,%rsp
    5dc4:       48 8d 05 ed 93 22 00    lea    0x2293ed(%rip),%rax        # 22f1b8 <__JCR_END__+0x8>
    5dcb:       48 8d 0d 46 fe 01 00    lea    0x1fe46(%rip),%rcx        # 25c18 <_fini+0x14>
    5dd2:       31 d2                   xor    %edx,%edx
    5dd4:       41 89 d0                mov    %edx,%r8d
    5dd7:       48 8d 7c 24 08          lea    0x8(%rsp),%rdi
    5ddc:       48 89 c6                mov    %rax,%rsi
    5ddf:       ba 01 00 00 00          mov    $0x1,%edx
    5de4:       e8 37 01 00 00          callq  5f20 <_ZN4core3fmt9Arguments6new_v117h5ae58c641f8553b9E>
    5de9:       48 8d 7c 24 08          lea    0x8(%rsp),%rdi
    5dee:       ff 15 9c af 22 00       callq  *0x22af9c(%rip)        # 230d90 <_GLOBAL_OFFSET_TABLE_+0x310>
    5df4:       48 83 c4 38             add    $0x38,%rsp
    5df8:       c3                      retq   
    5df9:       0f 1f 80 00 00 00 00    nopl   0x0(%rax)

cranelift:

    4120:       40 55                   rex push %rbp
    4122:       48 89 e5                mov    %rsp,%rbp
    4125:       48 81 ec 90 00 00 00    sub    $0x90,%rsp
    412c:       40 b8 00 00 00 00       rex mov $0x0,%eax
    4132:       48 8d 84 24 88 00 00    lea    0x88(%rsp),%rax
    4139:       00 
    413a:       48 89 84 24 70 00 00    mov    %rax,0x70(%rsp)
    4141:       00 
    4142:       48 8d 84 24 80 00 00    lea    0x80(%rsp),%rax
[...]

Second:

(rr) disassemble
[...]
   0x0000561a3dce93f5 <+501>:   add    $0xa0,%rsp
=> 0x0000561a3dce93fc <+508>:   rex pop %rbp
---Type <return> to continue, or q <return> to quit---
   0x0000561a3dce93fe <+510>:   retq   
   0x0000561a3dce93ff <+511>:   mov    0x18(%rsp),%rax
[...]
(rr) info registers
[...]
rbp            0x7ffda0bbacc0   0x7ffda0bbacc0
rsp            0x7ffda0bbacc0   0x7ffda0bbacc0
[...]
(rr) disassemble    
Dump of assembler code for function _ZN46_$LT$std..thread..local..LocalKey$LT$T$GT$$GT$8try_with17h36cfa393b9d2739bE:
   0x0000561a3dce9200 <+0>:     rex push %rbp
   0x0000561a3dce9202 <+2>:     mov    %rsp,%rbp
=> 0x0000561a3dce9205 <+5>:     sub    $0xa0,%rsp
   0x0000561a3dce920c <+12>:    mov    %rdi,0x68(%rsp)
   0x0000561a3dce9214 <+20>:    mov    %rsi,0x60(%rsp)
   0x0000561a3dce921c <+28>:    lea    0x0(%rsp),%rax
   0x0000561a3dce9224 <+36>:    lea    0x98(%rsp),%rax
   0x0000561a3dce922c <+44>:    mov    %rax,0x58(%rsp)
   0x0000561a3dce9234 <+52>:    lea    0x90(%rsp),%rax
   0x0000561a3dce923c <+60>:    mov    %rax,0x50(%rsp)
   0x0000561a3dce9244 <+68>:    lea    0x88(%rsp),%rax
   0x0000561a3dce924c <+76>:    mov    %rax,0x48(%rsp)
   0x0000561a3dce9254 <+84>:    lea    0x0(%rsp),%rax
   0x0000561a3dce925c <+92>:    mov    %rax,0x40(%rsp)
   0x0000561a3dce9264 <+100>:   lea    0x0(%rsp),%rax
   0x0000561a3dce926c <+108>:   lea    0x0(%rsp),%rax
   0x0000561a3dce9274 <+116>:   lea    0x0(%rsp),%rax
   0x0000561a3dce927c <+124>:   mov    %rax,0x38(%rsp)
   0x0000561a3dce9284 <+132>:   lea    0x0(%rsp),%rax
   0x0000561a3dce928c <+140>:   mov    %rax,0x30(%rsp)
   0x0000561a3dce9294 <+148>:   lea    0x0(%rsp),%rax
   0x0000561a3dce929c <+156>:   lea    0x0(%rsp),%rax
   0x0000561a3dce92a4 <+164>:   mov    %rax,0x28(%rsp)
   0x0000561a3dce92ac <+172>:   lea    0x80(%rsp),%rax
   0x0000561a3dce92b4 <+180>:   mov    %rax,0x20(%rsp)
   0x0000561a3dce92bc <+188>:   lea    0x78(%rsp),%rax
   0x0000561a3dce92c4 <+196>:   mov    %rax,0x18(%rsp)
   0x0000561a3dce92cc <+204>:   lea    0x70(%rsp),%rax
   0x0000561a3dce92d4 <+212>:   mov    %rax,0x10(%rsp)
   0x0000561a3dce92dc <+220>:   mov    0x60(%rsp),%rax
   0x0000561a3dce92e4 <+228>:   mov    (%rax),%rax
   0x0000561a3dce92e7 <+231>:   mov    0x48(%rsp),%rcx
   0x0000561a3dce92ef <+239>:   mov    %rcx,%rdi
   0x0000561a3dce92f2 <+242>:   rex callq *%rax
   0x0000561a3dce92f5 <+245>:   mov    0x50(%rsp),%rax
   0x0000561a3dce92fd <+253>:   mov    0x48(%rsp),%rcx
   0x0000561a3dce9305 <+261>:   mov    0x40(%rsp),%rdx
   0x0000561a3dce930d <+269>:   mov    %rax,%rdi
   0x0000561a3dce9310 <+272>:   mov    %rcx,%rsi
   0x0000561a3dce9313 <+275>:   callq  0x561a3dce9510 <_ZN38_$LT$core..option..Option$LT$T$GT$$GT$5ok_or17hc08dcc56df316dd4E>
   0x0000561a3dce9318 <+280>:   mov    0x58(%rsp),%rax
   0x0000561a3dce9320 <+288>:   mov    0x50(%rsp),%rcx
   0x0000561a3dce9328 <+296>:   mov    %rax,%rdi
   0x0000561a3dce932b <+299>:   mov    %rcx,%rsi
   0x0000561a3dce932e <+302>:   callq  0x561a3dce9640 <_ZN78_$LT$core..result..Result$LT$T$C$$u20$E$GT$$u20$as$u20$core..ops..try..Try$GT$11into_result17h020ad5f0907363fdE>
---Type <return> to continue, or q <return> to quit---q
Quit
(rr) bt
#0  0x0000561a3dce9205 in _$LT$std..thread..local..LocalKey$LT$T$GT$$GT$::try_with::h36cfa393b9d2739b ()
#1  0x00007ffda0bbad10 in ?? ()
#2  0x0000561a3dcf1065 in _$LT$std..thread..local..LocalKey$LT$T$GT$$GT$::with::h3a43c45273ccf36f ()
#3  0x0000561a3f47a040 in ?? ()
#4  0x0000000000000005 in ?? ()
#5  0x00007ffda0bbad30 in ?? ()
#6  0x00007ffda0bbad38 in ?? ()
#7  0x00007ffda0bbace0 in ?? ()
#8  0x00007ffda0bbad0f in ?? ()
#9  0x00007ffda0bbacd0 in ?? ()
#10 0x00007ffda0bbac70 in ?? ()
#11 0x00007ffda0bbad80 in ?? ()
#12 0x0000561a3dcf0f75 in std::sys_common::thread_info::set::head7c9f27ff8aec1 ()
#13 0x00007ffda0bbac60 in ?? ()
#14 0x00007ffda0bbaec8 in ?? ()
#15 0x0000000000000000 in ?? ()
(rr) si
0x0000561a3dce920c in _$LT$std..thread..local..LocalKey$LT$T$GT$$GT$::try_with::h36cfa393b9d2739b ()
(rr) info registers 
rbp            0x7ffda0bbacc0   0x7ffda0bbacc0
rsp            0x7ffda0bbac20   0x7ffda0bbac20
[...]

Seems the stack is aligned after all.

@bjorn3

This comment has been minimized.

Copy link
Owner

bjorn3 commented Dec 21, 2018

I am still puzzled by the gdb backtraces though.

@sunfishcode

This comment has been minimized.

Copy link
Contributor

sunfishcode commented Dec 21, 2018

Oh, it's possible that gdb is trying to parse the prologue and getting confused by the rex prefixes. Let me investigate a little more.

@bjorn3

This comment has been minimized.

Copy link
Owner

bjorn3 commented Dec 21, 2018

Let me investigate a little more.

Thanks

@sunfishcode

This comment has been minimized.

Copy link
Contributor

sunfishcode commented Dec 21, 2018

Yes, that looks like it. You can see it in a simple .s file like this:

.globl foo
foo:
       rex push %rbp
       mov    %rsp,%rbp
       sub    $0x20,%rsp
       nop
       add    $0x20,%rsp
       pop %rbp
       retq

gdb has trouble printing back traces in the middle of this function, and removing the rex prefix fixes it.

@sunfishcode

This comment has been minimized.

Copy link
Contributor

sunfishcode commented Dec 21, 2018

It looks like opt_level=best is a workaround, as that enables the shrink pass which eliminates the rex prefix. But that's just a workaound, of course we'll want to fix it so that we always avoid the rex prefix so that backtraces work.

@bjorn3

This comment has been minimized.

Copy link
Owner

bjorn3 commented Dec 21, 2018

It looks like opt_level=best is a workaround

Rebuilding sysroot with -Copt-level=3 right now. Hope it fixes at least gdb backtraces.

@bjorn3

This comment has been minimized.

Copy link
Owner

bjorn3 commented Dec 21, 2018

Yes, it fixes the backtraces 🎉

@bjorn3

This comment has been minimized.

Copy link
Owner

bjorn3 commented Dec 21, 2018

Found the corrupting instruction. I don't know why it does corrupt though.

(rr) backtrace
#0  0x000055e6c58b2866 in std::sys_common::thread_info::THREAD_INFO::__init::h84a096a88e66c68a ()
#1  0x000055e6c58a6581 in _$LT$std..thread..local..LocalKey$LT$T$GT$$GT$::try_with::h72e6de457ec8a4ce ()
#2  0x000055e6c58ab0a6 in _$LT$std..thread..local..LocalKey$LT$T$GT$$GT$::with::hf9d1413c59690409 ()
#3  0x000055e6c58ba11e in std::sys_common::thread_info::set::h9c22d4252436490b ()
#4  0x000055e6c58ba332 in std::rt::lang_start_internal::h1f8bf9c0dec3faf8 ()
#5  0x000055e6c5894742 in std::rt::lang_start::h9f2ee4672fdbaa85 ()
#6  0x000055e6c5894c19 in main ()
(rr) disassemble
Dump of assembler code for function _ZN3std10sys_common11thread_info11THREAD_INFO6__init17h84a096a88e66c68aE:
   0x000055e6c58b27f0 <+0>:  push   %rbp
   0x000055e6c58b27f1 <+1>:  mov    %rsp,%rbp
   0x000055e6c58b27f4 <+4>:  push   %rbx
   0x000055e6c58b27f5 <+5>:  sub    $0x58,%rsp
   0x000055e6c58b27f9 <+9>:  lea    0x20(%rsp),%rax
   0x000055e6c58b2801 <+17>:  lea    0x0(%rsp),%rcx
   0x000055e6c58b2809 <+25>:  lea    0x50(%rsp),%rdx
   0x000055e6c58b2811 <+33>:  lea    0x48(%rsp),%rbx
   0x000055e6c58b2819 <+41>:  mov    $0x2,%esi
   0x000055e6c58b281e <+46>:  mov    %rsi,(%rax)
   0x000055e6c58b2821 <+49>:  mov    (%rax),%rsi
   0x000055e6c58b2824 <+52>:  mov    %rsi,(%rcx)
   0x000055e6c58b2827 <+55>:  mov    0x8(%rax),%rsi
   0x000055e6c58b282b <+59>:  mov    %rsi,0x8(%rcx)
   0x000055e6c58b282f <+63>:  mov    0x10(%rax),%rsi
   0x000055e6c58b2833 <+67>:  mov    %rsi,0x10(%rcx)
   0x000055e6c58b2837 <+71>:  mov    0x18(%rax),%rax
   0x000055e6c58b283b <+75>:  mov    %rax,0x18(%rcx)
   0x000055e6c58b283f <+79>:  mov    $0x0,%eax
   0x000055e6c58b2844 <+84>:  mov    %rax,(%rbx)
   0x000055e6c58b2847 <+87>:  mov    (%rbx),%rax
   0x000055e6c58b284a <+90>:  mov    %rax,(%rdx)
   0x000055e6c58b284d <+93>:  mov    (%rdx),%rax
   0x000055e6c58b2850 <+96>:  mov    %rax,(%rdi)
   0x000055e6c58b2853 <+99>:  mov    (%rcx),%rax
   0x000055e6c58b2856 <+102>:  mov    %rax,0x8(%rdi)
   0x000055e6c58b285a <+106>:  mov    0x8(%rcx),%rax
   0x000055e6c58b285e <+110>:  mov    %rax,0x10(%rdi)
   0x000055e6c58b2862 <+114>:  mov    0x10(%rcx),%rax
=> 0x000055e6c58b2866 <+118>:  mov    %rax,0x18(%rdi)
   0x000055e6c58b286a <+122>:  mov    0x18(%rcx),%rax
   0x000055e6c58b286e <+126>:  mov    %rax,0x20(%rdi)
   0x000055e6c58b2872 <+130>:  add    $0x58,%rsp
   0x000055e6c58b2876 <+134>:  pop    %rbx
   0x000055e6c58b2877 <+135>:  pop    %rbp
   0x000055e6c58b2878 <+136>:  retq   
(rr) si
0x000055e6c58b286a in std::sys_common::thread_info::THREAD_INFO::__init::h84a096a88e66c68a ()
(rr) backtrace
#0  0x000055e6c58b286a in std::sys_common::thread_info::THREAD_INFO::__init::h84a096a88e66c68a ()
#1  0x000055e6c58a6581 in _$LT$std..thread..local..LocalKey$LT$T$GT$$GT$::try_with::h72e6de457ec8a4ce ()
#2  0x000055e6c58ab0a6 in _$LT$std..thread..local..LocalKey$LT$T$GT$$GT$::with::hf9d1413c59690409 ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)
@sunfishcode

This comment has been minimized.

Copy link
Contributor

sunfishcode commented Dec 21, 2018

Is it possible that the store to 0x18(%rdi) is somehow clobbering a return address on the stack?

@bjorn3

This comment has been minimized.

Copy link
Owner

bjorn3 commented Dec 21, 2018

That's possible. rdi is a bit higher than rsp.

rdi 0x7ffc3ea15ab8
rsp 0x7ffc3ea159f0
@bjorn3

This comment has been minimized.

Copy link
Owner

bjorn3 commented Dec 21, 2018

(rr) disassemble
Dump of assembler code for function _ZN46_$LT$std..thread..local..LocalKey$LT$T$GT$$GT$8try_with17h72e6de457ec8a4ceE:
   0x000055e6c58a64f0 <+0>:  push   %rbp
   0x000055e6c58a64f1 <+1>:  mov    %rsp,%rbp
   0x000055e6c58a64f4 <+4>:  push   %rbx
   0x000055e6c58a64f5 <+5>:  sub    $0x68,%rsp
   0x000055e6c58a64f9 <+9>:  mov    %rdi,0x40(%rsp)
   0x000055e6c58a6501 <+17>:  mov    %rsi,0x38(%rsp)
   0x000055e6c58a6509 <+25>:  lea    0x0(%rsp),%rax
   0x000055e6c58a6511 <+33>:  mov    %rax,0x30(%rsp)
   0x000055e6c58a6519 <+41>:  lea    0x60(%rsp),%rax
   0x000055e6c58a6521 <+49>:  mov    %rax,0x28(%rsp)
   0x000055e6c58a6529 <+57>:  lea    0x58(%rsp),%rax
=> 0x000055e6c58a6531 <+65>:  mov    %rax,0x20(%rsp)
(rr) info registers
rax            0x7ffc3ea15ab8   0x7ffc3ea15ab8
[...]

0x7ffc3ea15ab8 seems to be a normal part of try_with's stack frame. (offset 0x58 out of 0x68)

Edit: 0x58 + 0x18 = 0x70 which is bigger than 0x68. This seems to be the problem indeed.

@bjorn3 bjorn3 self-assigned this Dec 23, 2018

@bjorn3 bjorn3 added the bug label Dec 23, 2018

@bjorn3

This comment has been minimized.

Copy link
Owner

bjorn3 commented Dec 29, 2018

I was able to work around this in d3dcf4d.

@bjorn3

This comment has been minimized.

Copy link
Owner

bjorn3 commented Dec 29, 2018

I am trying to compile ripgrep using this at the moment. Some build scripts fail, because of code replaced with unimplemented!() to workaround missing varargs support. (CraneStation/cranelift#212)

@bjorn3

This comment was marked as resolved.

Copy link
Owner

bjorn3 commented Jan 31, 2019

Status report:

For https://github.com/dropbox/rust-brotli-decompressor I get the following on Linux:

$ RUSTFLAGS="-Cpanic=abort -Zcodegen-backend=$(pwd)/../target/debug/librustc_codegen_cranelift.so --sysroot $(pwd)/../build_sysroot/sysroot" cargo run --release --bin brotli-decompressor
[...]
$ lldb target/release/brotli-decompressor
(lldb) target create "target/release/brotli-decompressor"
Current executable set to 'target/release/brotli-decompressor' (x86_64).
(lldb) run
Process 22547 launched: '/home/bjorn/Documenten/rustc_codegen_cranelift/rust-brotli-decompressor/target/release/brotli-decompressor' (x86_64)
Process 22547 stopped
* thread #1: tid = 22547, 0x00005555555bf148 brotli-decompressor`core::ptr::real_drop_in_place::h87a6e70141dee524 + 8 at ptr.rs:193, name = 'brotli-decompre', stop reason = signal SIGSEGV: invalid address (fault address: 0x0)
    frame #0: 0x00005555555bf148 brotli-decompressor`core::ptr::real_drop_in_place::h87a6e70141dee524 + 8 at ptr.rs:193
   190  // actually access it with raw pointers.
   191  #[lang = "drop_in_place"]
   192  #[allow(unconditional_recursion)]
-> 193  unsafe fn real_drop_in_place<T: ?Sized>(to_drop: &mut T) {
   194      // Code here does not matter - this is replaced by the
   195      // real drop glue by the compiler.
   196      real_drop_in_place(to_drop)
(lldb) bt
* thread #1: tid = 22547, 0x00005555555bf148 brotli-decompressor`core::ptr::real_drop_in_place::h87a6e70141dee524 + 8 at ptr.rs:193, name = 'brotli-decompre', stop reason = signal SIGSEGV: invalid address (fault address: 0x0)
  * frame #0: 0x00005555555bf148 brotli-decompressor`core::ptr::real_drop_in_place::h87a6e70141dee524 + 8 at ptr.rs:193
    frame #1: 0x00005555555bf12e brotli-decompressor`core::ptr::real_drop_in_place::h1288bec36c72e74e + 30 at ptr.rs:193
    frame #2: 0x00005555555bba91 brotli-decompressor`core::ptr::real_drop_in_place::hb04f20f9e1e029a3 + 49 at ptr.rs:193
    frame #3: 0x00005555555bba50 brotli-decompressor`core::ptr::real_drop_in_place::h95d80bc1fd152fa7 + 80 at ptr.rs:193
    frame #4: 0x00005555555b261e brotli-decompressor`core::ptr::real_drop_in_place::hd2b77ac6446ffd50 + 30 at ptr.rs:193
    frame #5: 0x00005555555ce8d9 brotli-decompressor`core::ptr::real_drop_in_place::hc504e28ab70ee02f + 73 at ptr.rs:193
    frame #6: 0x00005555555cddf3 brotli-decompressor`std::io::stdio::stdin::stdin_init::h074a1efd6ad98233 + 947 at stdio.rs:202
    frame #7: 0x00005555555c2e00 brotli-decompressor`_$LT$std..io..lazy..Lazy$LT$T$GT$$GT$::init::hd283afda3e37b21b + 256 at lazy.rs:58
    frame #8: 0x00005555555c2c13 brotli-decompressor`_$LT$std..io..lazy..Lazy$LT$T$GT$$GT$::get::h1cdf1ddd76678384 + 163 at lazy.rs:34
    frame #9: 0x00005555555ded82 brotli-decompressor`std::io::stdio::stdin::h72f7fa09a01a5196 + 82 at stdio.rs:193
    frame #10: 0x000055555558b461 brotli-decompressor`brotli_decompressor::main::h6cd6bd21167c7df1 + 2929
    frame #11: 0x000055555556ca3d brotli-decompressor`std::rt::lang_start::_$u7b$$u7b$closure$u7d$$u7d$::h5d5bdc3eceea0d27 + 45
    frame #12: 0x00005555555b34d4 brotli-decompressor`std::rt::lang_start_internal::_$u7b$$u7b$closure$u7d$$u7d$::h1ac2308b810b402a + 84 at rt.rs:52
    frame #13: 0x00005555555b3468 brotli-decompressor`std::panicking::try::do_call::hf50a45a4b02cb4f8 + 328 at panicking.rs:297
    frame #14: 0x00005555555e0080 brotli-decompressor`__rust_maybe_catch_panic + 32 at lib.rs:29
    frame #15: 0x00005555555cfc90 brotli-decompressor`std::panicking::try::hbf774221e207c402 + 256 at panicking.rs:276
    frame #16: 0x00005555555dff59 brotli-decompressor`std::rt::lang_start_internal::h0c159ce7acd430d1 + 521 at panic.rs:382
    frame #17: 0x0000555555576af2 brotli-decompressor`std::rt::lang_start::hb4be95bce08f0567 + 66
    frame #18: 0x00005555555a17d9 brotli-decompressor`main + 25
    frame #19: 0x00007ffff74312e1 libc.so.6`__libc_start_main + 241
    frame #20: 0x000055555555808a brotli-decompressor`_start + 42

Note: use lldb or rr, because gdb crashes itself.

@bjorn3

This comment has been minimized.

Copy link
Owner

bjorn3 commented Feb 1, 2019

Note to self: I need to promote any argument smaller than a C int to an int, and promote float to double. (Source: https://github.com/rust-lang/rfcs/blob/master/text/2137-variadic.md)

@bjorn3

This comment was marked as resolved.

Copy link
Owner

bjorn3 commented Feb 3, 2019

The std::io::stdin() crash from #146 (comment) seems to be caused by drop glue for the error case of a result being run, while the result was Ok.

@bjorn3

This comment was marked as resolved.

Copy link
Owner

bjorn3 commented Feb 3, 2019

I found a problem: storing a func ptr in a zero sized stack slot. That stack slot was probably meant for TyFnDef instead of TyFnPtr.

[...]
    ss4 = explicit_slot 0
[...]
; _1 = const <std::result::Result<T, E>>::map(move _2, const std::prelude::v1::Some)
@0000                               v6 = func_addr.i64 fn0
@0000                               v7 = load.i8 v2
@0000                               v8 = stack_addr.i64 ss4
[...]
@bjorn3

This comment was marked as resolved.

Copy link
Owner

bjorn3 commented Feb 3, 2019

Fixed it in 0d16dcf

@bjorn3

This comment has been minimized.

Copy link
Owner

bjorn3 commented Feb 3, 2019

Things crashing:

  • ::std::iter::repeat('a' as u8).take(10).collect::<Vec<_>>()
  • ::std::io::stderr().write_fmt(format_args!("thread '{}' panicked at ...", "<unknown>"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment