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

Regression in cross-compiling from 64 -> 32 bit #36793

Closed
alexcrichton opened this issue Sep 27, 2016 · 24 comments · Fixed by #36866
Closed

Regression in cross-compiling from 64 -> 32 bit #36793

alexcrichton opened this issue Sep 27, 2016 · 24 comments · Fixed by #36866
Labels
regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@alexcrichton
Copy link
Member

In today's most recent nightly:

rustc 1.13.0-nightly (d0623cf7b 2016-09-26)
binary: rustc
commit-hash: d0623cf7bda44849ab5df78a06b22f9108cf821a
commit-date: 2016-09-26
host: x86_64-unknown-linux-gnu
release: 1.13.0-nightly

Compiling a simple program:

fn main() {}

yields

$ rustc +nightly foo.rs --target i686-unknown-linux-gnu
error: linking with `cc` failed: exit code: 1
  |
  = note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m32" "-L" "/home/alex/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/i686-unknown-linux-gnu/lib" "foo.0.o" "-o" "foo" "-Wl,--gc-sections" "-pie" "-nodefaultlibs" "-L" "/home/alex/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/i686-unknown-linux-gnu/lib" "-Wl,-Bstatic" "-Wl,-Bdynamic" "/home/alex/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/i686-unknown-linux-gnu/lib/libstd-411f48d3.rlib" "/home/alex/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/i686-unknown-linux-gnu/lib/libpanic_unwind-411f48d3.rlib" "/home/alex/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/i686-unknown-linux-gnu/lib/libunwind-411f48d3.rlib" "/home/alex/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/i686-unknown-linux-gnu/lib/librand-411f48d3.rlib" "/home/alex/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/i686-unknown-linux-gnu/lib/libcollections-411f48d3.rlib" "/home/alex/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/i686-unknown-linux-gnu/lib/librustc_unicode-411f48d3.rlib" "/home/alex/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/i686-unknown-linux-gnu/lib/liballoc-411f48d3.rlib" "/home/alex/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/i686-unknown-linux-gnu/lib/liballoc_jemalloc-411f48d3.rlib" "/home/alex/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/i686-unknown-linux-gnu/lib/liblibc-411f48d3.rlib" "/home/alex/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/i686-unknown-linux-gnu/lib/libcore-411f48d3.rlib" "/home/alex/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/i686-unknown-linux-gnu/lib/libcompiler_builtins-411f48d3.rlib" "-l" "dl" "-l" "pthread" "-l" "gcc_s" "-l" "pthread" "-l" "c" "-l" "m" "-l" "rt" "-l" "util"
  = note: foo.0.o: In function `main':
foo.cgu-0.rs:(.text.main+0x2d): undefined reference to `std::rt::lang_start::h95854775e4ac8b95'
collect2: error: ld returned 1 exit status


error: aborting due to previous error

Seems odd to have an undefined symbol in the standard library! Taking a look at what's actually inside:

$ nm -g /home/alex/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/i686-unknown-linux-gnu/lib/libstd-411f48d3.rlib | grep lang_start | c++filt
00000000 T std::rt::lang_start::hb5404024d2e88016

Looks like the hashes are different!

Did we perhaps leak a usize into metadata/symbol calculation?

cc @eddyb
cc @michaelwoerister

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

eddyb commented Sep 27, 2016

So I guess tuple lengths were always broken w/ cross-compilation, but only through TypeId.
You can fix it by adding as u64 (or u32 but that'd require an extra check) here and here.

@eddyb eddyb added the E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. label Sep 27, 2016
sophiajt pushed a commit to sophiajt/rust that referenced this issue Sep 28, 2016
bors added a commit that referenced this issue Sep 28, 2016
TypeIdHasher: hash usize as u64

Fixes #36793.
@BurntSushi
Copy link
Member

Is this related? https://travis-ci.org/BurntSushi/ripgrep/jobs/163366626 (Cross compiling i686-apple-darwin from x86_64-apple-darwin.)

@TimNN
Copy link
Contributor

TimNN commented Sep 28, 2016

@BurntSushi I'd think that you're experiencing exactly this issue, although I'm not sure what to make of these warnings (and if they are even important):

  = note: ld: warning: could not create compact unwind for __ZN4core3num7flt2dec8strategy6dragon15format_shortest17hbdcbfeff9d90c839E: stack subl instruction is too different from dwarf stack size
ld: warning: could not create compact unwind for __ZN4core3fmt23float_to_decimal_common17h07a52791ce6b485eE: stack subl instruction is too different from dwarf stack size
ld: warning: could not create compact unwind for __ZN4core3fmt23float_to_decimal_common17h62a680cf01e490e7E: stack subl instruction is too different from dwarf stack size
ld: warning: could not create compact unwind for __ZN4core3fmt27float_to_exponential_common17hb2f23958bdef5ec0E: stack subl instruction is too different from dwarf stack size
ld: warning: could not create compact unwind for __ZN4core3fmt27float_to_exponential_common17hedda57d97c9f5d15E: stack subl instruction is too different from dwarf stack size
ld: warning: could not create compact unwind for __ZN3std3sys2fs4copy17ha1b8cf4f7b2525caE: stack subl instruction is too different from dwarf stack size
ld: warning: could not create compact unwind for __ZN3std4rand6StdRng3new17h2d301b41144d5cfcE: stack subl instruction is too different from dwarf stack size
ld: warning: could not create compact unwind for __ZN99_$LT$std..rand..ThreadRngReseeder$u20$as$u20$rand..reseeding..Reseeder$LT$std..rand..StdRng$GT$$GT$6reseed17h37d92a6ecfebac86E: stack subl instruction is too different from dwarf stack size
ld: warning: could not create compact unwind for __ZN3std4rand10thread_rng14THREAD_RNG_KEY6__init17hfd5fb3b8ece6f6d7E: stack subl instruction is too different from dwarf stack size

@japaric
Copy link
Member

japaric commented Sep 29, 2016

This bug is affecting the current beta: 1.13.0.beta.1. Can the fix be backported? This bug may affect bootstrapping the compiler, I think; that beta is (or will soon be) the current stage0 (?).

@alexcrichton
Copy link
Member Author

It looks like this is also still affecting nightly:

$ rustc +nightly -vV
rustc 1.14.0-nightly (289f3a4ca 2016-09-29)
binary: rustc
commit-hash: 289f3a4ca79916d6445b452fc19a18a1e42a879a
commit-date: 2016-09-29
host: x86_64-unknown-linux-gnu
release: 1.14.0-nightly
$ rustc +nightly foo.rs --target i686-unknown-linux-gnu
error: linking with `cc` failed: exit code: 1
  |
  = note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m32" "-L" "/home/alex/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/i686-unknown-linux-gnu/lib" "foo.0.o" "-o" "foo" "-Wl,--gc-sections" "-pie" "-nodefaultlibs" "-L" "/home/alex/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/i686-unknown-linux-gnu/lib" "-Wl,-Bstatic" "-Wl,-Bdynamic" "/home/alex/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/i686-unknown-linux-gnu/lib/libstd-6eb85298.rlib" "/home/alex/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/i686-unknown-linux-gnu/lib/libpanic_unwind-6eb85298.rlib" "/home/alex/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/i686-unknown-linux-gnu/lib/libunwind-6eb85298.rlib" "/home/alex/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/i686-unknown-linux-gnu/lib/librand-6eb85298.rlib" "/home/alex/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/i686-unknown-linux-gnu/lib/libcollections-6eb85298.rlib" "/home/alex/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/i686-unknown-linux-gnu/lib/librustc_unicode-6eb85298.rlib" "/home/alex/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/i686-unknown-linux-gnu/lib/liballoc-6eb85298.rlib" "/home/alex/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/i686-unknown-linux-gnu/lib/liballoc_jemalloc-6eb85298.rlib" "/home/alex/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/i686-unknown-linux-gnu/lib/liblibc-6eb85298.rlib" "/home/alex/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/i686-unknown-linux-gnu/lib/libcore-6eb85298.rlib" "/home/alex/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/i686-unknown-linux-gnu/lib/libcompiler_builtins-6eb85298.rlib" "-l" "dl" "-l" "pthread" "-l" "gcc_s" "-l" "pthread" "-l" "c" "-l" "m" "-l" "rt" "-l" "util"
  = note: foo.0.o: In function `main':
foo.cgu-0.rs:(.text.main+0x2d): undefined reference to `std::rt::lang_start::h14cbded5fe3cd915'
collect2: error: ld returned 1 exit status
$ nm -g `rustc +nightly --print sysroot`/lib/rustlib/i686-unknown-linux-gnu/lib/libstd-*.rlib 2>&1 | grep lang_start | c++filt
00000000 T std::rt::lang_start::ha713258a8b5363bc

@alexcrichton alexcrichton reopened this Sep 30, 2016
@alexcrichton
Copy link
Member Author

@eddyb thoughts about any more vectors where a usize could leak in?

@eddyb
Copy link
Member

eddyb commented Sep 30, 2016

No idea. Do we do anything special about hashing slices? IIRC string slices get invalid Unicode separators, but what about otherl slices? Not that I can think of a place whwre we would use slices.

@alexcrichton
Copy link
Member Author

Looks like builtin_bounds is an EnumSet which contains a usize

@hanna-kruppe
Copy link
Contributor

Do we do anything special about hashing slices?

Yes, they hash their length.

@alexcrichton
Copy link
Member Author

I'm working on a patch

@alexcrichton alexcrichton removed the E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. label Sep 30, 2016
@TimNN
Copy link
Contributor

TimNN commented Sep 30, 2016

Maybe we can just hash all i,usizes as i,u64s in the Hasher implementation?

@alexcrichton
Copy link
Member Author

Indeed! I first tried to just panic and audit locations, but turns out there's a bunch, so I'm just auto-widening those to i/u64 now

@alexcrichton
Copy link
Member Author

Ok, I've confirmed that compiling hello world from 64 -> 32 works with #36866

@eddyb
Copy link
Member

eddyb commented Sep 30, 2016

@alexcrichton How can that be when you haven't fixed the symbol case?

alexcrichton added a commit to alexcrichton/rust that referenced this issue Sep 30, 2016
In another attempt to fix rust-lang#36793 this commit attempts to head off any future
problems by adding a custom `WidentUsizeHasher` which will widen any hashing of
`isize` and `usize` to a `u64` as necessary. This obviates the need for a
previous number of `as u64` annotations and will hopefully protect us against
future problems here.

Closes rust-lang#36793 (hopefully)
bors added a commit that referenced this issue Sep 30, 2016
rustc: More fixes for arch-independent hashing

In another attempt to fix #36793 this commit attempts to head off any future
problems by adding a custom `WidentUsizeHasher` which will widen any hashing of
`isize` and `usize` to a `u64` as necessary. This obviates the need for a
previous number of `as u64` annotations and will hopefully protect us against
future problems here.

Closes #36793 (hopefully)
jakllsch pushed a commit to jakllsch/rust that referenced this issue Oct 1, 2016
In another attempt to fix rust-lang#36793 this commit attempts to head off any future
problems by adding a custom `WidentUsizeHasher` which will widen any hashing of
`isize` and `usize` to a `u64` as necessary. This obviates the need for a
previous number of `as u64` annotations and will hopefully protect us against
future problems here.

Closes rust-lang#36793 (hopefully)
brson pushed a commit to brson/rust that referenced this issue Oct 19, 2016
In another attempt to fix rust-lang#36793 this commit attempts to head off any future
problems by adding a custom `WidentUsizeHasher` which will widen any hashing of
`isize` and `usize` to a `u64` as necessary. This obviates the need for a
previous number of `as u64` annotations and will hopefully protect us against
future problems here.

Closes rust-lang#36793 (hopefully)
@briansmith
Copy link
Contributor

IIUC, this bug breaks 64-bit -> 32-bit i686 builds on the beta channel. We are getting close to the release of Rust 1.13 and it would be good to see a beta build with the fixes soon so that projects (like mine) can make sure that we're fully compatible with the Rust 1.13 release in time to report any other (unrelated) issues.

@alexcrichton
Copy link
Member Author

@briansmith they've been a little slow to get out, but new beta builds are now available (as of a few hours ago)

@briansmith
Copy link
Contributor

@briansmith they've been a little slow to get out, but new beta builds are now available (as of a few hours ago

I confirmed that my builds are working with yesterday's beta build. Thanks!

@zeldin
Copy link

zeldin commented Dec 18, 2016

FYI: The current powerpc-unknown-linux-gnu build in the Beta channel (1.14) seems to be still affected by this:

hello.cgu-0.rs:(.text+0x118): undefined reference to `std::rt::lang_start::h0dc5391f6ca4a03d'

The symbol actually present in the library is std::rt::lang_start::h4c2460dd8e2a2db5

@eddyb
Copy link
Member

eddyb commented Dec 18, 2016

@zeldin Does the nightly work?

@zeldin
Copy link

zeldin commented Dec 18, 2016

No, the nightly has the same problem:

hello.cgu-0.rs:(.text+0x118): undefined reference to `std::rt::lang_start::h48234b6f50c3f490'

And the symbol in the library is std::rt::lang_start::hbf07045205cfddc7

@eddyb
Copy link
Member

eddyb commented Dec 18, 2016

cc @infinity0 @michaelwoerister

@michaelwoerister
Copy link
Member

PR #38357 refactored the symbol hashing code a bit. Maybe it accidentally broke something. We should check if this reappeared recently or was broken all along for these targets.

@michaelwoerister
Copy link
Member

Or maybe we fixed 32 bit vs 64 bit but not endianess (at least not all cases)?

@zeldin
Copy link

zeldin commented Feb 13, 2017

Current ppc32 nightly is working now, so I guess someone unbroke something again? 😄

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

Successfully merging a pull request may close this issue.

9 participants