Faster linker

Joakim dlang at
Sat Nov 10 15:15:30 UTC 2018

On Saturday, 10 November 2018 at 13:38:09 UTC, Kagamin wrote:
> On Friday, 9 November 2018 at 15:30:24 UTC, Joakim wrote:
>> I plan on moving the native packages for the Termux app on 
>> Android to use -link-internally by default (they currently 
>> default to clang/bfd), since it should be straightforward to 
>> add the necessary linker flags and logic for that limited 
>> environment. Maybe we could do that for Mac and even Windows 
>> someday too, but I can't imagine we'll ever have an official 
>> ldc that works for every linux distro! ;)
> Can't Debian-based systems be covered?

Why, because it's the most common distro? I've never really used 
Debian much- I've long preferred and used Arch- but I just looked 
up what would be needed on Ubuntu 18.04.

Building a simple sample D file with the latest ldc 1.3 beta 
shows the following linker command invoked by the system 
compiler, gcc:

/usr/lib/gcc/x86_64-linux-gnu/7/collect2 -plugin 
-plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s 
-plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc 
-plugin-opt=-pass-through=-lgcc_s --sysroot=/ --build-id 
--eh-frame-hdr -m elf_x86_64 --hash-style=gnu --as-needed 
-dynamic-linker /lib64/ -pie -z now 
-fuse-ld=gold -z relro -o sieve 
-L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu 
-L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/7/../../.. 
sieve.o --no-warn-search-mismatch -lphobos2-ldc -ldruntime-ldc 
--gc-sections -lrt -ldl -lpthread -lm -lgcc --push-state 
--as-needed -lgcc_s --pop-state -lc -lgcc --push-state 
--as-needed -lgcc_s --pop-state 

Some of that isn't strictly necessary, but you will likely need 
those libc files that it automatically adds, which dpkg tells me 
come in the libc6-dev and libgcc-7-dev packages.

OK, but how do we know to look in those packages' paths without 
the pre-configured system gcc telling us? Try running `apt search 
libc`: you'll come up with a ton of alternative packages, with 
many other paths and libc files that could've been used.

I'm not saying it couldn't be done to some extent, but it seems a 
pain even on Ubuntu alone.

> It may make sense to have a config section for internal linker 
> arguments, so that if it doesn't work, cc can still be used.

If you mean a config file, I think you could use ldc's ldc2.conf 
for that. And yeah, you could have ldc switch back and forth 
between a config for its internal lld and the external C compiler.

This all depends on someone putting in the work to remove that 
current dependency on the C compiler on various platforms. I'll 
be looking into it for the ldc package on Termux for Android, 
you're free to do the same on any other platform.

More information about the Digitalmars-d mailing list