Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linux: Don't default to ld.gold linker & fix TLS range with static x86/x64 druntime #3848

Merged
merged 8 commits into from
Oct 24, 2021

Conversation

kinke
Copy link
Member

@kinke kinke commented Oct 13, 2021

I hope the issues with old bfd aren't really a thing anymore.

The main reason is that the user might have set LLD as default /usr/bin/ld symlink, and LDC not using it by default isn't intuitive. And LLD can be significantly faster than gold.

@kinke
Copy link
Member Author

kinke commented Oct 13, 2021

For reference, here are some linking times on Ubuntu 20.04 for a pretty large executable (~1.1 GB with debuginfos, FWIW compiled with DMD) using the distro linkers:

bfd v2.34:
	Elapsed (wall clock) time (h:mm:ss or m:ss): 1:26.59
	Maximum resident set size (kbytes): 16211232

gold v1.16 (from binutils v2.34):
	Elapsed (wall clock) time (h:mm:ss or m:ss): 0:18.23
	Maximum resident set size (kbytes): 10524112

lld v10.0.0:
	Elapsed (wall clock) time (h:mm:ss or m:ss): 0:05.48
	Maximum resident set size (kbytes): 6338564

@kinke
Copy link
Member Author

kinke commented Oct 13, 2021

Oh, lld is more picky than gold, and rightfully so:

ld: error: duplicate symbol: std::bad_exception::~bad_exception()
>>> defined in /usr/lib/gcc/x86_64-linux-gnu/10/libstdc++.a(eh_exception.o)
>>> defined in /home/vsts/work/1/bootstrap-ldc/lib/libdruntime-ldc-lto.a(exception.bc.o)

ld: error: duplicate symbol: std::bad_cast::~bad_cast()
>>> defined in /home/vsts/work/1/bootstrap-ldc/lib/libdruntime-ldc-lto.a(typeinfo.bc.o)
>>> defined in /usr/lib/gcc/x86_64-linux-gnu/10/libstdc++.a(bad_cast.o)

ld: error: duplicate symbol: std::bad_typeid::~bad_typeid()
>>> defined in /home/vsts/work/1/bootstrap-ldc/lib/libdruntime-ldc-lto.a(typeinfo.bc.o)
>>> defined in /usr/lib/gcc/x86_64-linux-gnu/10/libstdc++.a(bad_typeid.o)

These are auto-generated dtors which don't inherit the @weak UDA of the dtor in the base class...

@kinke
Copy link
Member Author

kinke commented Oct 14, 2021

The frontend workaround is now proposed as dlang/dmd#13167. It's really just a workaround for simple cases like this, and just addressing the IMO oddity that derived C++ classes get a superfluous dtor, even if they don't introduce any new fields requiring destruction or user dtors. The @weak UDA limitation only affecting the user dtor is still in place.

Not using gold has led to #3849. And the LTO lit-tests with lld run into #3786 apparently.

I hope the issues with old bfd aren't really a thing anymore.

The main reason is that the user might have set LLD as default
`/usr/bin/ld` symlink, and LDC not using it by default isn't
intuitive. And LLD can be significantly faster than gold.
bfd cannot be used for linking the final compiler with LTO, it
rejects bitcode .a libs.
As bfd doesn't support lib{druntime,phobos}-ldc-lto.a libs.
@kinke kinke changed the title Linux: Don't default to ld.gold linker Linux: Don't default to ld.gold linker & fix TLS range with static x86/x64 druntime Oct 24, 2021
After some manual tests with bfd and lld linkers, this should fix ldc-developers#3849.
As for Azure CI Linux, using the LLD bundled with the LDC-LLVM
package and thus matching the LLVM version LDC is linked against.

The prebuilt Linux packages are thus linked with LLD now.
Now that lld is tested by Azure & Travis, use GH Actions for gold.
Cirrus & Circle use bfd.
@kinke kinke merged commit 92e080f into ldc-developers:master Oct 24, 2021
@kinke kinke deleted the linux_no_default_linker branch October 24, 2021 19:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant