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

Unresolved LLVM symbols when linking rustc_driver. #81381

Closed
MarnixKuijs opened this issue Jan 25, 2021 · 15 comments
Closed

Unresolved LLVM symbols when linking rustc_driver. #81381

MarnixKuijs opened this issue Jan 25, 2021 · 15 comments
Labels
C-bug Category: This is a bug. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example O-windows-msvc Toolchain: MSVC, Operating system: Windows T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

Comments

@MarnixKuijs
Copy link

The linking of rustc_driver will fail when using a custom llvm through the llvm-config setting in the config.toml.

Meta

Bootstrap compiler: beta 2020-12-30
Compiling master branch
LLVM 10.0.0
Windows 10 2004
Backtrace

librustc_llvm-cb11b760f2056bc3.rlib(MachineBasicBlock.obj) : error LNK2019: unresolved external symbol __imp_rint referenced in function "public: void __cdecl llvm::MachineBasicBlock::print(class llvm::raw_ostream &,class llvm::ModuleSlotTracker &,class llvm::SlotIndexes const *,bool)const " (?print@MachineBasicBlock@llvm@@QEBAXAEAVraw_ostream@2@AEAVModuleSlotTracker@2@PEBVSlotIndexes@2@_N@Z)
librustc_llvm-cb11b760f2056bc3.rlib(BranchProbability.obj) : error LNK2001: unresolved external symbol __imp_rint
librustc_llvm-cb11b760f2056bc3.rlib(SimplifyLibCalls.obj) : error LNK2019: unresolved external symbol __imp_log2 referenced in function "private: class llvm::Value * __cdecl llvm::LibCallSimplifier::replacePowWithExp(class llvm::CallInst *,class llvm::IRBuilder<class llvm::ConstantFolder,class llvm::IRBuilderDefaultInserter> &)" (?replacePowWithExp@LibCallSimplifier@llvm@@AEAAPEAVValue@2@PEAVCallInst@2@AEAV?$IRBuilder@VConstantFolder@llvm@@VIRBuilderDefaultInserter@2@@2@@Z)
librustc_llvm-cb11b760f2056bc3.rlib(ConstantFolding.obj) : error LNK2001: unresolved external symbol __imp_log2
librustc_llvm-cb11b760f2056bc3.rlib(SimplifyLibCalls.obj) : error LNK2019: unresolved external symbol __imp_log2f referenced in function "private: class llvm::Value * __cdecl llvm::LibCallSimplifier::replacePowWithExp(class llvm::CallInst *,class llvm::IRBuilder<class llvm::ConstantFolder,class llvm::IRBuilderDefaultInserter> &)" (?replacePowWithExp@LibCallSimplifier@llvm@@AEAAPEAVValue@2@PEAVCallInst@2@AEAV?$IRBuilder@VConstantFolder@llvm@@VIRBuilderDefaultInserter@2@@2@@Z)
librustc_llvm-cb11b760f2056bc3.rlib(ConstantFolding.obj) : error LNK2019: unresolved external symbol __imp_feclearexcept referenced in function "class llvm::Constant * __cdecl `anonymous namespace'::ConstantFoldBinaryFP(double (__cdecl*)(double,double),double,double,class llvm::Type *)" (?ConstantFoldBinaryFP@?A0x4678a5ee@@YAPEAVConstant@llvm@@P6ANNN@ZNNPEAVType@3@@Z)
librustc_llvm-cb11b760f2056bc3.rlib(InstrProf.obj) : error LNK2019: unresolved external symbol __imp_strncpy referenced in function "public: void __cdecl llvm::OverlapStats::dump(class llvm::raw_fd_ostream &)const " (?dump@OverlapStats@llvm@@QEBAXAEAVraw_fd_ostream@2@@Z)
librustc_llvm-cb11b760f2056bc3.rlib(WindowsResource.obj) : error LNK2001: unresolved external symbol __imp_strncpy
librustc_llvm-cb11b760f2056bc3.rlib(XCOFFObjectWriter.obj) : error LNK2001: unresolved external symbol __imp_strncpy
librustc_llvm-cb11b760f2056bc3.rlib(WinCOFFObjectWriter.obj) : error LNK2019: unresolved external symbol __imp__time64 referenced in function "public: virtual unsigned __int64 __cdecl `anonymous namespace'::WinCOFFObjectWriter::writeObject(class llvm::MCAssembler &,class llvm::MCAsmLayout const &)" (?writeObject@WinCOFFObjectWriter@?A0x86030a0a@@UEAA_KAEAVMCAssembler@llvm@@AEBVMCAsmLayout@4@@Z)
librustc_llvm-cb11b760f2056bc3.rlib(Program.obj) : error LNK2019: unresolved external symbol __imp__setmode referenced in function "class std::error_code __cdecl llvm::sys::ChangeStdinToBinary(void)" (?ChangeStdinToBinary@sys@llvm@@YA?AVerror_code@std@@XZ)
librustc_llvm-cb11b760f2056bc3.rlib(Process.obj) : error LNK2019: unresolved external symbol __imp__heapwalk referenced in function "public: static unsigned __int64 __cdecl llvm::sys::Process::GetMallocUsage(void)" (?GetMallocUsage@Process@sys@llvm@@SA_KXZ)
librustc_llvm-cb11b760f2056bc3.rlib(Process.obj) : error LNK2019: unresolved external symbol __imp_close referenced in function "public: static class std::error_code __cdecl llvm::sys::Process::SafelyCloseFileDescriptor(int)" (?SafelyCloseFileDescriptor@Process@sys@llvm@@SA?AVerror_code@std@@H@Z)
librustc_llvm-cb11b760f2056bc3.rlib(Path.obj) : error LNK2001: unresolved external symbol __imp_close
OLDNAMES.lib(close.obi) : error LNK2001: unresolved external symbol __imp_close
librustc_llvm-cb11b760f2056bc3.rlib(Path.obj) : error LNK2019: unresolved external symbol __imp__chsize_s referenced in function "class std::error_code __cdecl llvm::sys::fs::resize_file(int,unsigned __int64)" (?resize_file@fs@sys@llvm@@YA?AVerror_code@std@@H_K@Z)
librustc_llvm-cb11b760f2056bc3.rlib(Path.obj) : error LNK2019: unresolved external symbol __imp_read referenced in function "class std::error_code __cdecl llvm::sys::fs::copy_file_internal(int,int)" (?copy_file_internal@fs@sys@llvm@@YA?AVerror_code@std@@HH@Z)
OLDNAMES.lib(read.obi) : error LNK2001: unresolved external symbol __imp_read
librustc_llvm-cb11b760f2056bc3.rlib(Path.obj) : error LNK2019: unresolved external symbol __imp_write referenced in function "class std::error_code __cdecl llvm::sys::fs::copy_file_internal(int,int)" (?copy_file_internal@fs@sys@llvm@@YA?AVerror_code@std@@HH@Z)
librustc_llvm-cb11b760f2056bc3.rlib(raw_ostream.obj) : error LNK2001: unresolved external symbol __imp_write
librustc_llvm-cb11b760f2056bc3.rlib(ErrorHandling.obj) : error LNK2001: unresolved external symbol __imp_write
OLDNAMES.lib(write.obi) : error LNK2001: unresolved external symbol __imp_write
librustc_llvm-cb11b760f2056bc3.rlib(Errno.obj) : error LNK2019: unresolved external symbol __imp_strerror_s referenced in function "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl llvm::sys::StrError(int)" (?StrError@sys@llvm@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@H@Z)
librustc_llvm-cb11b760f2056bc3.rlib(raw_ostream.obj) : error LNK2019: unresolved external symbol __imp_lseek referenced in function "public: __cdecl llvm::raw_fd_ostream::raw_fd_ostream(int,bool,bool)" (??0raw_fd_ostream@llvm@@QEAA@H_N0@Z)
OLDNAMES.lib(lseek.obi) : error LNK2001: unresolved external symbol __imp_lseek
librustc_llvm-cb11b760f2056bc3.rlib(NativeFormatting.obj) : error LNK2019: unresolved external symbol __imp__fpclass referenced in function "void __cdecl llvm::write_double(class llvm::raw_ostream &,double,enum llvm::FloatStyle,class llvm::Optional<unsigned __int64>)" (?write_double@llvm@@YAXAEAVraw_ostream@1@NW4FloatStyle@1@V?$Optional@_K@1@@Z)
librustc_llvm-cb11b760f2056bc3.rlib(JSON.obj) : error LNK2019: unresolved external symbol __imp_modf referenced in function "public: class llvm::Optional<__int64> __cdecl llvm::json::Value::getAsInteger(void)const " (?getAsInteger@Value@json@llvm@@QEBA?AV?$Optional@_J@3@XZ)
librustc_llvm-cb11b760f2056bc3.rlib(Chrono.obj) : error LNK2019: unresolved external symbol __imp__localtime64_s referenced in function "class llvm::raw_ostream & __cdecl llvm::operator<<(class llvm::raw_ostream &,class std::chrono::time_point<struct std::chrono::system_clock,class std::chrono::duration<__int64,struct std::ratio<1,1000000000> > >)" (??6llvm@@YAAEAVraw_ostream@0@AEAV10@V?$time_point@Usystem_clock@chrono@std@@V?$duration@_JU?$ratio@$00$0DLJKMKAA@@std@@@23@@chrono@std@@@Z)
rustc_driver-53307c04a46b25d9.dll : fatal error LNK1120: 17 unresolved externals

@MarnixKuijs MarnixKuijs added the C-bug Category: This is a bug. label Jan 25, 2021
@jyn514
Copy link
Member

jyn514 commented Jan 25, 2021

@MarnixKuijs that looks like a version mismatch in the c++ standard library. Try updating your version of MSVC build tools.

@jyn514 jyn514 added T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example labels Jan 25, 2021
@MarnixKuijs
Copy link
Author

My MSVC build tools are the latest:

MSVC v142 - VS 2019 C++ x64/x86 build tools (v14.28)

One problem that I faced was this. Which I circumvented by commenting out #define HAVE_STD_IS_TRIVIALLY_COPYABLE in llvm-10.0.0\include\llvm\Config\config.h, but I find it highly unlikely that that would cause the problem. This is due to a conformance update, so maybe it could be that my version is too new and need to downgrade my MSVC build tools?

@MarnixKuijs
Copy link
Author

I have gone and tested MSVC v142,14.20..14.28 I even tried MSVC v141,14.16. All of them result in the same linker errors.

@mati865

This comment has been minimized.

@rustbot rustbot added the O-windows-msvc Toolchain: MSVC, Operating system: Windows label Jan 31, 2021
@klensy
Copy link
Contributor

klensy commented Jan 31, 2021

There was some issues, nightly-2021-01-11-x86_64-pc-windows-msvc works for bootstrap, at least better works.

@MarnixKuijs
Copy link
Author

I have tested with different bootstrap compilers, but nothing seems to effect anything

@MarnixKuijs
Copy link
Author

MarnixKuijs commented Feb 17, 2021

I got the rustc_driver to link, by setting crt-static = true in the config.toml and making sure that the LLVM_USE_CRT was set to MT instead of MD. However it seems that linking with dynamic libs results in these linker errors.

@MarnixKuijs
Copy link
Author

When building llvm from source it seems to default to MT, so maybe MD isn't supported?

-- Native target architecture is X86
-- Threads enabled.
-- Doxygen disabled.
-- Go bindings disabled.
-- Ninja version: 1.10.2
-- Could NOT find OCaml (missing: OCAMLFIND OCAML_VERSION OCAML_STDLIB_PATH)
-- OCaml bindings disabled.
-- Could NOT find Python module pygments
-- Could NOT find Python module pygments.lexers.c_cpp
-- Could NOT find Python module yaml
-- LLVM host triple: x86_64-pc-windows-msvc
-- LLVM default target triple: x86_64-pc-windows-msvc
-- Using Release VC++ CRT: MT <--------------
-- Looking for os_signpost_interval_begin
-- Looking for os_signpost_interval_begin - not found

@beepster4096
Copy link
Contributor

I'm getting an error similar to this, but using the download-ci-llvm option.

@gheoan
Copy link
Contributor

gheoan commented Jul 30, 2021

I'm also experiencing linker errors related to llvm when building rustc_driver. Using download-ci-llvm = true.

dpaoliello added a commit to dpaoliello/rust that referenced this issue Jun 27, 2022
…c` to get a compiler command line.

When attempting to build rustc with LLVM on Windows, I noticed that the CRT flag provided to the C and C++ Compilers was inconsistent:

```
"-DCMAKE_C_FLAGS=-nologo -MT -Brepro" "-DCMAKE_CXX_FLAGS=-nologo -MD -Brepro"
```

Since the bootstrapper also sets the various `LLVM_USE_CRT` variables, this resulted in cl.exe reporting a bunch of warnings:

```
cl : Command line warning D9025 : overriding '/MD' with '/MT'
```

The root cause for this is that `cc_detect::find` was creating a `cc::Build` twice, but didn't set `static_crt` the second time.

It's possible that this what is also causing rust-lang#81381
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Jun 29, 2022
Ensure that `static_crt` is set in the bootstrapper whenever using `cc-rs` to get a compiler command line.

When attempting to build rustc with LLVM on Windows, I noticed that the CRT flag provided to the C and C++ Compilers was inconsistent:

```
"-DCMAKE_C_FLAGS=-nologo -MT -Brepro" "-DCMAKE_CXX_FLAGS=-nologo -MD -Brepro"
```

Since the bootstrapper also sets the various `LLVM_USE_CRT` variables, this resulted in cl.exe reporting a bunch of warnings:

```
cl : Command line warning D9025 : overriding '/MD' with '/MT'
```

The root cause for this is that `cc_detect::find` was creating a `cc::Build` twice, but didn't set `static_crt` the second time.

It's possible that this what is also causing rust-lang#81381
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jun 29, 2022
Ensure that `static_crt` is set in the bootstrapper whenever using `cc-rs` to get a compiler command line.

When attempting to build rustc with LLVM on Windows, I noticed that the CRT flag provided to the C and C++ Compilers was inconsistent:

```
"-DCMAKE_C_FLAGS=-nologo -MT -Brepro" "-DCMAKE_CXX_FLAGS=-nologo -MD -Brepro"
```

Since the bootstrapper also sets the various `LLVM_USE_CRT` variables, this resulted in cl.exe reporting a bunch of warnings:

```
cl : Command line warning D9025 : overriding '/MD' with '/MT'
```

The root cause for this is that `cc_detect::find` was creating a `cc::Build` twice, but didn't set `static_crt` the second time.

It's possible that this what is also causing rust-lang#81381
@jyn514
Copy link
Member

jyn514 commented May 25, 2023

It's been a while - is anyone still running into this issue?

@riidefi
Copy link

riidefi commented May 25, 2023

It's been a while - is anyone still running into this issue?

I do not know if this helps you, but I've also come about the same linker error with a slightly different setup.

In your issue, you fail to link against CRT symbols when the MSVC version ? linker tries to link librustc_llvm with rustc version ?.
I have ran into a similar, perhaps related, issue where the MSVC 14.335.32215 linker fails to link against CRT symbols when it tries to link a rustc 1.70.0-beta.5 (16ec1c0 2023-05-20) build of libcurl_sys built with CLANG instead of MSVC.

Notably, switching the compiler from Clang to Clang-CL MSVC was the workaround fix for me.

I mention this because libcurl_sys and librustc_llvm are both C/C++ sys libraries built with the system compiler. Perhaps this is the same issue?

If this is not useful, I do not wish to derail your issue at all.

@jyn514
Copy link
Member

jyn514 commented May 25, 2023

This issue is not tracking arbitrary "unresolved external symbols" errors. This is specifically about unresolved LLVM symbols when building rustc_driver.

@jyn514 jyn514 changed the title Unresolved external symbols when linking rustc_driver. Unresolved LLVM symbols when linking rustc_driver. May 25, 2023
@MarnixKuijs
Copy link
Author

It's been a very long time since I have attempted it, so I'm not sure if it's still an issue.

@jackh726
Copy link
Member

Closing this since there hasn't been a reproduction.

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. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example O-windows-msvc Toolchain: MSVC, Operating system: Windows T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
Projects
None yet
Development

No branches or pull requests

9 participants