Skip to content

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

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
novacrazy opened this issue Aug 7, 2019 · 15 comments · Fixed by #63415
Closed

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

novacrazy opened this issue Aug 7, 2019 · 15 comments · Fixed by #63415
Assignees
Labels
A-linkage Area: linking into static, shared libraries and binaries A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug. O-linux Operating system: Linux O-windows Operating system: Windows regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@novacrazy
Copy link

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.

@Mark-Simulacrum
Copy link
Member

Is this reproducible after cargo clean?

@Mark-Simulacrum Mark-Simulacrum added E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc O-windows-msvc Toolchain: MSVC, Operating system: Windows regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 7, 2019
@novacrazy
Copy link
Author

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

@Mark-Simulacrum
Copy link
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?

@novacrazy
Copy link
Author

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

Also, that's a nifty tool.

@Mark-Simulacrum
Copy link
Member

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

@ollie27
Copy link
Member

ollie27 commented Aug 7, 2019

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?

@novacrazy
Copy link
Author

novacrazy commented Aug 7, 2019

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

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.

@novacrazy
Copy link
Author

novacrazy commented Aug 7, 2019

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

@mati865
Copy link
Contributor

mati865 commented Aug 8, 2019

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

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. O-linux Operating system: Linux O-windows Operating system: Windows and removed E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc O-windows-msvc Toolchain: MSVC, Operating system: Windows labels Aug 8, 2019
@alexcrichton
Copy link
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.

@alexcrichton
Copy link
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.

@alexcrichton alexcrichton removed their assignment Aug 8, 2019
@jonas-schievink jonas-schievink added A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug. labels Aug 8, 2019
@mati865
Copy link
Contributor

mati865 commented Aug 8, 2019

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.

@nikic
Copy link
Contributor

nikic commented Aug 8, 2019

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.

@nikic
Copy link
Contributor

nikic commented Aug 8, 2019

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

@nikic
Copy link
Contributor

nikic commented Aug 8, 2019

LLVM bug reported at https://bugs.llvm.org/show_bug.cgi?id=42935.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-linkage Area: linking into static, shared libraries and binaries A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug. O-linux Operating system: Linux O-windows Operating system: Windows regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants