-
Notifications
You must be signed in to change notification settings - Fork 249
Closed
Description
Similar to #412, on armv7-unknown-linux-gnueabihf we get symbols __sync_fetch_and_add_4 and __sync_fetch_and_add_8 (and probably others) clashing when a C/C++ tries to link with our library. We've tried on arm-unknown-linux-gnueabihf, aarch64-unknown-linux-gnu and x86_64-unknown-linux-gnu and it doesn't seem to generate these symbols.
On Zulip, Alex Crichton suggested to flag the symbol as weak. This issue is off my level of competence, so I'll probably leave it to someone who knows better than me.
Some links that I've found while investigating this (for cross-reference):
Activity
Amanieu commentedon May 25, 2021
The solution is the same as #412: each intrinsic needs to be defined in its own
mod, so that rustc can put each function in a separate object file. This will fix the linker errors.armv7-linux-androideabistaticlib targets starting with rustc 1.54 rust#93310armv7-linux-androideabiincludes multiple definitions of__sync_fetch_and_add_4#449Amanieu commentedon 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.
joelriendeau commentedon Mar 2, 2022
Hi @Amanieu, I'm encountering the same issue on the nightly (today's version) for armv5te-unknown-linux-musleabi.
/opt/arm-buildroot-linux-musleabi_sdk-buildroot/bin/../lib/gcc/arm-buildroot-linux-musleabi/11.2.0/../../../../arm-buildroot-linux-musleabi/bin/ld: /opt/arm-buildroot-linux-musleabi_sdk-buildroot/bin/../lib/gcc/arm-buildroot-linux-musleabi/11.2.0/libgcc.a(linux-atomic.o): in function
__sync_fetch_and_add_4': /root/wsl/sfl_buildroot/buildroot/output/build/host-gcc-final-11.2.0/build/arm-buildroot-linux-musleabi/libgcc/../../../libgcc/config/arm/linux-atomic.c:116: multiple definition of__sync_fetch_and_add_4'; ../../../modules/leodream/leodream/armv5te-unknown-linux-musleabi/release/libleodream.a(compiler_builtins-ed49ad36634beb21.compiler_builtins.22da61b5-cgu.66.rcgu.o):/cargo/registry/src/github.com-1ecc6299db9ec823/compiler_builtins-0.1.70/src/macros.rs:360: first defined here/opt/arm-buildroot-linux-musleabi_sdk-buildroot/bin/../lib/gcc/arm-buildroot-linux-musleabi/11.2.0/../../../../arm-buildroot-linux-musleabi/bin/ld: /opt/arm-buildroot-linux-musleabi_sdk-buildroot/bin/../lib/gcc/arm-buildroot-linux-musleabi/11.2.0/libgcc.a(linux-atomic.o): in function
__sync_synchronize': /root/wsl/sfl_buildroot/buildroot/output/build/host-gcc-final-11.2.0/build/arm-buildroot-linux-musleabi/libgcc/../../../libgcc/config/arm/linux-atomic.c:277: multiple definition of__sync_synchronize'; ../../../modules/leodream/leodream/armv5te-unknown-linux-musleabi/release/libleodream.a(compiler_builtins-ed49ad36634beb21.compiler_builtins.22da61b5-cgu.201.rcgu.o):/cargo/registry/src/github.com-1ecc6299db9ec823/compiler_builtins-0.1.70/src/macros.rs:360: first defined herIs there anything I can do?
package/pkg-cargo.mk: fix building cargo packages on 32bit arm
snowp commentedon Apr 28, 2022
@Amanieu Hitting this issue on x86_64-apple-ios and moving to Rust 1.60.0 (which I believe includes the proposed fix) does not seem to fix it.
What is the general advice here? Should we weaken the compiler_builtins symbols in favor of the libclang_rt ones? Are these symbols considered compatible enough that Rust code depending on the compiler builtin ones can safely use the clang ones instead?
bjorn3 commentedon Apr 28, 2022
We should already put all compiler_builtins symbols in separate object files and the linker should only pull in object files from archives if at least one symbol in them is referenced. Together this should mean that only either the object file providing this from compiler_builtins or libclang_rt should be pulled in and not both. I'm not sure where it goes wrong though that would cause this issue. If I locally try to list which object files in libcompiler_builtins.rlib provide which symbols it looks like
___mulodi4and___mulosi4are provided by separate object files that don't provide any other symbols which is indeed how it should be.Yes, in fact they should be identical between clang and gcc even.
keith commentedon Apr 28, 2022
The issue in this case is the link is using
-all_loadto force all objects from all archives to be loaded. In our project this saves roughly 10% of link time, so it's a build performance optimization for debug builds. I imagine if the symbols could be weak it would actually remove the need for the separate object files, but I'm not sure?bjorn3 commentedon Apr 28, 2022
I see. compiler_builtins indeed needs to be linked without
-force_load(which-all_loadimplies for all archives) to prevent this kind of symbol conflicts. Would it be possible to explicitly use-force_loadjust for the non-rust libraries? Or is the rust part of your project large enough that that would negate all benefits of-all_load?Support for weak symbols is rather spotty across platforms I believe and the exact behavior differs between platforms.
keith commentedon Apr 28, 2022
Ideally that would be possible but practically in the build system it would be difficult to add that for every single one of the transitive libraries, which is why we take the
-all_loadapproach instead. I do wish I could do-all_load -no_force_load compiler_builtins.rlibas well.Ah yea fair enough. Do you see any other downsides to doing weak symbols as well as the current solution? That would satisfy this use case for macho at least (although maybe it only apply to the one format is enough to not do it to not cause confusion)
bjorn3 commentedon Apr 29, 2022
Not sure.
hgy59 commentedon Jun 24, 2022
facing this issue too, when building fd-find (https://github.com/sharkdp/fd/) version 8.4.0 for
armv5te-unknown-linux-gnueabi.AdrianBunk commentedon Oct 8, 2022
The file is
arm_linux.rs(and the weak attribute is already used insrc/arm.rs).Linux on ARM is a pretty limited scope, and there are other widespread usages like glibc used to provide weak versions of pthread symbols in libc.so for decades (that changed recently for unrelated reasons when libpthread was merged into libc).
8 remaining items