This backports the following two fixes from upstream lld:
------------------------------------------------------------------------ r315334 | rafael | 2017-10-10 19:27:34 +0200 (Tue, 10 Oct 2017) | 12 lines Don't create a dummy __tls_get_addr. We just don't need one with the current setup. We only error on undefined references that are used by some relocation. If we managed to relax all uses of __tls_get_addr, no relocation uses it and we don't produce an error. This is less code and fixes the case were we fail to relax. Before we would produce a broken output, but now we produce an error. ------------------------------------------------------------------------ r320390 | rafael | 2017-12-11 18:23:28 +0100 (Mon, 11 Dec 2017) | 18 lines Create reserved symbols early so they can be versioned. This fixes pr35570. We were creating these symbols after parsing version scripts, so they could not be versioned. We cannot move the version script parsing later because we need it for lto. One option is to move both addReservedSymbols and createSyntheticSections earlier. The disadvantage is that some sections created by createSyntheticSections replace other input sections. For example, gdb index replaces .debug_gnu_pubnames, so it wants to run after gc sections so that it can set S->Live to false. What this patch does instead is to move just the ElfHeader creation early. ------------------------------------------------------------------------
This should ensure that reserved symbols such as _end, _edata etc
get correctly placed into executables, making brk(2) and sbrk(2) work,
and thereby fixing programs that use these, such as emacs.