The Desert of Cargo, Xargo, and Circular Linking

Greetings,

I'm currently wandering through the desert of bringing up a new Rust target. I appear to be in the final linking stage, and I think I can see the end of the desert, though I may actually be experiencing a mirage.

With my current target specification, Xargo.toml and .cargo/config, I run into the following undefined references (paths abbreviated for brevity):

  = note: libc.a(calloc.o): In function `calloc':
          calloc.c:(.text+0x10): undefined reference to `__aeabi_uidiv'
          libpthread.a(attr.o): In function `pthread_attr_setguardsize':
          attr.c:(.text+0x150): undefined reference to `__aeabi_uidiv'
          libpthread.a(pthread.o): In function `__pthread_reset_main_thread':
          pthread.c:(.text+0x438): undefined reference to `_errno'
          pthread.c:(.text+0x43c): undefined reference to `_h_errno'
          libpthread.a(pthread.o): In function `pthread_initialize':
          pthread.c:(.text+0x790): undefined reference to `_errno'
          pthread.c:(.text+0x794): undefined reference to `_h_errno'
          pthread.c:(.text+0x798): undefined reference to `_stdio_user_locking'
          libpthread.a(pthread.o): In function `__pthread_initialize_minimal':
          pthread.c:(.text+0xb98): undefined reference to `__libc_pthread_init'
          libpthread.a(pthread.o):(.data+0x64): undefined reference to `_errno'
          libpthread.a(pthread.o):(.data+0x6c): undefined reference to `_h_errno'
          libpthread.a(cancel.o): In function `__pthread_perform_cleanup':
          cancel.c:(.text+0xc4): undefined reference to `__rpc_thread_destroy'
          collect2: ld returned 1 exit status

This seems rather odd because those symbols are defined in libc.a and I'm already linking against libc with -lc (twice in fact, once from late-link-args and another from a dependent crate?) in the final linking statement. However in the desert nothing is as it appears.

My current solution for moving past this linking issue is to take the actual linking command that xargo failed on and perform some manual manipulations. I did the following:

  • Moved the linking requests "-lgcc" "-lc" "-lm" "-lrt" "-lpthread" "-lc" from the end of the linking command to the list of archives that contains all the *.rlib files. It seems this combination of libraries need to be included in the circular linking process.
  • removed the -lc linking statements and replaced them with the absolute path of libc.a

These changes allowed me to exchange my undefined references for multiple definitions (paths shortened):

.xargo/../thumbv7m-unknown-linux-uclibc/../libcompiler_builtins-d56d77cbe1821960.rlib(compiler_builtins-d56d77cbe1821960.compiler_builtins.2whiafxq-cgu.3.rcgu.o): In function `__udivdi3':
compiler_builtins.2whiafxq-cgu.3:(.text.__udivdi3+0x0): multiple definition of `__udivdi3'
/toolchain_path/lib/gcc/arm-uclinuxeabi/4.4.1/thumb2/libgcc.a(_udivdi3.o):libgcc2.c:(.text+0x0): first defined here
.xargo/../thumbv7m-unknown-linux-uclibc/../libcompiler_builtins-d56d77cbe1821960.rlib(compiler_builtins-d56d77cbe1821960.compiler_builtins.2whiafxq-cgu.3.rcgu.o): In function `__udivsi3':
compiler_builtins.2whiafxq-cgu.3:(.text.__udivsi3+0x0): multiple definition of `__udivsi3'
/toolchain_path/lib/gcc/arm-uclinuxeabi/4.4.1/thumb2/libgcc.a(_udivsi3.o):(.text+0x0): first defined here
.xargo/../thumbv7m-unknown-linux-uclibc/../libcompiler_builtins-d56d77cbe1821960.rlib(compiler_builtins-d56d77cbe1821960.compiler_builtins.2whiafxq-cgu.9.rcgu.o): In function `__divsi3':
compiler_builtins.2whiafxq-cgu.9:(.text.__divsi3+0x0): multiple definition of `__divsi3'
/toolchain_path/lib/gcc/arm-uclinuxeabi/4.4.1/thumb2/libgcc.a(_divsi3.o):(.text+0x0): first defined here

I removed command to link in libcompiler_builtins.rlib and things progressed to a post linking error that I won't discuss here haha.

So here is my problem: I have manually "fixed" the linking command, but I'm not sure how to bring these changes back into the proper xargo/cargo build process. I'm not even sure if these changes were legitimate or if I've just been deluded by the hot desert sun. This is my SOS. Look for the bearded man with the crazy look in his eyes.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.