Skip to content
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

rustc 1.13.0-nightly exit with linkage error, when compiling 'Rust by Example - 8.2.5 As output parameters' code. #36260

Closed
koizumi9n opened this Issue Sep 4, 2016 · 10 comments

Comments

Projects
None yet
9 participants
@koizumi9n
Copy link

koizumi9n commented Sep 4, 2016

I found that current rustc 1.13.0-nightly can't compile'Rust by Example - 8.2.5 As output parameters' code, both on my linux pc and Rust Playground.

I tried this code: see Rust by Example 8.2.5

fn create_fn() -> Box<Fn()> {
    let text = "Fn".to_owned();

    Box::new(move || println!("This is a: {}", text))
}

fn create_fnmut() -> Box<FnMut()> {
    let text = "FnMut".to_owned();

    Box::new(move || println!("This is a: {}", text))
}

fn main() {
    let fn_plain = create_fn();
    let mut fn_mut = create_fnmut();

    fn_plain();
    fn_mut();
}

Executing code above on Rust Playground produces the message below when selecting nightly. ( but stable and beta do not produce this error).


error: linking with cc failed: exit code: 1
|
= note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-L" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib" "./out.0.o" "-o" "./out" "-Wl,--gc-sections" "-pie" "-nodefaultlibs" "-L" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "-Wl,-Bdynamic" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-411f48d3.rlib" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-411f48d3.rlib" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-411f48d3.rlib" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/librand-411f48d3.rlib" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcollections-411f48d3.rlib" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_unicode-411f48d3.rlib" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-411f48d3.rlib" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_jemalloc-411f48d3.rlib" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-411f48d3.rlib" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-411f48d3.rlib" "-l" "dl" "-l" "pthread" "-l" "gcc_s" "-l" "pthread" "-l" "c" "-l" "m" "-l" "rt" "-l" "util" "-l" "compiler-rt"
= note: ./out.0.o: In function drop::hf3564cae7b79f1cb': rust_out.cgu-0.rs:(.text._ZN4drop17hf3564cae7b79f1cbE+0xd): undefined reference to$LT$collections..vec..Vec$LT$T$GT$$u20$as$u20$core..ops..Drop$GT$::drop::h4c07c16183524d21'
./out.0.o: In function drop::hc5f0e028c3876d25': rust_out.cgu-0.rs:(.text._ZN4drop17hc5f0e028c3876d25E+0xd): undefined reference to
$LT$alloc..raw_vec..RawVec$LT$T$GT$$u20$as$u20$core..ops..Drop$GT$::drop::h7a8bb753832b1af2'
collect2: error: ld returned 1 exit status

error: aborting due to previous error

Compilation failed.


This happens on my Linux Laptop pc as well.
This is my laptop's rustc version(installing current latest) .

rustc --version --verbose:
rustc 1.13.0-nightly (e07dd59 2016-08-25)
binary: rustc
commit-hash: e07dd59
commit-date: 2016-08-25
host: x86_64-unknown-linux-gnu
release: 1.13.0-nightly

@koizumi9n koizumi9n changed the title rustc 1.13.0-nightly can't compile 'Rust by Example - 8.2.5 As output parameters' code. rustc 1.13.0-nightly exit with linkage error, when compiling 'Rust by Example - 8.2.5 As output parameters' code. Sep 4, 2016

@koizumi9n koizumi9n changed the title rustc 1.13.0-nightly exit with linkage error, when compiling 'Rust by Example - 8.2.5 As output parameters' code. rustc 1.13.0-nightly exits with linkage error, when compiling 'Rust by Example - 8.2.5 As output parameters' code. Sep 4, 2016

@koizumi9n koizumi9n changed the title rustc 1.13.0-nightly exits with linkage error, when compiling 'Rust by Example - 8.2.5 As output parameters' code. rustc 1.13.0-nightly exit with linkage error, when compiling 'Rust by Example - 8.2.5 As output parameters' code. Sep 4, 2016

@MagaTailor

This comment has been minimized.

Copy link

MagaTailor commented Sep 4, 2016

error: linking with `cc` failed: exit code: 1
  |
  = note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-L" "/rust/rust-nightly-sysalloc-llvm3.9/lib/rustlib/aarch64-unknown-linux-gnu/lib" "../parity-master/target/release/parity.0.o" "-o" "../parity-master/target/release/parity" "-Wl,--gc-sections" "-pie" "-Wl,-O1" "-nodefaultlibs" "-L" "../parity-master/target/release/deps" "-L" "../parity-master/target/release/build/rust-crypto-ed6f35bcd4283630/out" "-L" "../parity-master/target/release/build/rocksdb-sys-85650723073925db/out" "-L" "../parity-master/target/release/build/rocksdb-sys-85650723073925db/out" "-L" "../parity-master/target/release/build/sha3-5886980f897f8041/out" "-L" "../parity-master/target/release/build/eth-secp256k1-fcaa5ca0c6e6e793/out" "-L" "../parity-master/target/release/build/nanomsg-sys-197eca269c49f40e/out" "-L" "/rust/rust-nightly-sysalloc-llvm3.9/lib/rustlib/aarch64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "-Wl,-Bdynamic" "/tmp/rustc.sPBlB1kA2Qr1/libnanomsg_sys-ef795781850263eb.rlib" "/tmp/rustc.sPBlB1kA2Qr1/libsha3.rlib" "/tmp/rustc.sPBlB1kA2Qr1/librocksdb_sys-775707c1a0d48a54.rlib" "/tmp/rustc.sPBlB1kA2Qr1/libsecp256k1-ddb291d467b8ff52.rlib" "/tmp/rustc.sPBlB1kA2Qr1/libcrypto-ccca7bf8b1baef5f.rlib" "/tmp/rustc.sPBlB1kA2Qr1/libstd-836a4172.rlib" "-l" "anl" "-l" "snappy" "-l" "rocksdb" "-l" "stdc++" "-l" "stdc++" "-l" "c" "-l" "util" "-l" "dl" "-l" "pthread" "-l" "gcc_s" "-l" "c" "-l" "m" "-l" "rt" "-l" "util" "-s" "-l" "compiler-rt"
  = note: ../parity-master/target/release/parity.0.o: In function `drop::hca057d947f770cc6':
parity.cgu-0.rs:(.text._ZN4drop17hca057d947f770cc6E+0x0): undefined reference to `_$LT$alloc..arc..Arc$LT$T$GT$$u20$as$u20$core..ops..Drop$GT$::drop::ha2fd73b0d2df24c5'
../parity-master/target/release/parity.0.o: In function `extern$u20$$u22$rust.call$u22$$u20$fn$LP$$u5b$closure$SP$rpc$u2f$src$u2f$lib.rs.106.19.$u20$108.5$u20$panic_handler.std..sync..Arc$LT$io..PanicHandler$GT$$u5d$$C$$u20$$LP$$RP$$RP$::once_shim.27073::hb6ef47f61e5bd418':
parity.cgu-0.rs:(.text._ZN179extern$u20$$u22$rust.call$u22$$u20$fn$LP$$u5b$closure$SP$rpc$u2f$src$u2f$lib.rs.106.19.$u20$108.5$u20$panic_handler.std..sync..Arc$LT$io..PanicHandler$GT$$u5d$$C$$u20$$LP$$RP$$RP$15once_shim.2707317hb6ef47f61e5bd418E+0xcc): undefined reference to `_$LT$alloc..arc..Arc$LT$T$GT$$u20$as$u20$core..ops..Drop$GT$::drop::ha2fd73b0d2df24c5'
@steveklabnik

This comment has been minimized.

Copy link
Member

steveklabnik commented Sep 6, 2016

Nominating since this appears to be a regression.

@TimNN

This comment has been minimized.

Copy link
Contributor

TimNN commented Sep 7, 2016

nightly-2016-08-23 is still good, nightly-2016-08-24 does not exist and nightly-2016-08-25 fails. Changes between -23 and -25.

Reduced:

fn create_fn() -> Box<Fn()> {
    let text = String::new();

    Box::new(move || { let _ = &text; })
}

fn main() {
    let _ = create_fn();
}
@TimNN

This comment has been minimized.

Copy link
Contributor

TimNN commented Sep 7, 2016

This may be a duplicate of / related to #36155.

Edit: not a duplicate I think, since #36155 was introduced in a different nightly.

@thepowersgang

This comment has been minimized.

Copy link
Contributor

thepowersgang commented Sep 10, 2016

Running rustc 1.13.0-nightly (a7b2232d2 2016-09-07) with the above sample and RUST_LOG=debug leads to an ICE in printing a log message

*SNIP*
INFO:rustc_trans::base: trans_closure(..., std::boxed::<impl Box<T>><[closure@1.rs:3:11: 3:37 text:std::string::String]>::new)
INFO:rustc_trans::base: trans_closure(..., create_fn)
INFO:rustc_trans::base: trans_closure(..., error: internal compiler error: ../src/librustc/ty/mod.rs:2067: No def'n found for DefId { krate: 0, node: DefIndex(6) => create_fn::{{closure}} } in tcx.generics
@eddyb

This comment has been minimized.

Copy link
Member

eddyb commented Sep 10, 2016

This is from the removal of old trans. We should've been covered by on-demand drop glue generation still, though.
cc @michaelwoerister

@thepowersgang

This comment has been minimized.

Copy link
Contributor

thepowersgang commented Sep 10, 2016

Looking at the IR - the missing methods are declared, and called from internal drop methods taking e.g. std::vec::Vec<u8>

define internal void @_ZN4drop17h974e21c3220a1699E(%"3.std::vec::Vec<u8>"*) unnamed_addr personality i32 (i32, i32, i64, %"8.unwind::libunwind::_Unwind_Exception"*, %"8.unwind::libunwind::_Unwind_Context"*)* @rust_eh_personality {
entry-block:
  %1 = alloca { i8*, i32 }
  invoke void @"_ZN66_$LT$collections..vec..Vec$LT$T$GT$$u20$as$u20$core..ops..Drop$GT$4drop17h4c07c16183524d21E"(%"3.std::vec::Vec<u8>"* dereferenceable(24) %0)
          to label %normal-return unwind label %unwind_custom_

normal-return:                                    ; preds = %entry-block
  call void @_ZN13drop_contents17h974e21c3220a1699E(%"3.std::vec::Vec<u8>"* %0)
  ret void

** SNIP **

declare void @"_ZN66_$LT$collections..vec..Vec$LT$T$GT$$u20$as$u20$core..ops..Drop$GT$4drop17h4c07c16183524d21E"(%"3.std::vec::Vec<u8>"* dereferenceable(24)) unnamed_addr
@eddyb

This comment has been minimized.

Copy link
Member

eddyb commented Sep 10, 2016

@thepowersgang Oh, this is bad. The collector needs to know user definitions being instantiated ahead of time (including Drop impls), and these can be used from drop glue which is not guaranteedly known ahead of time.

We might need to temporarily detect the shim'd cases in the collector and trigger drop glue generation. cc #34151

@michaelwoerister

This comment has been minimized.

Copy link
Contributor

michaelwoerister commented Sep 13, 2016

I'm looking into a short-term fix right now.

bors added a commit that referenced this issue Sep 14, 2016

Auto merge of #36468 - michaelwoerister:collect-vtable-drop-glue, r=e…
…ddyb

trans: Let the collector find drop-glue for all vtables, not just VTableImpl.

This fixes #36260. So far, the collector has only recorded drop-glue for insertion into a vtable if the vtable was for an impl. But there's actually no reason why it shouldn't do just the same for closure vtables, afaict.

r? @eddyb
cc @rust-lang/compiler

bors added a commit that referenced this issue Sep 14, 2016

Auto merge of #36468 - michaelwoerister:collect-vtable-drop-glue, r=e…
…ddyb

trans: Let the collector find drop-glue for all vtables, not just VTableImpl.

This fixes #36260. So far, the collector has only recorded drop-glue for insertion into a vtable if the vtable was for an impl. But there's actually no reason why it shouldn't do just the same for closure vtables, afaict.

r? @eddyb
cc @rust-lang/compiler

@nrc nrc removed the I-nominated label Sep 15, 2016

jonathandturner added a commit to jonathandturner/rust that referenced this issue Sep 15, 2016

Rollup merge of rust-lang#36468 - michaelwoerister:collect-vtable-dro…
…p-glue, r=eddyb

trans: Let the collector find drop-glue for all vtables, not just VTableImpl.

This fixes rust-lang#36260. So far, the collector has only recorded drop-glue for insertion into a vtable if the vtable was for an impl. But there's actually no reason why it shouldn't do just the same for closure vtables, afaict.

r? @eddyb
cc @rust-lang/compiler

bors added a commit that referenced this issue Sep 17, 2016

Auto merge of #36468 - michaelwoerister:collect-vtable-drop-glue, r=e…
…ddyb

trans: Let the collector find drop-glue for all vtables, not just VTableImpl.

This fixes #36260. So far, the collector has only recorded drop-glue for insertion into a vtable if the vtable was for an impl. But there's actually no reason why it shouldn't do just the same for closure vtables, afaict.

r? @eddyb
cc @rust-lang/compiler

@bors bors closed this in #36468 Sep 17, 2016

@thepowersgang

This comment has been minimized.

Copy link
Contributor

thepowersgang commented Sep 19, 2016

yay! Thanks @jonathandturner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.