Edward Diener via llvm-dev
2017-Mar-29 14:56 UTC
[llvm-dev] Invoking lld for PE/COFF (Windows) linking
I build llvm/clang/lld from source on Windows using mingw-64/gcc-6.3. I use clang++ both to test clang targeting gcc and clang targeting VC++. When using clang targeting VC++ I use the appropriate target triple when compiling and am trying to use lld to link the object file(s) into an exe. To do that I use the clang option "-fuse-ld=lld" when linking. According to the llvm doc on using lld with PE/COFF on Windows at https://lld.llvm.org/windows_support.html: "LLD supports Windows operating system. When invoked as lld-link.exe or with -flavor link, the driver for Windows operating system is used to parse command line options, and it drives further linking processes. LLD accepts almost all command line options that the linker shipped with Microsoft Visual C++ (link.exe) supports." Unfortunately with clang++ attempting to use "-fuse-ld=lld-link" when linking outputs: "clang++.exe: error: unsupported value 'lld_link' for -linker option" So I must use "-fuse-ld=lld". Does this mean that I should be passing "-flavor link" to the lld linker ? If so, how do I do that ? If not, what do I do to have lld work with PE/COFF linking rather than ELF linking ? I have attempted to pass to the clang++ when linking: 1) "-flavor link", which outputs: clang++.exe: error: unknown argument: '-flavor' clang++.exe: error: no such file or directory: 'link' 2) -flavor=link", which outputs: clang++.exe: error: unknown argument: '-flavor=link' 3) -Wl,-flavor,link, which outputs C:\Programming\VersionControl\bninja_installed_clang\bin\lld: error: unknown argument: -flavor 4) -Wl,-flavor=link, which outputs C:\Programming\VersionControl\bninja_installed_clang\bin\lld: error: unknown argument: -flavor=link What is the "magic" invocation that will allow me to invoke the lld linker from the clang++ command, but get the linker to work in PE/COFF mode rather than in ELF mode, so it will link object files created by clang targeting VC++ ?
Reid Kleckner via llvm-dev
2017-Mar-29 17:38 UTC
[llvm-dev] Invoking lld for PE/COFF (Windows) linking
If clang is targeting VC++, then -fuse-ld=lld should be enough to make it run lld-link.exe, and you won't need to set the flavor or do anything special to get PE/COFF files. This example worked for me: $ cat t.cpp #include <iostream> int main() { std::cout << "hello world\n"; } $ clang++ t.cpp -fuse-ld=lld -o t.exe && ./t.exe hello world Unfortunately, we don't have a GNU-ld compatible command line interface for the COFF port of LLD, if that's what you're having trouble with. This is something I personally think we should add, but don't have time to pursue. On Wed, Mar 29, 2017 at 7:56 AM, Edward Diener via llvm-dev < llvm-dev at lists.llvm.org> wrote:> I build llvm/clang/lld from source on Windows using mingw-64/gcc-6.3. I > use clang++ both to test clang targeting gcc and clang targeting VC++. When > using clang targeting VC++ I use the appropriate target triple when > compiling and am trying to use lld to link the object file(s) into an exe. > To do that I use the clang option "-fuse-ld=lld" when linking. According to > the llvm doc on using lld with PE/COFF on Windows at > https://lld.llvm.org/windows_support.html: > > "LLD supports Windows operating system. When invoked as lld-link.exe or > with -flavor link, the driver for Windows operating system is used to parse > command line options, and it drives further linking processes. LLD accepts > almost all command line options that the linker shipped with Microsoft > Visual C++ (link.exe) supports." > > Unfortunately with clang++ attempting to use "-fuse-ld=lld-link" when > linking outputs: > > "clang++.exe: error: unsupported value 'lld_link' for -linker option" > > So I must use "-fuse-ld=lld". Does this mean that I should be passing > "-flavor link" to the lld linker ? If so, how do I do that ? If not, what > do I do to have lld work with PE/COFF linking rather than ELF linking ? > > I have attempted to pass to the clang++ when linking: > > 1) "-flavor link", which outputs: > clang++.exe: error: unknown argument: '-flavor' > clang++.exe: error: no such file or directory: 'link' > > 2) -flavor=link", which outputs: > clang++.exe: error: unknown argument: '-flavor=link' > > 3) -Wl,-flavor,link, which outputs > C:\Programming\VersionControl\bninja_installed_clang\bin\lld: error: > unknown argument: -flavor > > 4) -Wl,-flavor=link, which outputs > C:\Programming\VersionControl\bninja_installed_clang\bin\lld: error: > unknown argument: -flavor=link > > What is the "magic" invocation that will allow me to invoke the lld linker > from the clang++ command, but get the linker to work in PE/COFF mode rather > than in ELF mode, so it will link object files created by clang targeting > VC++ ? > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170329/1cbdd1b9/attachment.html>
Edward Diener via llvm-dev
2017-Mar-29 20:59 UTC
[llvm-dev] Invoking lld for PE/COFF (Windows) linking
On 3/29/2017 1:38 PM, Reid Kleckner via llvm-dev wrote:> If clang is targeting VC++, then -fuse-ld=lld should be enough to make > it run lld-link.exe, and you won't need to set the flavor or do anything > special to get PE/COFF files.I build LLVM/cClang/lld with mingw-64/gcc-6.3, not with VC++. If I compile with clang using the target triple of "-target i686-pc-windows-msvc" and "-fmsc-version=1900" for VC++14, the compilation is successful and clang creates a VC++ compatible object file. If I subsequently link using clang++ with link option "-fuse-ld=lld" I get as output: "lld: error: Windows targets are not supported on the ELF frontend: i386pe" If I add the "-target i686-pc-windows-msvc" to the clang++ link command, the clang++ command just hangs and never completes.> > This example worked for me: > > $ cat t.cpp > #include <iostream> > int main() { std::cout << "hello world\n"; } > > $ clang++ t.cpp -fuse-ld=lld -o t.exe && ./t.exe > hello world > > Unfortunately, we don't have a GNU-ld compatible command line interface > for the COFF port of LLD, if that's what you're having trouble with. > This is something I personally think we should add, but don't have time > to pursue. > > On Wed, Mar 29, 2017 at 7:56 AM, Edward Diener via llvm-dev > <llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org>> wrote: > > I build llvm/clang/lld from source on Windows using > mingw-64/gcc-6.3. I use clang++ both to test clang targeting gcc and > clang targeting VC++. When using clang targeting VC++ I use the > appropriate target triple when compiling and am trying to use lld to > link the object file(s) into an exe. To do that I use the clang > option "-fuse-ld=lld" when linking. According to the llvm doc on > using lld with PE/COFF on Windows at > https://lld.llvm.org/windows_support.html > <https://lld.llvm.org/windows_support.html>: > > "LLD supports Windows operating system. When invoked as lld-link.exe > or with -flavor link, the driver for Windows operating system is > used to parse command line options, and it drives further linking > processes. LLD accepts almost all command line options that the > linker shipped with Microsoft Visual C++ (link.exe) supports." > > Unfortunately with clang++ attempting to use "-fuse-ld=lld-link" > when linking outputs: > > "clang++.exe: error: unsupported value 'lld_link' for -linker option" > > So I must use "-fuse-ld=lld". Does this mean that I should be > passing "-flavor link" to the lld linker ? If so, how do I do that ? > If not, what do I do to have lld work with PE/COFF linking rather > than ELF linking ? > > I have attempted to pass to the clang++ when linking: > > 1) "-flavor link", which outputs: > clang++.exe: error: unknown argument: '-flavor' > clang++.exe: error: no such file or directory: 'link' > > 2) -flavor=link", which outputs: > clang++.exe: error: unknown argument: '-flavor=link' > > 3) -Wl,-flavor,link, which outputs > C:\Programming\VersionControl\bninja_installed_clang\bin\lld: error: > unknown argument: -flavor > > 4) -Wl,-flavor=link, which outputs > C:\Programming\VersionControl\bninja_installed_clang\bin\lld: error: > unknown argument: -flavor=link > > What is the "magic" invocation that will allow me to invoke the lld > linker from the clang++ command, but get the linker to work in > PE/COFF mode rather than in ELF mode, so it will link object files > created by clang targeting VC++ ? > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org> > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev > <http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev> > > > > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >
Edward Diener via llvm-dev
2017-Mar-30 13:08 UTC
[llvm-dev] Invoking lld for PE/COFF (Windows) linking
On 3/29/2017 1:38 PM, Reid Kleckner via llvm-dev wrote:> If clang is targeting VC++, then -fuse-ld=lld should be enough to make > it run lld-link.exe, and you won't need to set the flavor or do anything > special to get PE/COFF files. > > This example worked for me: > > $ cat t.cpp > #include <iostream> > int main() { std::cout << "hello world\n"; } > > $ clang++ t.cpp -fuse-ld=lld -o t.exe && ./t.exe > hello world > > Unfortunately, we don't have a GNU-ld compatible command line interface > for the COFF port of LLD, if that's what you're having trouble with. > This is something I personally think we should add, but don't have time > to pursue.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.> > On Wed, Mar 29, 2017 at 7:56 AM, Edward Diener via llvm-dev > <llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org>> wrote: > > I build llvm/clang/lld from source on Windows using > mingw-64/gcc-6.3. I use clang++ both to test clang targeting gcc and > clang targeting VC++. When using clang targeting VC++ I use the > appropriate target triple when compiling and am trying to use lld to > link the object file(s) into an exe. To do that I use the clang > option "-fuse-ld=lld" when linking. According to the llvm doc on > using lld with PE/COFF on Windows at > https://lld.llvm.org/windows_support.html > <https://lld.llvm.org/windows_support.html>: > > "LLD supports Windows operating system. When invoked as lld-link.exe > or with -flavor link, the driver for Windows operating system is > used to parse command line options, and it drives further linking > processes. LLD accepts almost all command line options that the > linker shipped with Microsoft Visual C++ (link.exe) supports." > > Unfortunately with clang++ attempting to use "-fuse-ld=lld-link" > when linking outputs: > > "clang++.exe: error: unsupported value 'lld_link' for -linker option" > > So I must use "-fuse-ld=lld". Does this mean that I should be > passing "-flavor link" to the lld linker ? If so, how do I do that ? > If not, what do I do to have lld work with PE/COFF linking rather > than ELF linking ? > > I have attempted to pass to the clang++ when linking: > > 1) "-flavor link", which outputs: > clang++.exe: error: unknown argument: '-flavor' > clang++.exe: error: no such file or directory: 'link' > > 2) -flavor=link", which outputs: > clang++.exe: error: unknown argument: '-flavor=link' > > 3) -Wl,-flavor,link, which outputs > C:\Programming\VersionControl\bninja_installed_clang\bin\lld: error: > unknown argument: -flavor > > 4) -Wl,-flavor=link, which outputs > C:\Programming\VersionControl\bninja_installed_clang\bin\lld: error: > unknown argument: -flavor=link > > What is the "magic" invocation that will allow me to invoke the lld > linker from the clang++ command, but get the linker to work in > PE/COFF mode rather than in ELF mode, so it will link object files > created by clang targeting VC++ ?