ldc-developers / ldc

The LLVM-based D Compiler.
http://wiki.dlang.org/LDC
Other
1.19k stars 258 forks source link

`-link-internally` on Posix requires manually specifying arguments #2717

Open dlblv opened 6 years ago

dlblv commented 6 years ago

Archlinux, ldc 1.9.0, using DUB 1.9.0 to build projects.

dflags "-link-internally"
ldc2: Unknown command line argument '-link-internally'.  Try: 'ldc2 -help'

dflags "-linker=lld"
gcc: error: unrecognized command line option ‘-fuse-ld=lld’; did you mean ‘-fuse-ld=bfd’?

dflags "-linker=ld.lld"
gcc: error: unrecognized command line option ‘-fuse-ld=ld.lld’; did you mean ‘-fuse-ld=gold’?

Why does LDC 1.9.0 still use GCC? How can I switch it to use LLVM stack only (under both Linux and Windows)?

On version 1.10.0 beta1 strange thing occurs:

~/ldc2-1.10.0-beta1-linux-x86_64/bin/ldc2 -link-internally retrycatch.d                                                                                                   
 ��: error: unknown argument: --no-warn-search-mismatch
 ��: error: unable to find library -lrt
 ��: error: unable to find library -ldl
 ��: error: unable to find library -lpthread
 ��: error: unable to find library -lm
Error: linking with LLD failed

or

CC=clang ~/ldc2-1.10.0-beta1-linux-x86_64/bin/ldc2 -linker=lld retrycatch.d
/usr/bin/ld.lld: error: unknown argument: --no-warn-search-mismatch
clang-6.0: error: linker command failed with exit code 1 (use -v to see invocation)
Error: /usr/bin/clang failed with status: 1
kinke commented 6 years ago

-link-internally is still somewhat experimental (no LTO, LLD compatibility issues with Apple's ld64), and is only available if the LLD libs are available when building LDC, which apparently wasn't the case when building the ArchLinux package (please file an issue there if that bothers you, we don't maintain distro packages ourselves). The official prebuilt release package features it.

Additionally, the C system libs etc. are still needed as linker input, so if you don't go through gcc, you have to specify them manually; see the PR linked in the release notes. Edit: this doesn't apply to Windows/MSVC, where it's working fine without additional linker flags as long as you have a MSVC installation.

kinke commented 6 years ago

Wrt. to your extended post now:

jacob-carlborg commented 6 years ago

FYI, using LLD works with a betterC Hello World program on macOS without any additional flags, see the bottom of this post https://github.com/ldc-developers/ldc/issues/2662#issuecomment-383698114,

joakim-noah commented 6 years ago

Also see recent forum thread and issue #2028, the upshot being that it would be almost impossible for us to support the crazy variety of linux distros and alternate toolchains, so we offload that work to the specially-configured C compilers.

dnadlinger commented 6 years ago

We could in theory still provide a script/command line flag to extract the linker flags from gcc -v and store them to our config file to later be used.

kinke commented 6 years ago

I see the main usage of -link-internally for cross-linking (at least for Posix), so manual tweaking will most likely be required in those cases anyway. I fail to see a reason to use it for normal linking on Posix, at least as long as LTO doesn't work that way.