Skip to content

Link errors on MSVC Nightly since around 2019-07-13 #63361

Closed

Description

@novacrazy

Any crate that uses std::sync::Arc fails to compile with a link error saying unresolved external symbol __atomic_fetch_sub_8

Test case on rustc 1.38.0-nightly (6a91782b7 2019-08-06)

fn main() {
    let test = std::sync::Arc::new(32);
}

outputs:

link_error-44aa39a2e793d984.29ne1tatqckt0j9r.rcgu.o : error LNK2019: unresolved external symbol __atomic_fetch_sub_8 referenced in function _ZN4core4sync6atomic10atomic_sub17hb46c24bb21c6d0b1E

or from a bigger project:

build_script_build-10d0cb3662789960.build_script_build.brrzdj7n-cgu.18.rcgu.o : error LNK2019: unresolved external symbol __atomic_fetch_sub_8 referenced in function
_ZN5alloc4sync12Arc$LT$T$GT$9drop_slow17h215332bbcf7e5cb5E
          build_script_build-10d0cb3662789960.build_script_build.brrzdj7n-cgu.20.rcgu.o : error LNK2001: unresolved external symbol __atomic_fetch_sub_8
          F:\code\projects\active\untitled\target\debug\build\byteorder-10d0cb3662789960\build_script_build-10d0cb3662789960.exe : fatal error LNK1120: 1 unresolved externals

Nightly rustc 1.38.0-nightly (4bb6b4a5e 2019-07-11)/nightly-2019-07-12-x86_64-pc-windows-msvc works totally fine.

Activity

  1. Mark-Simulacrum commented on Aug 7, 2019

    @Mark-Simulacrum
    Member

    Is this reproducible after cargo clean?

  2. added
    E-needs-bisectionCall for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc
    O-windows-msvcToolchain: MSVC, Operating system: Windows
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Aug 7, 2019
  3. novacrazy commented on Aug 7, 2019

    @novacrazy
    ContributorAuthor

    Yes, happens on a fresh project I made for testing (cargo new) and after cargo clean

  4. Mark-Simulacrum commented on Aug 7, 2019

    @Mark-Simulacrum
    Member

    4bb6b4a...6a91782 is the full commit range, which notably includes an LLVM upgrade #62592 -- cc @nikic

    Could you check with https://crates.io/crates/rustup-toolchain-install-master/ if 07e0c36 is fine and 38798c6 is broken for you?

  5. novacrazy commented on Aug 7, 2019

    @novacrazy
    ContributorAuthor

    I can confirm that 07e0c36 works fine but 38798c6 is broken.

    Also, that's a nifty tool.

  6. Mark-Simulacrum commented on Aug 7, 2019

    @Mark-Simulacrum
    Member

    Okay, LLVM update is then definitely at fault, cc @alexcrichton

  7. ollie27 commented on Aug 7, 2019

    @ollie27
    Contributor

    With default settings I'm not reproducing this locally with rustc 1.38.0-nightly (6a91782b7 2019-08-06) on x86_64-pc-windows-msvc. Do you have any rustflags set in your cargo config or RUSTFLAGS environment variable? What is the full output of cargo build --verbose?

  8. novacrazy commented on Aug 7, 2019

    @novacrazy
    ContributorAuthor

    Here is the full failing output from cargo build --verbose

    Details
    PS F:\code\projects\bugs\link-error> cargo +38798c6d68394874686dfa3d03e56e12a3ff3d54 build --verbose
       Compiling link-error v0.1.0 (F:\code\projects\bugs\link-error)
         Running `rustc --edition=2018 --crate-name link_error src\main.rs --color always --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=b27e03e5a815a5d1 -C extra-filename=-b27e03e5a815a5d1 --out-dir F:\code\projects\bugs\link-error\target\debug\deps -C incremental=F:\code\projects\bugs\link-error\target\debug\incremental -L dependency=F:\code\projects\bugs\link-error\target\debug\deps -C target-cpu=native`
    warning: unused variable: `test`
     --> src\main.rs:2:9
      |
    2 |     let test = std::sync::Arc::new(32);
      |         ^^^^ help: consider prefixing with an underscore: `_test`
      |
      = note: #[warn(unused_variables)] on by default
    
    error: linking with `link.exe` failed: exit code: 1120
      |
      = note: "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.16.27023\\bin\\HostX64\\x64\\link.exe" "/NOLOGO" "/NXCOMPAT" "/LIBPATH:C:\\Users\\novacrazy\\.rustup\\toolchains\\38798c6d68394874686dfa3d03e56e12a3ff3d54\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "F:\\code\\projects\\bugs\\link-error\\target\\debug\\deps\\link_error-b27e03e5a815a5d1.1awbet0zrarqk6zk.rcgu.o" "F:\\code\\projects\\bugs\\link-error\\target\\debug\\deps\\link_error-b27e03e5a815a5d1.1dxr01vrw6o44v8d.rcgu.o" "F:\\code\\projects\\bugs\\link-error\\target\\debug\\deps\\link_error-b27e03e5a815a5d1.1fpix7q2qm1wmx5m.rcgu.o" "F:\\code\\projects\\bugs\\link-error\\target\\debug\\deps\\link_error-b27e03e5a815a5d1.1s1iizs3eh6qnigf.rcgu.o" "F:\\code\\projects\\bugs\\link-error\\target\\debug\\deps\\link_error-b27e03e5a815a5d1.1tjwswr407orue5r.rcgu.o" "F:\\code\\projects\\bugs\\link-error\\target\\debug\\deps\\link_error-b27e03e5a815a5d1.1y7gpfx9xaq8bpjo.rcgu.o" "F:\\code\\projects\\bugs\\link-error\\target\\debug\\deps\\link_error-b27e03e5a815a5d1.25g5g8r4a01smim3.rcgu.o" "F:\\code\\projects\\bugs\\link-error\\target\\debug\\deps\\link_error-b27e03e5a815a5d1.2g805zhrwczbb193.rcgu.o" "F:\\code\\projects\\bugs\\link-error\\target\\debug\\deps\\link_error-b27e03e5a815a5d1.2k5f5cynwdkqbn68.rcgu.o" "F:\\code\\projects\\bugs\\link-error\\target\\debug\\deps\\link_error-b27e03e5a815a5d1.3ghs4gwhwch7ener.rcgu.o" "F:\\code\\projects\\bugs\\link-error\\target\\debug\\deps\\link_error-b27e03e5a815a5d1.3gt2eqgods8mcyg6.rcgu.o" "F:\\code\\projects\\bugs\\link-error\\target\\debug\\deps\\link_error-b27e03e5a815a5d1.3t2kk55q0g0e2cko.rcgu.o" "F:\\code\\projects\\bugs\\link-error\\target\\debug\\deps\\link_error-b27e03e5a815a5d1.3yjyt4nba10t386r.rcgu.o" "F:\\code\\projects\\bugs\\link-error\\target\\debug\\deps\\link_error-b27e03e5a815a5d1.41rvjzz983qpd0h8.rcgu.o" "F:\\code\\projects\\bugs\\link-error\\target\\debug\\deps\\link_error-b27e03e5a815a5d1.4l7t5gfqknkiv69w.rcgu.o" "F:\\code\\projects\\bugs\\link-error\\target\\debug\\deps\\link_error-b27e03e5a815a5d1.4rer12768bc7ik0p.rcgu.o" "F:\\code\\projects\\bugs\\link-error\\target\\debug\\deps\\link_error-b27e03e5a815a5d1.4srnky4m519x1ojk.rcgu.o" "F:\\code\\projects\\bugs\\link-error\\target\\debug\\deps\\link_error-b27e03e5a815a5d1.4x1ga75z1pvtzhx8.rcgu.o" "F:\\code\\projects\\bugs\\link-error\\target\\debug\\deps\\link_error-b27e03e5a815a5d1.5gujwewf933r84vr.rcgu.o" "F:\\code\\projects\\bugs\\link-error\\target\\debug\\deps\\link_error-b27e03e5a815a5d1.mfdrxcq31397ia.rcgu.o" "/OUT:F:\\code\\projects\\bugs\\link-error\\target\\debug\\deps\\link_error-b27e03e5a815a5d1.exe" "F:\\code\\projects\\bugs\\link-error\\target\\debug\\deps\\link_error-b27e03e5a815a5d1.1id0re3mvkfyrv57.rcgu.o" "/OPT:REF,NOICF" "/DEBUG" "/NATVIS:C:\\Users\\novacrazy\\.rustup\\toolchains\\38798c6d68394874686dfa3d03e56e12a3ff3d54\\lib\\rustlib\\etc\\intrinsic.natvis" "/NATVIS:C:\\Users\\novacrazy\\.rustup\\toolchains\\38798c6d68394874686dfa3d03e56e12a3ff3d54\\lib\\rustlib\\etc\\liballoc.natvis" "/NATVIS:C:\\Users\\novacrazy\\.rustup\\toolchains\\38798c6d68394874686dfa3d03e56e12a3ff3d54\\lib\\rustlib\\etc\\libcore.natvis" "/LIBPATH:F:\\code\\projects\\bugs\\link-error\\target\\debug\\deps" "/LIBPATH:C:\\Users\\novacrazy\\.rustup\\toolchains\\38798c6d68394874686dfa3d03e56e12a3ff3d54\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "C:\\Users\\novacrazy\\.rustup\\toolchains\\38798c6d68394874686dfa3d03e56e12a3ff3d54\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd-b566626ebe749075.rlib" "C:\\Users\\novacrazy\\.rustup\\toolchains\\38798c6d68394874686dfa3d03e56e12a3ff3d54\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libpanic_unwind-753783a0225bcab0.rlib" "C:\\Users\\novacrazy\\.rustup\\toolchains\\38798c6d68394874686dfa3d03e56e12a3ff3d54\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libbacktrace-f2388b9a738be1c1.rlib" "C:\\Users\\novacrazy\\.rustup\\toolchains\\38798c6d68394874686dfa3d03e56e12a3ff3d54\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_demangle-ab8bf9eb113bad40.rlib" "C:\\Users\\novacrazy\\.rustup\\toolchains\\38798c6d68394874686dfa3d03e56e12a3ff3d54\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libhashbrown-1d47f4d5d4c55f29.rlib" "C:\\Users\\novacrazy\\.rustup\\toolchains\\38798c6d68394874686dfa3d03e56e12a3ff3d54\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_std_workspace_alloc-968848331328bf94.rlib" "C:\\Users\\novacrazy\\.rustup\\toolchains\\38798c6d68394874686dfa3d03e56e12a3ff3d54\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libunwind-c563f0a9c23be7f0.rlib" "C:\\Users\\novacrazy\\.rustup\\toolchains\\38798c6d68394874686dfa3d03e56e12a3ff3d54\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcfg_if-7d399886811af5b8.rlib" "C:\\Users\\novacrazy\\.rustup\\toolchains\\38798c6d68394874686dfa3d03e56e12a3ff3d54\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liblibc-3aae73859accfdc5.rlib" "C:\\Users\\novacrazy\\.rustup\\toolchains\\38798c6d68394874686dfa3d03e56e12a3ff3d54\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liballoc-a669c0bcf77807e0.rlib" "C:\\Users\\novacrazy\\.rustup\\toolchains\\38798c6d68394874686dfa3d03e56e12a3ff3d54\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_std_workspace_core-111392f21d7931f2.rlib" "C:\\Users\\novacrazy\\.rustup\\toolchains\\38798c6d68394874686dfa3d03e56e12a3ff3d54\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcore-1df959b2344278a7.rlib" "C:\\Users\\novacrazy\\.rustup\\toolchains\\38798c6d68394874686dfa3d03e56e12a3ff3d54\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcompiler_builtins-1e2dcdf34bb26038.rlib" "advapi32.lib" "ws2_32.lib" "userenv.lib" "msvcrt.lib"
      = note: link_error-b27e03e5a815a5d1.3t2kk55q0g0e2cko.rcgu.o : error LNK2019: unresolved external symbol __atomic_fetch_sub_8 referenced in function _ZN4core4sync6atomic10atomic_sub17hd23c128025f91fd5E
              F:\code\projects\bugs\link-error\target\debug\deps\link_error-b27e03e5a815a5d1.exe : fatal error LNK1120: 1 unresolved externals
    
    
    error: aborting due to previous error
    
    error: Could not compile `link-error`.
    
    Caused by:
      process didn't exit successfully: `rustc --edition=2018 --crate-name link_error src\main.rs --color always --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=b27e03e5a815a5d1 -C extra-filename=-b27e03e5a815a5d1 --out-dir F:\code\projects\bugs\link-error\target\debug\deps -C incremental=F:\code\projects\bugs\link-error\target\debug\incremental -L dependency=F:\code\projects\bugs\link-error\target\debug\deps -C target-cpu=native` (exit code: 1)
    

    Indeed, my RUSTFLAGS are set to $env:RUSTFLAGS = "-C target-cpu=native"

    Testing again without -C target-cpu=native does not error, and compiles/runs fine.

  9. novacrazy commented on Aug 7, 2019

    @novacrazy
    ContributorAuthor

    If it helps, I'm on AMD Zen v1, or target-cpu=znver1, and it looks like znver2 was introduced in the LLVM upgrade.

  10. mati865 commented on Aug 8, 2019

    @mati865
    Member

    Fails the same way on Linux (GNU and musl) and Windows GNU using RUSTFLAGS="-C target-cpu=native" cargo run on Ryzen 2700X platform so it probably affects all the OSes.

    Details
      = note: /usr/bin/ld: /home/mateusz/tmp/zen_test/target/debug/deps/zen_test-192eddefb9cd5b11.3p9u9xvxudj8dh99.rcgu.o: in function `core::sync::atomic::atomic_sub':
              /rustc/ad7c55e1fc55d9af4787b285cec1c64e3480ae84/src/libcore/sync/atomic.rs:2165: undefined reference to `__atomic_fetch_sub_8'
              /usr/bin/ld: /rustc/ad7c55e1fc55d9af4787b285cec1c64e3480ae84/src/libcore/sync/atomic.rs:2161: undefined reference to `__atomic_fetch_sub_8'
              /usr/bin/ld: /rustc/ad7c55e1fc55d9af4787b285cec1c64e3480ae84/src/libcore/sync/atomic.rs:2162: undefined reference to `__atomic_fetch_sub_8'
              /usr/bin/ld: /rustc/ad7c55e1fc55d9af4787b285cec1c64e3480ae84/src/libcore/sync/atomic.rs:2163: undefined reference to `__atomic_fetch_sub_8'
              /usr/bin/ld: /rustc/ad7c55e1fc55d9af4787b285cec1c64e3480ae84/src/libcore/sync/atomic.rs:2164: undefined reference to `__atomic_fetch_sub_8'
              collect2: error: ld returned 1 exit status
    

    @rustbot modify labels: -E-needs-bisection -O-windows-msvc +O-linux +O-windows +A-LLVM

  11. removed
    E-needs-bisectionCall for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc
    O-windows-msvcToolchain: MSVC, Operating system: Windows
    on Aug 8, 2019
  12. 1 remaining item

  13. alexcrichton commented on Aug 8, 2019

    @alexcrichton
    Member

    This seems like LLVM's auto-detection of what CPU is on the host or what the target features your native CPU has may be broken. The next step for this is to probably use a build of Clang to reproduce and then report this upstream to LLVM itself.

  14. alexcrichton commented on Aug 8, 2019

    @alexcrichton
    Member

    Er sorry I have a guess as to where this is but I do not have time to investigate this right now, so I'm going to unassign myself since I can't take care of this.

  15. removed their assignment
    on Aug 8, 2019
  16. added
    A-linkageArea: linking into static, shared libraries and binaries
    C-bugCategory: This is a bug.
    on Aug 8, 2019
  17. mati865 commented on Aug 8, 2019

    @mati865
    Member

    Minimised:

    use std::sync::atomic::{AtomicU64, Ordering};
    
    fn main() {
        AtomicU64::new(19).fetch_sub(6, Ordering::SeqCst);
    }
    

    IR:
    atomic.ll.txt
    atomic_znver1.ll.txt

    I cannot build Clang/LLVM from master right now so I'm attaching IR from my code above. I'll try to find time tomorrow or somewhere next week.

  18. nikic commented on Aug 8, 2019

    @nikic
    Contributor

    Confirming that

    define i64 @test(i64* %p) {
      %x = atomicrmw sub i64* %p, i64 1 seq_cst 
      ret i64 %x 
    } 
    

    produces a __atomic_fetch_sub_8 call instead of a lock xaddq under llc -mcpu=znver1.

  19. nikic commented on Aug 8, 2019

    @nikic
    Contributor

    I believe the cause is that the znver feature spec is missing FeatureCMPXCHG8B (the 16B variant is listed).

  20. nikic commented on Aug 8, 2019

    @nikic
    Contributor
  21. added a commit that references this issue on Aug 9, 2019
    0ff76ad
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-linkageArea: linking into static, shared libraries and binariesC-bugCategory: This is a bug.O-linuxOperating system: LinuxO-windowsOperating system: WindowsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions