Skip to content

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

Closed
@jcowgill

Description

@jcowgill

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions