Simplify DSO registration with druntime#2870
Conversation
|
Number of global {c,d}tor pairs for a Phobos hello-world with LDC v1.11: 143 => Eliding 141 useless ctor/dtor calls on startup/shutdown & 2x142 functions (explicit {c,d}tor functions). The asm/IR output for trivial test cases will also be much nicer (147 vs. 211 lines for a printf hello-world |
|
Hmm, Travis' ld v2.24 apparently strips the ModuleInfos; CircleCI (also based on Ubuntu 14.04) works with gold. Mac is looking bad too (well, when linking against static druntime/Phobos, fine with shared ones). |
|
Yep, as per the comments, a lot of the complexity comes from --gc-sections. |
|
It's working with Ubuntu 18.04's ld (bfd) v2.30 at least, otherwise I wouldn't have opened this PR, so older versions of ld not respecting Do you know if ld64 is doing something similar implicitly? AFAIK we only use |
|
Btw how would you guys feel about dropping LLVM support for < 3.9? IIRC, that's the minimum version required for MSVC and LTO, and there are 61 occurrences of |
|
AFAICT, the problem for macOS is that the global {c,d}tors aren't folded to a single pair. From SSH session: So there are 0x480 / 8 = 144 ModuleInfos, and unfortunately the same number of ctors/dtors, while there should be a single one for those. As each [The symptom is quite a different one, an LDC segfault in |
|
Further findings: the 'workaround' leads to the same symptom on Linux, apparently because the manual {c,d}tor refs are stripped - makes sense. So I added them to |
17f1301 to
3b14f9c
Compare
|
Emitting the refs manually works for macOS, they are folded correctly. Without putting them into |
Fine with me. LLVM 3.9 was released 2 years ago. (it's perhaps nice that we support so many LLVM versions, but it is a burden and I don't know how many people actually make use of that; clang only supports one LLVM version ;-) ) |
d64e005 to
d1e9309
Compare
* The explicit reference to the ModuleInfo should be obsolete, it's
added to the llvm.used array.
* Only keep a single pair of ldc.dso_{c,d}tor per DSO (pointing to a
common ldc.register_dso() function) instead of a pair per linked-in D
object file. This simplifies ldc.register_dso() and allows to get rid
of the explicit ctor/dtor functions and the ldc.dso_initialized global.
|
We should write down clearer in the release notes why the default linker is now |
If that's the case, worse indeed! Part of what made this difficult to develop in the first instance is precisely that users expect a compiler to just work with "the linker"; probably not many are aware that there are different linkers, or if they are, that there are differences beyond linking speed. |
It does under following circumstances OTOH:
[What makes it worse is that the error msg doesn't say To me, the advantages of this PR are clear (excl. the switch to [I assumed |
gold is included in the |
|
Debian also includes gold in its oldest supported |
|
Trusty's It's missing in AArch64's native Edit: I checked all binutils Trusty packages - arm64 is the only one missing gold, i.e., PowerPC etc. all include it. I also checked Arch and Fedora (recent ones, x86_64 only), they include it; I couldn't quickly find a file listing for the Suse package. |
|
So unless there are other prominent distros missing gold, I'd say this is fine, considering Trusty reaches EOL in half a year anyway. gold being significantly faster and preventing LTO issues makes it a rather good default on Linux IMO. I'm not sure mentioning that an explicit |
|
It is very nice that you did the digging to get data about availability of ld.gold, thanks. |
llvm.usedarray.ldc.dso_{c,d}torper DSO (pointing to a commonldc.register_dso()function) instead of a pair per linked-in D object file. This simplifiesldc.register_dso()and allows to get rid of the explicit ctor/dtor functions and theldc.dso_initializedglobal.