www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.ldc - Linux LTO with lld from llvm 9

reply Newbie2019 <newbie2019 gmail.com> writes:
If I link without druntime, can I use lld from linux ?

when I link with gold I get this error:

ld-new: fatal error: LLVM gold plugin has failed to create LTO 
module: Unknown attribute kind (62) (Producer: 'LLVM9.0.0' 
Reader: 'LLVM 8.0.1')
clang-8: error: linker command failed with exit code 1 (use -v to 
see invocation)

I try rebuild the ld-new, but seems not fix the problem.

I guess lld is a better link since it from llvm team,  how can i 
use it with ldc or clang for LTO and linux ?
Oct 03 2019
next sibling parent reply kinke <kinke gmx.net> writes:
On Friday, 4 October 2019 at 03:06:19 UTC, Newbie2019 wrote:
 If I link without druntime, can I use lld from linux ?
Should work, independent from whether you link with or without druntime. If you have clang and lld installed, specify `-gcc=clang -linker=lld` in the LDC cmdline; when linking with clang directly, use `-fuse-ld=lld`.
 ld-new: fatal error: LLVM gold plugin has failed to create LTO 
 module: Unknown attribute kind (62) (Producer: 'LLVM9.0.0' 
 Reader: 'LLVM 8.0.1')
 clang-8: error: linker command failed with exit code 1 (use -v 
 to see invocation)
The problem here is that the produced bitcode is v9, but the gold plugin is from LLVM v8.0.1. LDC v1.18.0-beta2 features the v9 gold plugin; it'll probably also work when updating your clang to v9.
Oct 04 2019
parent reply Newbie2019 <newbie2019 gmail.com> writes:
On Friday, 4 October 2019 at 09:54:44 UTC, kinke wrote:
 The problem here is that the produced bitcode is v9, but the 
 gold plugin is from LLVM v8.0.1. LDC v1.18.0-beta2 features the 
 v9 gold plugin; it'll probably also work when updating your 
 clang to v9.
Thanks for the explain. I add `-gcc=clang -linker=lld --plugin=/opt/build/llvm/build/lib/libLTO.so --flto-binary=/opt/build/llvm/build/lib/libLTO.so` to ldc, but ldc2 not pass libLTO.so into clang, and the ld.lld still run with `-plugin /usr/bin/../lib/LLVMgold.so`. how could I use the new builded libLTO.so instead LLVMgold.so ? On Friday, 4 October 2019 at 14:50:26 UTC, David Nadlinger wrote:
 Seems like you are trying to use LTO with LDC built against 
 LLVM 9.0, but the linker plugin (probably from clang) is built 
 against LLVM 8.0? The plugin [1] is separate from the linker 
 itself.

 ld.gold should generally work fine. Perhaps others can chime in 
 as to what the current situation with LLD on Linux is; I 
 haven't tried it recently.
Thanks for the explain.
Oct 10 2019
parent reply kinke <noone nowhere.com> writes:
On Thursday, 10 October 2019 at 08:44:32 UTC, Newbie2019 wrote:
 On Friday, 4 October 2019 at 09:54:44 UTC, kinke wrote:
 The problem here is that the produced bitcode is v9, but the 
 gold plugin is from LLVM v8.0.1. LDC v1.18.0-beta2 features 
 the v9 gold plugin; it'll probably also work when updating 
 your clang to v9.
Thanks for the explain. I add `-gcc=clang -linker=lld --plugin=/opt/build/llvm/build/lib/libLTO.so --flto-binary=/opt/build/llvm/build/lib/libLTO.so` to ldc, but ldc2 not pass libLTO.so into clang, and the ld.lld still run with `-plugin /usr/bin/../lib/LLVMgold.so`. how could I use the new builded libLTO.so instead LLVMgold.so ?
Since v1.17, LDC doesn't specify the plugin anymore when linking with LLD, as it shouldn't need it. So looks like your clang is adding a plugin path. You can explicitly add it with `-L-plugin=/opt/build/llvm/build/lib/libLTO.so` (`-plugin` is for LLVM/clang plugins) in the LDC cmdline (and make sure to specify `-flto=<thin|full>`). If you don't succeed, try with `-linker=gold`, where the plugin path is added by LDC automatically.
Oct 10 2019
parent reply kinke <noone nowhere.com> writes:
On Thursday, 10 October 2019 at 18:53:22 UTC, kinke wrote:
 If you don't succeed, try with `-linker=gold`, where the plugin 
 path is added by LDC automatically.
And, more importantly, the linker definitely uses that plugin with matching LLVM version; LLD might ignore it and so use its LLVM, which is apparently v8 in your case.
Oct 10 2019
parent Newbie2019 <newbie2019 gmail.com> writes:
On Thursday, 10 October 2019 at 18:56:31 UTC, kinke wrote:
 And, more importantly, the linker definitely uses that plugin 
 with matching LLVM version; LLD might ignore it and so use its 
 LLVM, which is apparently v8 in your case.
I rebuild ldc with lld & llvm9, it can generate the binary with clang8. with -linker=gold, or with -L-plugin=. make the link pass 2 or 3 plugin to link. /opt/local/bin/ld.lld -z now -z relro --hash-style=gnu --eh-frame-hdr -m elf_x86_64 -static -o tests_ng2.exe /usr/bin/../lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../crt1.o /usr/bin/../lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../crti.o /usr/bin/../lib/gcc/x86_64-alpine-linux-musl/9.2.0/crtbeginT.o -Llib -L/opt/build/lib -L/usr/bin/../lib/gcc/x86_64-alpine-linux-musl/9.2.0 -L/usr/bin/../lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-a pine-linux-musl/lib -L/usr/bin/../lib/gcc/x86_64-alpine-linux musl/9.2.0/../../.. -L/usr/bin/../lib -L/lib -L/usr/lib -plugin /usr/bin/../lib/LLVMgold.so -plugin-opt=mcpu=x86-64 -z now -z noexecstack -z text /opt/d/tests_ng2.o -plugin /usr/lib/LLVMgold.so -plugin-opt=mcpu=x86-64 -plugin-opt=O0 -plugin-opt=-function-sections -plugin-opt=-data-sections -plugin=/opt/build/llvm/build/lib/libLTO.so -lng2 -lncursesw -lrt -lpthread -lm -ldl -lpthread --start-group -lgcc -lgcc_eh --end-group /usr/bin/../lib/gcc/x86_64-alpine-linux-musl/9.2.0/crtend.o /usr/bin/../lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../crtn.o --gc-sections -plugin-opt=O3 -lssl -lcrypto -lc -lgcc the generate binary md5 hash seems is same when pass multi plugin.
Oct 11 2019
prev sibling parent "David Nadlinger" <code klickverbot.at> writes:
On 4 Oct 2019, at 4:06, Newbie2019 via digitalmars-d-ldc wrote:
 when I link with gold I get this error:

 ld-new: fatal error: LLVM gold plugin has failed to create LTO module: 
 Unknown attribute kind (62) (Producer: 'LLVM9.0.0' Reader: 'LLVM 
 8.0.1')
 clang-8: error: linker command failed with exit code 1 (use -v to see 
 invocation)
Seems like you are trying to use LTO with LDC built against LLVM 9.0, but the linker plugin (probably from clang) is built against LLVM 8.0? The plugin [1] is separate from the linker itself. ld.gold should generally work fine. Perhaps others can chime in as to what the current situation with LLD on Linux is; I haven't tried it recently. — David [1] https://llvm.org/docs/GoldPlugin.html
Oct 04 2019