Skip to content

Various symbols on win/apple are no longer weak after #598 #653

@aeubanks

Description

@aeubanks

After upgrading our rust toolchain version, on multiple win/apple platforms (arm64 win specifically for this error) we're seeing link errors like

../../third_party/llvm-build/Release+Asserts/bin/lld-link --rsp-quoting=posix "/OUT:./test_rust_metadata_cc_exe.exe" /nologo -libpath:../../third_party/llvm-build/Release+Asserts/lib/clang/20/lib/windows /winsysroot:../../third_party/depot_tools/win_toolchain/vs_files/7393122652 /MACHINE:ARM64  "/PDB:./test_rust_metadata_cc_exe.exe.pdb" "@./test_rust_metadata_cc_exe.exe.rsp"
lld-link: error: duplicate symbol: __udivti3
>>> defined at libcompiler_builtins_compiler_builtins.rlib(libcompiler_builtins_compiler_builtins.compiler_builtins.878e573648bac277-cgu.0.rcgu.o)
>>> defined at clang_rt.builtins-aarch64.lib(udivti3.c.obj)

lld-link: error: duplicate symbol: __umodti3
>>> defined at libcompiler_builtins_compiler_builtins.rlib(libcompiler_builtins_compiler_builtins.compiler_builtins.878e573648bac277-cgu.3.rcgu.o)
>>> defined at clang_rt.builtins-aarch64.lib(umodti3.c.obj)

lld-link: error: duplicate symbol: __muloti4
>>> defined at libcompiler_builtins_compiler_builtins.rlib(libcompiler_builtins_compiler_builtins.compiler_builtins.878e573648bac277-cgu.0.rcgu.o)
>>> defined at clang_rt.builtins-aarch64.lib(muloti4.c.obj)
ninja: build stopped: subcommand failed.

I believe this is due to #598. We were using the weak-intrinsics feature before. #598 removes that feature and makes everything weak by default, except for on win/apple platforms. That seems to be because some intrinsics unconditionally were not marked weak on win/apple. However, not all intrinsics were like that, e.g. the symbols in the error message above.

The following diff seems to make the error go away

diff --git a/src/macros.rs b/src/macros.rs
index fb14660..721d242 100644
--- a/src/macros.rs
+++ b/src/macros.rs
@@ -464,7 +464,7 @@ macro_rules! intrinsics {
         mod $name {
             $(#[$($attr)*])*
             #[no_mangle]
-            #[cfg_attr(all(not(windows), not(target_vendor = "apple")), linkage = "weak")]
+            #[linkage = "weak"]
             $(unsafe $($empty)?)? extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? {
                 super::$name($($argname),*)
             }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions