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

Mips (big endian) gives "undefined reference to `std::rt::lang_start'" #42239

Closed
jcowgill opened this issue May 26, 2017 · 4 comments · Fixed by #42335
Closed

Mips (big endian) gives "undefined reference to `std::rt::lang_start'" #42239

jcowgill opened this issue May 26, 2017 · 4 comments · Fixed by #42335

Comments

@jcowgill
Copy link
Contributor

Attempting to compile this example program foo.rs using a nightly compiler:

fn main() {}

On a native mips big endian machine gives me this:

error: linking with `cc` failed: exit code: 1
  |
  = note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-L" "/usr/local/lib/rustlib/mips-unknown-linux-gnu/lib" "foo.0.o" "-o" "foo" "-Wl,--gc-sections" "-pie" "-nodefaultlibs" "-L" "/usr/local/lib/rustlib/mips-unknown-linux-gnu/lib" "-Wl,-Bstatic" "/usr/local/lib/rustlib/mips-unknown-linux-gnu/lib/libstd-8bd0331885bb8f82.rlib" "/usr/local/lib/rustlib/mips-unknown-linux-gnu/lib/librand-c59b047c329fc869.rlib" "/usr/local/lib/rustlib/mips-unknown-linux-gnu/lib/libpanic_unwind-8b5a5d5d9b47b90e.rlib" "/usr/local/lib/rustlib/mips-unknown-linux-gnu/lib/libcollections-940fff481f9db1f7.rlib" "/usr/local/lib/rustlib/mips-unknown-linux-gnu/lib/liballoc-00bc69f25a7886ed.rlib" "/usr/local/lib/rustlib/mips-unknown-linux-gnu/lib/liballoc_system-8a70e0fa55025ef9.rlib" "/usr/local/lib/rustlib/mips-unknown-linux-gnu/lib/libunwind-6f736b1bf227d828.rlib" "/usr/local/lib/rustlib/mips-unknown-linux-gnu/lib/liblibc-0d4b94d34314ddab.rlib" "/usr/local/lib/rustlib/mips-unknown-linux-gnu/lib/libstd_unicode-27c6703fdb4bd5ba.rlib" "/usr/local/lib/rustlib/mips-unknown-linux-gnu/lib/libcore-f7c6aa272ea55579.rlib" "/usr/local/lib/rustlib/mips-unknown-linux-gnu/lib/libcompiler_builtins-93f6c14c48cd2162.rlib" "-Wl,-Bdynamic" "-l" "dl" "-l" "rt" "-l" "pthread" "-l" "gcc_s" "-l" "c" "-l" "m" "-l" "rt" "-l" "pthread" "-l" "util"
  = note: foo.0.o: In function `main':
          foo.cgu-0.rs:(.text.main+0x34): undefined reference to `std::rt::lang_start'
          collect2: error: ld returned 1 exit status


error: aborting due to previous error(s)

If I compile foo.rs to an object and dump the symbols, I see that the hash for lang_start is different between the object and the rlib file:

$ objdump -t foo.o | grep lang_start
00000000         *UND*  00000000 _ZN3std2rt10lang_start17h826655afc17b8ea3E

$ objdump -t /usr/local/lib/rustlib/mips-unknown-linux-gnu/lib/libstd-8bd0331885bb8f82.rlib | grep lang_start
00000000 l    d  .text._ZN3std2rt10lang_start17h5492aeb665e2d414E       00000000 .text._ZN3std2rt10lang_start17h5492aeb665e2d414E
00000000 g     F .text._ZN3std2rt10lang_start17h5492aeb665e2d414E       00000aec _ZN3std2rt10lang_start17h5492aeb665e2d414E

After some debugging, I managed to work out that the value of tcx.def_path_hash(def_id) for lang_start passed to the TypeIdHasher in rustc_trans::back::symbol_names::get_symbol_hash is byteswapped when run natively compared to running on an x86 -> mips cross compiler. I couldn't work out where this value originally comes from, but hopefully someone here knows. :)

I also tried using a stable compiler, but it failed with the issue #41471 before getting to this stage.

@est31
Copy link
Member

est31 commented May 27, 2017

cc @japaric

@arielb1
Copy link
Contributor

arielb1 commented May 27, 2017

I don't have a MIPS machine right here, but it certainly looks that def_path_hash should be returning a Fingerprint, which should be endianness-correct (i.e. return the same 2 u64s) - https://github.com/rust-lang/rust/blob/master/src/librustc/ich/fingerprint.rs#L68.

@arielb1
Copy link
Contributor

arielb1 commented May 27, 2017

@jcowgill

Does beta work, btw?

@jcowgill
Copy link
Contributor Author

@arielb1
It looks like #41471 affects beta as well. I get the same error as on stable - this is with: rustc 1.18.0-beta.4 (0308c9865 2017-05-27)

jcowgill added a commit to jcowgill/rust that referenced this issue Jun 1, 2017
Byteswapping Fingerprints when encoding is unnessesary and breaks if
the Fingerprint is later decoded on a machine with different endianness
to the one it was encoded on. Fix by removing the Encodable and
Decodable implementations and use the ones derived from RustcEncodable
and RustcDecodable.

Fixes rust-lang#42239
Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this issue Jun 1, 2017
…oerister

Don't byteswap Fingerprints when encoding

Byteswapping Fingerprints when encoding is unnessesary and breaks if the Fingerprint is later decoded on a machine with different endianness to the one it was encoded on.

Fixes rust-lang#42239

This PR fixes a regression caused by rust-lang#42082. @michaelwoerister
Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this issue Jun 1, 2017
…oerister

Don't byteswap Fingerprints when encoding

Byteswapping Fingerprints when encoding is unnessesary and breaks if the Fingerprint is later decoded on a machine with different endianness to the one it was encoded on.

Fixes rust-lang#42239

This PR fixes a regression caused by rust-lang#42082. @michaelwoerister
Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this issue Jun 2, 2017
…oerister

Don't byteswap Fingerprints when encoding

Byteswapping Fingerprints when encoding is unnessesary and breaks if the Fingerprint is later decoded on a machine with different endianness to the one it was encoded on.

Fixes rust-lang#42239

This PR fixes a regression caused by rust-lang#42082. @michaelwoerister
Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this issue Jun 2, 2017
…oerister

Don't byteswap Fingerprints when encoding

Byteswapping Fingerprints when encoding is unnessesary and breaks if the Fingerprint is later decoded on a machine with different endianness to the one it was encoded on.

Fixes rust-lang#42239

This PR fixes a regression caused by rust-lang#42082. @michaelwoerister
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

Successfully merging a pull request may close this issue.

3 participants