Undefined Symbols While Compiling to x86_64-unknown-uefi

I'm trying to compile this crate to the x86_64-unknown-uefi target and getting errors at link time. rust-lld seems not to be able to find symbols __sync_val_compare_and_swap_16 and __sync_lock_test_and_set_16. Does anyone know where these symbols exist so that I can resolve the errors? They seem to be compiler intrinsics, so perhaps they should they come from rustc or the compiler_builtins crate automatically. Not sure if that understanding is correct.

Build commandline used: cargo xbuild --target x86_64-unknown-uefi
Nightly version: rustc 1.40.0-nightly (9e346646e 2019-11-08)
Host OS: Windows 10
Build output:

error: linking with `rust-lld` failed: exit code: 1
  |
  = note: "rust-lld" "-flavor" "link" "/NOLOGO" "/NXCOMPAT" "/nodefaultlib" "/entry:efi_main" "/subsystem:efi_application" "/LIBPATH:C:\\Projects\\personal\\uefi-practice\\target/sysroot\\lib\\rustlib\\x86_64-unknown-uefi\\lib" "C:\\Projects\\personal\\uefi-practice\\target\\x86_64-unknown-uefi\\debug\\deps\\uefi_practice-f7df25972b29a10d.123mw28k7zdzq2hs.rcgu.o" "C:\\Projects\\personal\\uefi-practice\\target\\x86_64-unknown-uefi\\debug\\deps\\uefi_practice-f7df25972b29a10d.168luiprrv56txez.rcgu.o" "C:\\Projects\\personal\\uefi-practice\\target\\x86_64-unknown-uefi\\debug\\deps\\uefi_practice-f7df25972b29a10d.16ttvqfum6y188eu.rcgu.o" "C:\\Projects\\personal\\uefi-practice\\target\\x86_64-unknown-uefi\\debug\\deps\\uefi_practice-f7df25972b29a10d.1dalg2fy51wb8lah.rcgu.o" "C:\\Projects\\personal\\uefi-practice\\target\\x86_64-unknown-uefi\\debug\\deps\\uefi_practice-f7df25972b29a10d.1odqm0xkwcmyhq3o.rcgu.o" "C:\\Projects\\personal\\uefi-practice\\target\\x86_64-unknown-uefi\\debug\\deps\\uefi_practice-f7df25972b29a10d.24j9n0hj0zaekqvr.rcgu.o" "C:\\Projects\\personal\\uefi-practice\\target\\x86_64-unknown-uefi\\debug\\deps\\uefi_practice-f7df25972b29a10d.31oq7a7pt1mgmvjv.rcgu.o" "C:\\Projects\\personal\\uefi-practice\\target\\x86_64-unknown-uefi\\debug\\deps\\uefi_practice-f7df25972b29a10d.38ggyki2ov1emb8e.rcgu.o" "C:\\Projects\\personal\\uefi-practice\\target\\x86_64-unknown-uefi\\debug\\deps\\uefi_practice-f7df25972b29a10d.3mrbkqg5o6j3v878.rcgu.o" "C:\\Projects\\personal\\uefi-practice\\target\\x86_64-unknown-uefi\\debug\\deps\\uefi_practice-f7df25972b29a10d.3y9802a992jwu9sz.rcgu.o" "C:\\Projects\\personal\\uefi-practice\\target\\x86_64-unknown-uefi\\debug\\deps\\uefi_practice-f7df25972b29a10d.437tepsiq7p53qdq.rcgu.o" "C:\\Projects\\personal\\uefi-practice\\target\\x86_64-unknown-uefi\\debug\\deps\\uefi_practice-f7df25972b29a10d.l05bl28cf0s74oy.rcgu.o" "/OUT:C:\\Projects\\personal\\uefi-practice\\target\\x86_64-unknown-uefi\\debug\\deps\\uefi_practice-f7df25972b29a10d.efi" "/OPT:REF,NOICF" "/DEBUG" "/LIBPATH:C:\\Projects\\personal\\uefi-practice\\target\\x86_64-unknown-uefi\\debug\\deps" "/LIBPATH:C:\\Projects\\personal\\uefi-practice\\target\\debug\\deps" "/LIBPATH:C:\\Projects\\personal\\uefi-practice\\target/sysroot\\lib\\rustlib\\x86_64-unknown-uefi\\lib" "C:\\Projects\\personal\\uefi-practice\\target\\sysroot\\lib\\rustlib\\x86_64-unknown-uefi\\lib\\librustc_std_workspace_core-4db334855bda32b0.rlib" "C:\\Projects\\personal\\uefi-practice\\target\\sysroot\\lib\\rustlib\\x86_64-unknown-uefi\\lib\\libcore-8f5696ff045f66ab.rlib" "C:\\Projects\\personal\\uefi-practice\\target\\sysroot\\lib\\rustlib\\x86_64-unknown-uefi\\lib\\libcompiler_builtins-1bdfce1174c15c42.rlib"
  = note: rust-lld: error: undefined symbol: __sync_val_compare_and_swap_16
          >>> referenced by libcompiler_builtins-1bdfce1174c15c42.rlib(compiler_builtins-1bdfce1174c15c42.compiler_builtins.en09gzh0-cgu.3.rcgu.o):(__llvm_memcpy_element_unordered_atomic_16)
          >>> referenced by libcompiler_builtins-1bdfce1174c15c42.rlib(compiler_builtins-1bdfce1174c15c42.compiler_builtins.en09gzh0-cgu.3.rcgu.o):(__llvm_memmove_element_unordered_atomic_16)
          >>> referenced by libcompiler_builtins-1bdfce1174c15c42.rlib(compiler_builtins-1bdfce1174c15c42.compiler_builtins.en09gzh0-cgu.3.rcgu.o):(__llvm_memmove_element_unordered_atomic_16)
          >>> referenced by libcompiler_builtins-1bdfce1174c15c42.rlib(compiler_builtins-1bdfce1174c15c42.compiler_builtins.en09gzh0-cgu.3.rcgu.o):(__llvm_memmove_element_unordered_atomic_16)

          rust-lld: error: undefined symbol: __sync_lock_test_and_set_16
          >>> referenced by libcompiler_builtins-1bdfce1174c15c42.rlib(compiler_builtins-1bdfce1174c15c42.compiler_builtins.en09gzh0-cgu.3.rcgu.o):(__llvm_memcpy_element_unordered_atomic_16)
          >>> referenced by libcompiler_builtins-1bdfce1174c15c42.rlib(compiler_builtins-1bdfce1174c15c42.compiler_builtins.en09gzh0-cgu.3.rcgu.o):(__llvm_memmove_element_unordered_atomic_16)
          >>> referenced by libcompiler_builtins-1bdfce1174c15c42.rlib(compiler_builtins-1bdfce1174c15c42.compiler_builtins.en09gzh0-cgu.3.rcgu.o):(__llvm_memmove_element_unordered_atomic_16)
          >>> referenced by libcompiler_builtins-1bdfce1174c15c42.rlib(compiler_builtins-1bdfce1174c15c42.compiler_builtins.en09gzh0-cgu.3.rcgu.o):(__llvm_memmove_element_unordered_atomic_16)
          >>> referenced by libcompiler_builtins-1bdfce1174c15c42.rlib(compiler_builtins-1bdfce1174c15c42.compiler_builtins.en09gzh0-cgu.3.rcgu.o):(__llvm_memset_element_unordered_atomic_16)

Was due to a bug in compiler_builtins and is now fixed: Undefined Symbols While Compiling to x86_64-unknown-uefi · Issue #66320 · rust-lang/rust · GitHub

Is it fixed? Just spent 18 hours trying to see where its fixed. Really trying to give it a shot here...
Any advice? I really need to move past using assembly code, but this was only fixed when I manually compiled the object from IDA Pro analysis to nasm asm. I'm not trying to be doing this every last object file, but can find no place to pass the right dependencies to lld or cargo or xbuild...

Build commandline used: cargo xbuild --target x86_64-unknown-uefi
Nightly version: rustc 1.36.0-nightly @ x86_64_pc_windows_mvsc
Host OS: Windows 7 x64 Ultimate Edition
Build output:
C:/Users/Operator/.cargo/bin/cargo.exe +nightly xbuild --release --target x86_64-unknown-uefi Compiling deify v0.9.99 (W:\.projects\.deify) error: linking with rust-lld failed: exit code: 1 .projects\\.deify\\target\\sysroot\\lib\\rustlib\\x86_64-unknown-uefi\\lib\\libcore-e00375d86b50dac0.rlib" "W:\\.projects\\.deify\\target\\sysroot\\lib\\rustlib\\x86_64-unknown-uefi\\lib\\libcompiler_builtins-816d2609bcc25c7b.rlib" = note: rust-lld: error: undefined symbol: __rust_probestack >>> referenced by W:\.projects\.deify\target\x86_64-unknown-uefi\release\deps\deify

You're using an old nightly which would have the bug. Use the latest version.

1 Like

Thanks, but no cigar. Uninstalled 1.36.0 completely to 1.42.0, same issue.
EDIT:
Also update LLVM to 10.0.0 just in case. Still same result even with removing ./target/sysroot, ./target, rust, cargo, rustc, lld-link.exe and rust-lld.exe.

Hmm... Looks like a different issue. I found this bug on github that seems to report the same problem: Issues linking __rust_probestack when cross compiling for UEFI on 0.1.23 · Issue #333 · rust-lang/compiler-builtins · GitHub. I hope it'll be fixed soon.

1 Like

That worked! I had seen this post, but I hadn't taken compiler_builtins to v0.1.22 inside cargo-xbuild.

I ended up rebuilding a local cargo-xbuild and patching cargo-xbuild/src/sysroot.rs to

[dependencies.compiler_builtins]
git = "https://github.com/rust-lang/compiler-builtins"
tag = "0.1.21"

Here's a build log:
https://gist.github.com/corelibcore/7f1f4e5961f14ef724f0fe2cdd916552

Thanks alot for your help.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.