Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

undefined symbol: compiler_builtins::mem when building with cranelift + lld-link.exe on windows (and lld: error on gnu) #1480

Open
chamons opened this issue Apr 6, 2024 · 5 comments
Labels
C-bug Category: This is a bug. O-windows Operating system: Windows

Comments

@chamons
Copy link

chamons commented Apr 6, 2024

Issue

When I try compiling any rust program with the combination of:

  • LLD 18.1.2
  • Cranklift from 4/5/2024 cg_clif-x86_64-pc-windows-msvc.tar.xz

I get these errors

C:\Users\donblas\Programming\cranelift-march-6\cargo-clif.exe build
   Compiling link-crane-example v0.1.0 (C:\Users\donblas\Programming\link-crane-example)
error: linking with `C:\Program Files\LLVM\bin\lld-link.exe` failed: exit code: 1
  |
  = note: "C:\\Program Files\\LLVM\\bin\\lld-link.exe" "-flavor" "link" "/DEF:C:\\Users\\donblas\\AppData\\Local\\Temp\\rustcZYRz07\\lib.def" "/NOLOGO" "C:\\Users\\donblas\\AppData\\Local\\Temp\\rustcZYRz07\\symbols.o" "C:\\Users\\donblas\\Programming\\link-crane-example\\target\\debug\\deps\\shufflelib.1efll5bx2e00ud32.rcgu.o" "C:\\Users\\donblas\\Programming\\link-crane-example\\target\\debug\\deps\\shufflelib.1m5mg95wxg41i1ui.rcgu.rmeta" "C:\\Users\\donblas\\Programming\\link-crane-example\\target\\debug\\deps\\shufflelib.allocator_shim.rcgu.o" "/LIBPATH:C:\\Users\\donblas\\Programming\\link-crane-example\\target\\debug\\deps" "/LIBPATH:C:\\Users\\donblas\\Programming\\cranelift-march-6\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "C:\\Users\\donblas\\Programming\\cranelift-march-6\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd-31276ed477bdd0d6.rlib" "C:\\Users\\donblas\\Programming\\cranelift-march-6\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libpanic_abort-af2fd9d19bb9fc21.rlib" "C:\\Users\\donblas\\Programming\\cranelift-march-6\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_demangle-73ce6d0b11677fa9.rlib" "C:\\Users\\donblas\\Programming\\cranelift-march-6\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd_detect-fd98a2200ad11eae.rlib" "C:\\Users\\donblas\\Programming\\cranelift-march-6\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libhashbrown-35a7315e06cc80c2.rlib" "C:\\Users\\donblas\\Programming\\cranelift-march-6\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_std_workspace_alloc-0b437564369036c4.rlib" "C:\\Users\\donblas\\Programming\\cranelift-march-6\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libunwind-90a55d17c0fe05f2.rlib" "C:\\Users\\donblas\\Programming\\cranelift-march-6\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcfg_if-e1fe54e8b5ad24c1.rlib" "C:\\Users\\donblas\\Programming\\cranelift-march-6\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liblibc-2e452438aaad9a38.rlib" "C:\\Users\\donblas\\Programming\\cranelift-march-6\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liballoc-967980aca3096147.rlib" "C:\\Users\\donblas\\Programming\\cranelift-march-6\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_std_workspace_core-e02f187c876c9b12.rlib" "C:\\Users\\donblas\\Programming\\cranelift-march-6\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcore-e55a56e004e0a413.rlib" "C:\\Users\\donblas\\Programming\\cranelift-march-6\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcompiler_builtins-b9914bbc4f629d43.rlib" "kernel32.lib" "advapi32.lib" "kernel32.lib" "ntdll.lib" "userenv.lib" "ws2_32.lib" "synchronization.lib" "kernel32.lib" "ws2_32.lib" "kernel32.lib" "msvcrt.lib" "/NXCOMPAT" "/LIBPATH:C:\\Users\\donblas\\Programming\\cranelift-march-6\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "/OUT:C:\\Users\\donblas\\Programming\\link-crane-example\\target\\debug\\deps\\shufflelib.dll" "/OPT:REF,NOICF" "/DLL" "/IMPLIB:C:\\Users\\donblas\\Programming\\link-crane-example\\target\\debug\\deps\\shufflelib.dll.lib" "/DEBUG" "/PDBALTPATH:%_PDB%"
  = note: lld-link: error: <root>: undefined symbol: compiler_builtins::mem::bcmp::hf89d8ec69417b8af
          lld-link: error: <root>: undefined symbol: compiler_builtins::mem::memcmp::h5e7dc66d5bda6f4b
          lld-link: error: <root>: undefined symbol: compiler_builtins::mem::memcpy::h7112795738f157a8
          lld-link: error: <root>: undefined symbol: compiler_builtins::mem::memset::hd5a36185bfe23a75
          lld-link: error: <root>: undefined symbol: compiler_builtins::mem::strlen::h51798b0eccb4a025
          lld-link: error: <root>: undefined symbol: compiler_builtins::mem::memmove::h85e5af0d67f5ae71
          lld-link: error: undefined symbol: compiler_builtins::mem::bcmp::hf89d8ec69417b8af
          >>> referenced by C:\Users\donblas\AppData\Local\Temp\rustcZYRz07\symbols.o
          >>> referenced by libcompiler_builtins-b9914bbc4f629d43.rlib(compiler_builtins-b9914bbc4f629d43.compiler_builtins.88e0577c9cba8cfc-cgu.002.rcgu.o)

          lld-link: error: undefined symbol: compiler_builtins::mem::memcmp::h5e7dc66d5bda6f4b
          >>> referenced by C:\Users\donblas\AppData\Local\Temp\rustcZYRz07\symbols.o
          >>> referenced by libcompiler_builtins-b9914bbc4f629d43.rlib(compiler_builtins-b9914bbc4f629d43.compiler_builtins.88e0577c9cba8cfc-cgu.002.rcgu.o):(.refptr._ZN17compiler_builtins3mem6memcmp17h5e7dc66d5bda6f4bE)

          lld-link: error: undefined symbol: compiler_builtins::mem::memcpy::h7112795738f157a8
          >>> referenced by C:\Users\donblas\AppData\Local\Temp\rustcZYRz07\symbols.o
          >>> referenced by libcompiler_builtins-b9914bbc4f629d43.rlib(compiler_builtins-b9914bbc4f629d43.compiler_builtins.88e0577c9cba8cfc-cgu.002.rcgu.o)

          lld-link: error: undefined symbol: compiler_builtins::mem::memset::hd5a36185bfe23a75
          >>> referenced by C:\Users\donblas\AppData\Local\Temp\rustcZYRz07\symbols.o
          >>> referenced by libcompiler_builtins-b9914bbc4f629d43.rlib(compiler_builtins-b9914bbc4f629d43.compiler_builtins.88e0577c9cba8cfc-cgu.002.rcgu.o)

          lld-link: error: undefined symbol: compiler_builtins::mem::strlen::h51798b0eccb4a025
          >>> referenced by C:\Users\donblas\AppData\Local\Temp\rustcZYRz07\symbols.o
          >>> referenced by libcompiler_builtins-b9914bbc4f629d43.rlib(compiler_builtins-b9914bbc4f629d43.compiler_builtins.88e0577c9cba8cfc-cgu.002.rcgu.o)

          lld-link: error: undefined symbol: compiler_builtins::mem::memmove::h85e5af0d67f5ae71
          >>> referenced by C:\Users\donblas\AppData\Local\Temp\rustcZYRz07\symbols.o
          >>> referenced by libcompiler_builtins-b9914bbc4f629d43.rlib(compiler_builtins-b9914bbc4f629d43.compiler_builtins.88e0577c9cba8cfc-cgu.002.rcgu.o)

Steps to Reproduce

  • git clone down https://github.com/chamons/link-crane-example
  • Update .cargo\config.toml to point to your lld-link.exe location (if not in Program Files\LLVM\bin)
  • C:\Users\donblas\Programming\cranelift-march-6\cargo-clif.exe build (change path to clif)
@chamons chamons changed the title undefined symbol: compiler_builtins::mem when building with cranelift + lld-link.exe on windows undefined symbol: compiler_builtins::mem when building with cranelift + lld-link.exe on windows (but only on MSVC toolchain, not gnu) Apr 6, 2024
@chamons
Copy link
Author

chamons commented Apr 6, 2024

Note, if you use the gnu toolchain (and you don't forget to add the config for gnu), you get something different:

 C:\Users\donblas\Programming\cranelift-march-6-gnu\cargo-clif.exe build
   Compiling link-crane-example v0.1.0 (C:\Users\donblas\Programming\link-crane-example)
error: linking with `C:\Program Files\LLVM\bin\lld-link.exe` failed: exit code: 1
  |
  = note: "C:\\Program Files\\LLVM\\bin\\lld-link.exe" "-flavor" "gnu" "C:\\Users\\donblas\\AppData\\Local\\Temp\\rustc3a0RaK\\list.def" "--dynamicbase" "--disable-auto-image-base" "-m" "i386pep" "--high-entropy-va" "C:\\Users\\donblas\\Programming\\cranelift-march-6-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\rsbegin.o" "C:\\Users\\donblas\\AppData\\Local\\Temp\\rustc3a0RaK\\symbols.o" "C:\\Users\\donblas\\Programming\\link-crane-example\\target\\debug\\deps\\shufflelib.57bu7vjgmv6eimbk.rcgu.o" "C:\\Users\\donblas\\Programming\\link-crane-example\\target\\debug\\deps\\shufflelib.4oqax2q5yyfaalew.rcgu.rmeta" "C:\\Users\\donblas\\Programming\\link-crane-example\\target\\debug\\deps\\shufflelib.allocator_shim.rcgu.o" "-L" "C:\\Users\\donblas\\Programming\\link-crane-example\\target\\debug\\deps" "-L" "C:\\Users\\donblas\\Programming\\cranelift-march-6-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-Bstatic" "C:\\Users\\donblas\\Programming\\cranelift-march-6-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\libstd-fb642efde765ed9f.rlib" "C:\\Users\\donblas\\Programming\\cranelift-march-6-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\libpanic_abort-bec599011a40b01e.rlib" "C:\\Users\\donblas\\Programming\\cranelift-march-6-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\libobject-90242e79fa9540bf.rlib" "C:\\Users\\donblas\\Programming\\cranelift-march-6-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\libmemchr-07e571df86294406.rlib" "C:\\Users\\donblas\\Programming\\cranelift-march-6-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\libaddr2line-0fde156512bdf8bd.rlib" "C:\\Users\\donblas\\Programming\\cranelift-march-6-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\libgimli-b2c084914256f311.rlib" "C:\\Users\\donblas\\Programming\\cranelift-march-6-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\librustc_demangle-9128df6fd4207099.rlib" "C:\\Users\\donblas\\Programming\\cranelift-march-6-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\libstd_detect-32b0e2c3744c417f.rlib" "C:\\Users\\donblas\\Programming\\cranelift-march-6-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\libhashbrown-0f901b1895683413.rlib" "C:\\Users\\donblas\\Programming\\cranelift-march-6-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\librustc_std_workspace_alloc-18e121855a8ff11d.rlib" "C:\\Users\\donblas\\Programming\\cranelift-march-6-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\libminiz_oxide-9dab3a7a0c32e34e.rlib" "C:\\Users\\donblas\\Programming\\cranelift-march-6-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\libadler-6d8c3b9e81a4d025.rlib" "C:\\Users\\donblas\\Programming\\cranelift-march-6-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\libunwind-170319c0123e6f4f.rlib" "C:\\Users\\donblas\\Programming\\cranelift-march-6-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\libcfg_if-b27b1d5e0d171191.rlib" "C:\\Users\\donblas\\Programming\\cranelift-march-6-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\liblibc-ca10b7c5baff0a50.rlib" "C:\\Users\\donblas\\Programming\\cranelift-march-6-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\liballoc-07d55d69706511a7.rlib" "C:\\Users\\donblas\\Programming\\cranelift-march-6-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\librustc_std_workspace_core-6bbdbf5b7fac79bb.rlib" "C:\\Users\\donblas\\Programming\\cranelift-march-6-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\libcore-ca3de878d8c62a21.rlib" "C:\\Users\\donblas\\Programming\\cranelift-march-6-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\libcompiler_builtins-f5470747e3dbc32a.rlib" "-Bdynamic" "-lkernel32" "-ladvapi32" "-lkernel32" "-lntdll" "-luserenv" "-lws2_32" "-lsynchronization" "-lkernel32" "-lws2_32" "-lkernel32" "-lgcc_s" "-lmsvcrt" "-lmingwex" "-lmingw32" "-lgcc" "-lmsvcrt" "-luser32" "-lkernel32" "--nxcompat" "-L" "C:\\Users\\donblas\\Programming\\cranelift-march-6-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-o" "C:\\Users\\donblas\\Programming\\link-crane-example\\target\\debug\\deps\\shufflelib.dll" "-shared" "--out-implib=C:\\Users\\donblas\\Programming\\link-crane-example\\target\\debug\\deps\\libshufflelib.dll.a" "C:\\Users\\donblas\\Programming\\cranelift-march-6-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\rsend.o"
  = note: lld: error: unable to find library -lkernel32
          lld: error: unable to find library -ladvapi32
          lld: error: unable to find library -lkernel32
          lld: error: unable to find library -lntdll
          lld: error: unable to find library -luserenv
          lld: error: unable to find library -lws2_32
          lld: error: unable to find library -lsynchronization
          lld: error: unable to find library -lkernel32
          lld: error: unable to find library -lws2_32
          lld: error: unable to find library -lkernel32
          lld: error: unable to find library -lgcc_s
          lld: error: unable to find library -lmsvcrt
          lld: error: unable to find library -lmingwex
          lld: error: unable to find library -lmingw32
          lld: error: unable to find library -lgcc
          lld: error: unable to find library -lmsvcrt
          lld: error: unable to find library -luser32
          lld: error: unable to find library -lkernel32

@chamons chamons changed the title undefined symbol: compiler_builtins::mem when building with cranelift + lld-link.exe on windows (but only on MSVC toolchain, not gnu) undefined symbol: compiler_builtins::mem when building with cranelift + lld-link.exe on windows (and lld: error on gnu) Apr 6, 2024
@bjorn3
Copy link
Member

bjorn3 commented Apr 6, 2024

undefined symbol: compiler_builtins::mem when building with cranelift + lld-link.exe on windows (and lld: error on gnu)

Thanks for reporting this. I will try to reproduce this.

Note, if you use the gnu toolchain (and you don't forget to add the config for gnu), you get something different:

For the mingw toolchain you can't directly set the linker to lld-link.exe. Instead you have to pass something like -fuse-ld=lld (not sure exactly what it is on mingw) to the linker wrapper using -Clink-arg=-fuse-ld=lld. Just like on unix systems, with mingw the linker is wrapped by gcc or clang which pass a fair amount of extra arguments to for example set the linker search path.

@bjorn3
Copy link
Member

bjorn3 commented Apr 6, 2024

@chamons
Copy link
Author

chamons commented Apr 6, 2024

With the build from CI or using the CI to do the compile somehow?

@bjorn3
Copy link
Member

bjorn3 commented Apr 7, 2024

I changed the CI config to always use lld-link.exe and then triggered a CI run. This CI run didn't fail, meaning that it doesn't reproduce your issue.

@bjorn3 bjorn3 added C-bug Category: This is a bug. O-windows Operating system: Windows labels Aug 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. O-windows Operating system: Windows
Projects
None yet
Development

No branches or pull requests

2 participants