rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
96.92k stars 12.53k forks source link

Linking to rustc_llvm with --llvm-root #30970

Open Zoxc opened 8 years ago

Zoxc commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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

Zoxc commented 8 years ago

@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 commented 8 years ago

@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 commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

@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.

alexcrichton commented 7 years ago

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 commented 7 years ago

@alexcrichton I doubt that is true.

o01eg commented 6 years ago

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

steveklabnik commented 4 years ago

Triage: no idea what the status of this is.

Mark-Simulacrum commented 8 months ago

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