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

Multiple definition of '__aeabi_uidivmod' and '__aeabi_uldivmod' on arm-linux-androideabi #412

Closed
petrochenkov opened this issue Apr 10, 2021 · 5 comments

Comments

@petrochenkov
Copy link
Contributor

In rust-lang/rust#83822 I attempted to remove the --allow-multiple-definition linker hack from Android target specs in rustc, but observed the next linking error:

error: linking with `/android/ndk/arm-14/bin/arm-linux-androideabi-clang` failed: exit status: 1
  |
  = note: "/android/ndk/arm-14/bin/arm-linux-androideabi-clang" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-Wl,--as-needed" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/arm-linux-androideabi/lib" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-std/arm-linux-androideabi/release/deps/std-aa02b9ba56c47188.std.1gj5x857-cgu.0.rcgu.o" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-std/arm-linux-androideabi/release/deps/libstd-aa02b9ba56c47188.so" "-Wl,--version-script=/tmp/rustcsKqBUX/list" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-std/arm-linux-androideabi/release/deps/std-aa02b9ba56c47188.550hwdqflrivilit.rcgu.o" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-std/arm-linux-androideabi/release/deps/std-aa02b9ba56c47188.f3uuzluee2cbevv.rcgu.o" "-shared" "-Wl,-zrelro" "-Wl,-znow" "-Wl,-O1" "-nodefaultlibs" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-std/arm-linux-androideabi/release/deps" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-std/release/deps" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-std/arm-linux-androideabi/release/build/compiler_builtins-0cc9b3ede123fcbb/out" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-std/arm-linux-androideabi/release/build/profiler_builtins-f00fa99f86511a66/out" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/arm-linux-androideabi/lib" "-ldl" "-llog" "-lgcc" "-Wl,-Bstatic" "-Wl,--whole-archive" "/tmp/rustcsKqBUX/libpanic_unwind-53a82f532deef78c.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustcsKqBUX/libminiz_oxide-5ae569e4d71b98f2.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustcsKqBUX/libadler-480e8a29cd327522.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustcsKqBUX/libobject-818d6dece30befc6.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustcsKqBUX/libaddr2line-83e55526cd23350a.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustcsKqBUX/libgimli-d880f99d5b85d10a.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustcsKqBUX/librustc_demangle-cd2642fb698e70d6.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustcsKqBUX/libhashbrown-a9c6975bf97337e1.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustcsKqBUX/librustc_std_workspace_alloc-12a29a9bfdad4d51.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustcsKqBUX/libunwind-7de75771c758f0b5.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustcsKqBUX/libcfg_if-7dbf72bdfaf506c0.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustcsKqBUX/liblibc-f48e19d6fccfbd3c.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustcsKqBUX/liballoc-cddf24203f98dfca.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustcsKqBUX/librustc_std_workspace_core-751cff066ed2ddff.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustcsKqBUX/libcore-61aecf05f20b0be0.rlib" "-Wl,--no-whole-archive" "/tmp/rustcsKqBUX/libcompiler_builtins-fa77a8df7f01d459.rlib" "-Wl,-Bdynamic" "-lc" "-lm" "-Wl,-rpath,$ORIGIN/../lib"
  = note: /android/ndk/arm-14/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: /tmp/rustcsKqBUX/libcompiler_builtins-fa77a8df7f01d459.rlib(compiler_builtins-fa77a8df7f01d459.compiler_builtins.1pwrvrkl-cgu.55.rcgu.o): multiple definition of '__aeabi_uidivmod'
          /android/ndk/arm-14/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: /android/ndk/arm-14/bin/../lib/gcc/arm-linux-androideabi/4.9.x/armv7-a/libgcc.a(_udivsi3.o): previous definition here
          /android/ndk/arm-14/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: /tmp/rustcsKqBUX/libcompiler_builtins-fa77a8df7f01d459.rlib(compiler_builtins-fa77a8df7f01d459.compiler_builtins.1pwrvrkl-cgu.55.rcgu.o): multiple definition of '__aeabi_uldivmod'
          /android/ndk/arm-14/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: /android/ndk/arm-14/bin/../lib/gcc/arm-linux-androideabi/4.9.x/armv7-a/libgcc.a(_aeabi_uldivmod.o): previous definition here
          clang50: error: linker command failed with exit code 1 (use -v to see invocation)

Previously compiler-builtins fixed similar errors on other targets by putting symbols to separate object files or changing linking order.

It would be great to fix this case as well, and remove --allow-multiple-definition from Android target specs.
That option is a really heavy hammer used when everything is on fire but you still need to make things work, and it is able to hide legitimate errors.

@Amanieu
Copy link
Member

Amanieu commented Apr 10, 2021

compiler-builtins should be getting built with maximal codegen units (enabled by the #![cfg_attr(feature = "compiler-builtins", compiler_builtins)] at the top of the crate).

This should result in every function getting built in a separate object file, but it doesn't seem to be happening here for some reason: the linker error shows that both __aeabi_uidivmod and __aeabi_uldivmod are located in the same object file compiler_builtins-fa77a8df7f01d459.compiler_builtins.1pwrvrkl-cgu.55.rcgu.o.

@bjorn3
Copy link
Member

bjorn3 commented Apr 10, 2021

The functions are not placed in their own module. Rustc starts codegen unit partitioning with modules, not individual functions. The intrinsics! macro does this automatically:

pub mod $name {
$(#[$($attr)*])*
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
pub extern $abi fn $name( $($argname: $ty),* ) -> $ret {
super::$name($($argname),*)
}
}

@d3zd3z
Copy link

d3zd3z commented Jun 30, 2021

I am encountering this same issue trying to build a Zephyr application in Rust. I was able to workaround it by changing the Zephyr build system to place -lgcc after the .a for my Rust application.

@Amanieu
Copy link
Member

Amanieu commented Feb 6, 2022

Hopefully this should be fixed by #452 which will be included in rust-lang/rust#93696. Please try it in the next nightly once that is merged.

@petrochenkov
Copy link
Contributor Author

This issue was fixed, and --allow-multiple-definition was removed from Android targets.

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

No branches or pull requests

4 participants