[llvm-dev] Invoking lld for PE/COFF (Windows) linking

Edward Diener via llvm-dev llvm-dev at lists.llvm.org
Thu Mar 30 17:57:27 PDT 2017


On 3/30/2017 7:59 PM, Reid Kleckner via llvm-dev wrote:
> On Thu, Mar 30, 2017 at 6:08 AM, Edward Diener via llvm-dev
> <llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org>> wrote:
>
>     Are you saying that once lld is built with mingw-64/gcc on Windows
>     it is impossible to tell it to handle PE/COFF files when invoking it
>     from clang++ using the -fuse-ld=lld parameter ? That would indeed be
>     limiting, considering that on Windows I can build clang either with
>     mingw-64/gcc or with Visual C++, and the -target parameter allows
>     clang to generate the appropriate object files.
>
>
> The logic to construct an lld-link command line is part of the MSVC
> toolchain in the clang driver, so you can get clang++ to make a coff
> file if you tell it you're targetting MSVC like this:
> $ clang++ t.cpp  -fuse-ld=lld -o t.exe --target=x86_64-windows-msvc
>
> Of course, that will look for libraries and headers in the wrong places
> if you really want to target mingw. If I split it up like this, I get
> link errors:
> $ clang++ -c t.cpp -o t.o --target=x86_64-windows-gnu
> $ clang++ t.o -o t.exe --target=x86_64-windows-msvc -fuse-ld=lld

Actually just doing:

clang++ -c t.cpp -o t.o --target=x86_64-windows-msvc -fmsc-version=1900
clang++ t.o -o t.exe --target=x86_64-windows-msvc -fuse-ld=lld

is not working for me. The first invocation works but the second just 
hangs and never completes. Should it work ? If not, how can I invoke the 
second to make it work properly ?

> C:\src\llvm-project\build_mingw\bin\lld-link.exe: warning: t.o:
> undefined symbol: _ZNSt8ios_base4InitC1Ev
> C:\src\llvm-project\build_mingw\bin\lld-link.exe: warning: t.o:
> undefined symbol: _ZNSt8ios_base4InitD1Ev
> C:\src\llvm-project\build_mingw\bin\lld-link.exe: warning: t.o:
> undefined symbol: __main
> C:\src\llvm-project\build_mingw\bin\lld-link.exe: warning: t.o:
> undefined symbol: _ZSt4cout
> C:\src\llvm-project\build_mingw\bin\lld-link.exe: warning: t.o:
> undefined symbol: _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
> error: link failed
> clang++.exe: error: linker command failed with exit code 1 (use -v to
> see invocation)
>
> If you pile on enough link options, you can probably make it work, but
> at that point you're basically reconstructing a link.exe / lld-link.exe
> command line. To fix this, someone should add mingw toolchain logic to
> clang's driver to support constructing lld-link command lines.




More information about the llvm-dev mailing list