Skip to content

Linking to rustc_llvm with --llvm-root #30970

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

Open
Zoxc opened this issue Jan 17, 2016 · 12 comments
Open

Linking to rustc_llvm with --llvm-root #30970

Zoxc opened this issue Jan 17, 2016 · 12 comments
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Zoxc
Copy link
Contributor

Zoxc commented Jan 17, 2016

If you link to rustc_llvm with a rustc configured with --llvm-root the path to the LLVM libraries is not passed to the linker resulting in linking errors

@Zoxc
Copy link
Contributor Author

Zoxc commented Jan 17, 2016

There are no static libraries which depend on LLVM right? So there is no reason linking to rustc_plugin would require linking in LLVM libraries?

@Zoxc
Copy link
Contributor Author

Zoxc commented Jan 17, 2016

Linking to LLVM doesn't happen on OS X or debian, but it does on x86_64-mingw-w64 with msys2

@Zoxc
Copy link
Contributor Author

Zoxc commented Jan 21, 2016

@DiamondLovesYou Do you think this is related to #27937? I know this used to work on one of your earlier llvm-root-and-shared branches.

Linking errors:

   Compiling assembly v0.1.0 (file:///B:/Programmering/SandboxOS/AveryRust/kernel/arch/x64/multiboot)
error: linking with `gcc` failed: exit code: 1
note: "gcc" "-Wl,--enable-long-section-names" "-fno-use-linker-plugin" "-Wl,--nxcompat" "-nostdlib" "-m64" "B:\\Programmering\\SandboxOS\\AveryRust\\vendor\\rust\\install\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\dllcrt2.o" "B:\\Programmering\\SandboxOS\\AveryRust\\vendor\\rust\\install\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\rsbegin.o" "-L" "B:\\Programmering\\SandboxOS\\AveryRust\\vendor\\rust\\install\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "B:/Programmering/SandboxOS/AveryRust/build/cargo/target\\release\\deps\\assembly-bb6051f47b5bc242.0.o" "-o" "B:/Programmering/SandboxOS/AveryRust/build/cargo/target\\release\\deps\\assembly-bb6051f47b5bc242.dll" "B:/Programmering/SandboxOS/AveryRust/build/cargo/target\\release\\deps\\assembly-bb6051f47b5bc242.metadata.o" "-nodefaultlibs" "-L" "B:/Programmering/SandboxOS/AveryRust/build/cargo/target\\release\\deps" "-L" "B:/Programmering/SandboxOS/AveryRust/build/cargo/target\\release\\deps" "-L" "B:\\Programmering\\SandboxOS\\AveryRust\\vendor\\rust\\install\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-Wl,-Bstatic" "-Wl,-Bdynamic" "-L" "B:\\Programmering\\SandboxOS\\AveryRust\\vendor\\rust\\install\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-l" "rustc_plugin-ca1c970e" "-L" "B:\\Programmering\\SandboxOS\\AveryRust\\vendor\\rust\\install\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-l" "rustc_metadata-ca1c970e" "-L" "B:\\Programmering\\SandboxOS\\AveryRust\\vendor\\rust\\install\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-l" "rustc-ca1c970e" "-L" "B:\\Programmering\\SandboxOS\\AveryRust\\vendor\\rust\\install\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-l" "rustc_data_structures-ca1c970e" "-L" "B:\\Programmering\\SandboxOS\\AveryRust\\vendor\\rust\\install\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-l" "graphviz-ca1c970e" "-L" "B:\\Programmering\\SandboxOS\\AveryRust\\vendor\\rust\\install\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-l" "fmt_macros-ca1c970e" "-L" "B:\\Programmering\\SandboxOS\\AveryRust\\vendor\\rust\\install\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-l" "arena-ca1c970e" "-L" "B:\\Programmering\\SandboxOS\\AveryRust\\vendor\\rust\\install\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-l" "getopts-ca1c970e" "-L" "B:\\Programmering\\SandboxOS\\AveryRust\\vendor\\rust\\install\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-l" "flate-ca1c970e" "-L" "B:\\Programmering\\SandboxOS\\AveryRust\\vendor\\rust\\install\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-l" "rustc_back-ca1c970e" "-L" "B:\\Programmering\\SandboxOS\\AveryRust\\vendor\\rust\\install\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-l" "rustc_front-ca1c970e" "-L" "B:\\Programmering\\SandboxOS\\AveryRust\\vendor\\rust\\install\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-l" "syntax-ca1c970e" "-L" "B:\\Programmering\\SandboxOS\\AveryRust\\vendor\\rust\\install\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-l" "term-ca1c970e" "-L" "B:\\Programmering\\SandboxOS\\AveryRust\\vendor\\rust\\install\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-l" "rustc_llvm-ca1c970e" "-L" "B:\\Programmering\\SandboxOS\\AveryRust\\vendor\\rust\\install\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-l" "rbml-ca1c970e" "-L" "B:\\Programmering\\SandboxOS\\AveryRust\\vendor\\rust\\install\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-l" "serialize-ca1c970e" "-L" "B:\\Programmering\\SandboxOS\\AveryRust\\vendor\\rust\\install\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-l" "log-ca1c970e" "-L" "B:\\Programmering\\SandboxOS\\AveryRust\\vendor\\rust\\install\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-l" "std-ca1c970e" "-l" "psapi" "-l" "kernel32" "-l" "ole32" "-l" "LLVMInterpreter" "-l" "LLVMMCJIT" "-l" "LLVMExecutionEngine" "-l" "LLVMRuntimeDyld" "-l" "LLVMipo" "-l" "LLVMVectorize" "-l" "LLVMLinker" "-l" "LLVMIRReader" "-l" "LLVMAsmParser" "-l" "LLVMX86Disassembler" "-l" "LLVMX86AsmParser" "-l" "LLVMX86CodeGen" "-l" "LLVMSelectionDAG" "-l" "LLVMAsmPrinter" "-l" "LLVMCodeGen" "-l" "LLVMTarget" "-l" "LLVMScalarOpts" "-l" "LLVMInstCombine" "-l" "LLVMInstrumentation" "-l" "LLVMProfileData" "-l" "LLVMTransformUtils" "-l" "LLVMBitWriter" "-l" "LLVMAnalysis" "-l" "LLVMX86Desc" "-l" "LLVMObject" "-l" "LLVMMCParser" "-l" "LLVMBitReader" "-l" "LLVMMCDisassembler" "-l" "LLVMX86Info" "-l" "LLVMX86AsmPrinter" "-l" "LLVMMC" "-l" "LLVMX86Utils" "-l" "LLVMCore" "-l" "LLVMSupport" "-l" "psapi" "-l" "shell32" "-l" "ole32" "-l" "uuid" "-l" "stdc++" "-l" "gcc_eh" "-l" "ws2_32" "-l" "userenv" "-l" "shell32" "-l" "advapi32" "-shared" "-l" "compiler-rt" "-lmingwex" "-lmingw32" "-lgcc" "-lmsvcrt" "-luser32" "-lkernel32" "B:\\Programmering\\SandboxOS\\AveryRust\\vendor\\rust\\install\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\rsend.o"
note: X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMInterpreter
X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMMCJIT
X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMExecutionEngine
X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMRuntimeDyld
X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMipo
X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMVectorize
X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMLinker
X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMIRReader
X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMAsmParser
X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMX86Disassembler
X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMX86AsmParser
X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMX86CodeGen
X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMSelectionDAG
X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMAsmPrinter
X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMCodeGen
X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMTarget
X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMScalarOpts
X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMInstCombine
X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMInstrumentation
X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMProfileData
X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMTransformUtils
X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMBitWriter
X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMAnalysis
X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMX86Desc
X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMObject
X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMMCParser
X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMBitReader
X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMMCDisassembler
X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMX86Info
X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMX86AsmPrinter
X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMMC
X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMX86Utils
X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMCore
X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMSupport
collect2.exe: error: ld returned 1 exit status

@DiamondLovesYou
Copy link
Contributor

@Zoxc The error you've provided is the result of a missing -L path, specifically the one pointing to where LLVM's *.libs are located. In the normal case w.r.t. Rust's linking model, LLVM is statically linked into librustc_llvm (meaning an -L path to LLVM libs isn't needed/expected); however when LLVM is dynamic Rust will try to transitively link all shared/dynamic dependencies. Meaning every crate and their downstream dependencies which use any part of rustc_llvm will have the LLVM *.libs added to their linker args.

Rust doesn't install any LLVM static or shared libraries (this includes MSVCs .lib files) into its target specific rustlibs folder (which, as you've discovered, is quite an issue for shared LLVM + MSVC Rust), let alone at all, which I bet is the underlying issue.

@Zoxc
Copy link
Contributor Author

Zoxc commented Jan 22, 2016

You should only transitively link to dependencies of a dependency if the immediate dependency is a a static library. rustc_llvm is shared so it does not need its dependencies to be linked.

@Zoxc
Copy link
Contributor Author

Zoxc commented Jan 22, 2016

Well there is the case were an upstream Rust shared library has generic code which links to a native library. So I guess the behavior is justified.

That means we have to ensure LLVM's lib path is passed to the linker with rustc_llvm. Can the metadata hold paths to libraries or do we need some other way of making this happen?

@DiamondLovesYou
Copy link
Contributor

@Zoxc

That means we have to ensure LLVM's lib path is passed to the linker with rustc_llvm. Can the metadata hold paths to libraries or do we need some other way of making this happen?

Metadata should not hold paths to deps. The path must be provided by cargo or rustc.

@steveklabnik steveklabnik added the A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. label Jan 26, 2016
wizeman added a commit to NixOS/nixpkgs that referenced this issue Feb 2, 2016
This is a workaround for what appears to be issue rust-lang/rust#30970.

Without this change, rustcMaster will fail to build the clippy library
due to linking errors against LLVM (and ncurses, for some reason).

I expect this commit to be reverted once that issue is fixed upstream.
@Mark-Simulacrum Mark-Simulacrum added the C-bug Category: This is a bug. label Jul 24, 2017
@alexcrichton
Copy link
Member

I believe in the transition to rustbuild everything about LLVM changed enough that this is either likely fixed or no longe relevant, so closing.

@Zoxc
Copy link
Contributor Author

Zoxc commented Aug 25, 2017

@alexcrichton I doubt that is true.

@alexcrichton alexcrichton reopened this Aug 29, 2017
@o01eg
Copy link
Contributor

o01eg commented Dec 18, 2017

Same on Gentoo Linux after libraries were moved from /usr/lib/ to /usr/lib64/llvm/4/lib64/.

@steveklabnik
Copy link
Member

Triage: no idea what the status of this is.

@Noratrieb Noratrieb added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Apr 5, 2023
@Mark-Simulacrum
Copy link
Member

This needs instructions on how to reproduce the issue at least (ideally a set of shell commands, including how to obtain LLVM directories).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

7 participants