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

undefined reference link error regression #34796

Closed
alexcrichton opened this issue Jul 13, 2016 · 9 comments
Closed

undefined reference link error regression #34796

alexcrichton opened this issue Jul 13, 2016 · 9 comments
Labels
regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@alexcrichton
Copy link
Member

alexcrichton commented Jul 13, 2016

This looks to be a regression from stable to beta unfortunately, compiling rust-lang/futures-rs@6ae0345 succeeds on stable but fails on beta:

$ rustup run stable cargo build --manifest-path http/Cargo.toml
...
$ rustup run beta cargo build --manifest-path http/Cargo.toml
...
   Compiling http v0.1.0 (file:///home/alex/code/futures/http)
error: linking with `cc` failed: exit code: 1
note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-L" "/home/alex/.multirust/toolchains/beta-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "/home/alex/code/futures/http/target/debug/http.0.o" "-o" "/home/alex/code/futures/http/target/debug/http" "-Wl,--gc-sections" "-pie" "-nodefaultlibs" "-L" "/home/alex/code/futures/http/target/debug" "-L" "/home/alex/code/futures/http/target/debug/deps" "-L" "/home/alex/.multirust/toolchains/beta-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "-Wl,-Bdynamic" "/home/alex/code/futures/http/target/debug/libhttp.rlib" "/home/alex/code/futures/http/target/debug/deps/libhttparse-36b96d90ffbce562.rlib" "/home/alex/code/futures/http/target/debug/deps/libfuturemio-986c91cdeb491b00.rlib" "/home/alex/code/futures/http/target/debug/deps/libslab-45f4a226259c4869.rlib" "/home/alex/code/futures/http/target/debug/deps/libfutures-1a55edc1e7c129de.rlib" "/home/alex/code/futures/http/target/debug/deps/libmio-a89f84904d772c54.rlib" "/home/alex/code/futures/http/target/debug/deps/libnet2-b2390925f9bbf4a2.rlib" "/home/alex/code/futures/http/target/debug/deps/libcfg_if-72c1f992b13d5087.rlib" "/home/alex/code/futures/http/target/debug/deps/libmiow-b827bf6129dcd844.rlib" "/home/alex/code/futures/http/target/debug/deps/libwinapi-0889532d327ff4e2.rlib" "/home/alex/code/futures/http/target/debug/deps/libnix-f8d033ce6354dacb.rlib" "/home/alex/code/futures/http/target/debug/deps/libbytes-f9fbfc75eb2416e0.rlib" "/home/alex/code/futures/http/target/debug/deps/libscoped_tls-53036341d2dbbe26.rlib" "/home/alex/code/futures/http/target/debug/deps/libtime-750bfdd52feafcb7.rlib" "/home/alex/code/futures/http/target/debug/deps/liblibc-1f3392fe1afd1313.rlib" "/home/alex/code/futures/http/target/debug/deps/liblog-bf16bb9a4912b11d.rlib" "/home/alex/code/futures/http/target/debug/deps/libbitflags-e61ad67c3301e77d.rlib" "/home/alex/code/futures/http/target/debug/deps/libslab-4f8b9e9b6e35857c.rlib" "/home/alex/.multirust/toolchains/beta-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-411fd48b.rlib" "/home/alex/.multirust/toolchains/beta-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-411fd48b.rlib" "/home/alex/.multirust/toolchains/beta-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-411fd48b.rlib" "/home/alex/.multirust/toolchains/beta-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librand-411fd48b.rlib" "/home/alex/.multirust/toolchains/beta-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcollections-411fd48b.rlib" "/home/alex/.multirust/toolchains/beta-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_unicode-411fd48b.rlib" "/home/alex/.multirust/toolchains/beta-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-411fd48b.rlib" "/home/alex/.multirust/toolchains/beta-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_jemalloc-411fd48b.rlib" "/home/alex/.multirust/toolchains/beta-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-411fd48b.rlib" "/home/alex/.multirust/toolchains/beta-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-411fd48b.rlib" "-l" "util" "-l" "dl" "-l" "pthread" "-l" "gcc_s" "-l" "pthread" "-l" "c" "-l" "m" "-l" "rt" "-l" "util" "-l" "compiler-rt"
note: /home/alex/code/futures/http/target/debug/http.0.o: In function `http::serve<http::request::Request,http::response::Response,closure>':
/home/alex/code/futures/http/src/lib.rs:55: undefined reference to `futuremio::tcp::_$LT$impl$u20$futuremio..event_loop..LoopHandle$GT$::tcp_listen::h9a7258751896fb30'
/home/alex/code/futures/http/target/debug/http.0.o: In function `http::serve::_$u7b$$u7b$closure$u7d$$u7d$::hed42a806f41e1837':
http.0.rs:(.text._ZN4http5serve28_$u7b$$u7b$closure$u7d$$u7d$17hed42a806f41e1837E+0xa2): undefined reference to `futuremio::tcp::TcpListener::incoming::h7aae24690b0d3a8d'
/home/alex/code/futures/http/target/debug/http.0.o: In function `futures::forget::forget<futures::then::Then<Box<Future>, core::result::Result<(), std::sync::mpsc::SendError<core::result::Result<(), std::io::error::Error>>>, closure>>':
/home/alex/code/futures/src/forget.rs:23: undefined reference to `futures::forget::_forget::h4301ad1ba69f01dc'
collect2: error: ld returned 1 exit status


error: aborting due to previous error
error: Could not compile `http`.

cc @michaelwoerister, does this look familiar?

I'll try to reduce down as well, but wanted to file an issue nonetheless.

@alexcrichton alexcrichton added I-nominated T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. regression-from-stable-to-beta Performance or correctness regression from stable to beta. labels Jul 13, 2016
@alexcrichton
Copy link
Member Author

cc @rust-lang/compiler

@alexcrichton
Copy link
Member Author

Ok, minimized:

// foo.rs
#![crate_type = "lib"]
#![crate_name = "foo"]
pub trait Future {
    type Item;
    type Error;
}

fn foo() -> Box<Future<Item=(), Error=Box<()>>> {
    loop {}
}

pub fn bar<F, A, B>(_s: F)
    where F: Fn(A) -> B,
{
    foo();
}

// bar.rs
extern crate foo;

fn mk<T>() -> T { loop {} }

struct Data<T, E> {
    data: T,
    error: E,
}

fn main() {
    foo::bar(|()| {
        Data::<(), std::io::Error> {
            data: mk(),
            error: mk(),
        }
    })
}
$ rustup run stable rustc foo.rs && rustup run stable rustc bar.rs -L .
...
$ rustup run nightly rustc foo.rs && rustup run nightly rustc bar.rs -L .
...
error: linking with `cc` failed: exit code: 1
note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-L" "/home/alex/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "bar.0.o" "-o" "bar" "-Wl,--gc-sections" "-pie" "-nodefaultlibs" "-L" "." "-L" "/home/alex/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "-Wl,-Bdynamic" "/home/alex/code/futures/libfoo.rlib" "/home/alex/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-c8005792.rlib" "/home/alex/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-c8005792.rlib" "/home/alex/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-c8005792.rlib" "/home/alex/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librand-c8005792.rlib" "/home/alex/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcollections-c8005792.rlib" "/home/alex/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_unicode-c8005792.rlib" "/home/alex/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-c8005792.rlib" "/home/alex/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_jemalloc-c8005792.rlib" "/home/alex/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-c8005792.rlib" "/home/alex/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-c8005792.rlib" "-l" "dl" "-l" "pthread" "-l" "gcc_s" "-l" "pthread" "-l" "c" "-l" "m" "-l" "rt" "-l" "util" "-l" "compiler-rt"
note: bar.0.o: In function `foo::bar::h97da9529975f6f18':
bar.cgu-0.rs:(.text._ZN3foo3bar17h97da9529975f6f18E+0xf): undefined reference to `foo::foo::h4e3fa806e0391cb9'
collect2: error: ld returned 1 exit status

@alexcrichton
Copy link
Member Author

So it looks like the IR for the foo.rs file emits a symbol of the name

_ZN3foo3foo17h024669b567103e37E

Yet when bar.rs is compiled it expects a symbol of the name

_ZN3foo3foo17h4e3fa806e0391cb9E

Seems... bad! I wonder if #33703 is related...

@michaelwoerister
Copy link
Member

So, my guess is that both stable and beta compute different symbol names here, but in stable symbol names are still store in metadata and thus we don't see the discrepancy. Why they compute different names, I don't know yet.

@eddyb
Copy link
Member

eddyb commented Jul 13, 2016

@michaelwoerister If tcx.hash_crate_independent(...) is used for the hash in the symbol name then it's #33703 - @willcrichton said he'd look into fixing that.

@michaelwoerister
Copy link
Member

We are hashing the type parameters as they are encoded for metadata, which should be a stable representation.

@michaelwoerister
Copy link
Member

So, here is some debug output from symbol hashing:

foo.rs
compute symbol hash:
foo/45447b7afbd5e544f7d0f1df0fccd26014d9850130abd3f020b89ff96b82079f::foo[0]
encoded_item_type: Ffoo/45447b7afbd5e544f7d0f1df0fccd26014d9850130abd3f020b89ff96b82079f::foo[0]|[][][][][][]n[Rust][]N~x[foo/45447b7afbd5e544f7d0f1df0fccd26014d9850130abd3f020b89ff96b82079f::Future[0]|[][][][][][].EPfoo/45447b7afbd5e544f7d0f1df0fccd26014d9850130abd3f020b89ff96b82079f::Future[0]|[][][][][][]Item|T[]Pfoo/45447b7afbd5e544f7d0f1df0fccd26014d9850130abd3f020b89ff96b82079f::Future[0]|[][][][][][]Error|~T[].]
hash: h024669b567103e37


bar.rs
compute symbol hash:
foo/45447b7afbd5e544f7d0f1df0fccd26014d9850130abd3f020b89ff96b82079f::foo[0]
encoded_item_type: Ffoo/45447b7afbd5e544f7d0f1df0fccd26014d9850130abd3f020b89ff96b82079f::foo[0]|[][][][][][]n[Rust][]N~x[foo/45447b7afbd5e544f7d0f1df0fccd26014d9850130abd3f020b89ff96b82079f::Future[0]|[][][][][][].EPfoo/45447b7afbd5e544f7d0f1df0fccd26014d9850130abd3f020b89ff96b82079f::Future[0]|[][][][][][]Error|~T[]Pfoo/45447b7afbd5e544f7d0f1df0fccd26014d9850130abd3f020b89ff96b82079f::Future[0]|[][][][][][]Item|T[].]
hash: h4e3fa806e0391cb9

If you look closely, you might see that the named type parameters are encoded in a different order in the two cases.

@michaelwoerister
Copy link
Member

Yeah, it looks like the projection bounds are sorted by DefId:
https://github.com/rust-lang/rust/blob/beta/src/librustc/ty/mod.rs#L1030

@alexcrichton
Copy link
Member Author

@michaelwoerister awesome, thanks for the investigation!

bors added a commit that referenced this issue Jul 14, 2016
tyencode: Make sure that projection bounds are handled in stable order.

Fixes #34796.

r? @alexcrichton
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants