[PATCH] D52053: [LLD] [COFF] Provide __CTOR_LIST__ and __DTOR_LIST__ symbols for MinGW

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 13 12:53:55 PDT 2018


mstorsjo created this revision.
mstorsjo added reviewers: ruiu, rnk, pcc.
Herald added a reviewer: javed.absar.

MinGW uses these kind of list terminator symbols for traversing the constructor/destructor lists. These list terminators are actual pointers entries in the lists, with the values 0 and (uintptr_t)-1 (instead of just symbols pointing to the start/end of the list).

(This mechanism exists in both the mingw-w64 crt startup code and in libgcc; normally the mingw-w64 one is used, but a DLL build of libgcc uses the libgcc one. Therefore it's not trivial to change the mechanism without lots of cross-project synchronization and potentially invalidating some combinations of old/new versions of them.)

When mingw-w64 has been used with lld so far, the CRT startup object files have so far provided these symbols, ending up with different, incompatible builds of the CRT startup object files depending on whether binutils or lld are going to be used.

In order to avoid the need of different configuration of the CRT startup object files depending on what linker to be used, provide these symbols in lld instead. (Mingw-w64 checks at build time whether the linker provides these symbols or not.) This unifies this particular detail between the two linkers.

This does disallow the use of the very latest lld with older versions of mingw-w64 (the configure check for the list was added recently; earlier it simply checked whether the CRT was built with gcc or clang), and requires rebuilding the mingw-w64 CRT. But the number of users of lld+mingw still is low enough that such a change should be tolerable, and unifies this aspect of the toolchains, easing  interoperability between the toolchains for the future.

The actual test for this feature is added in ctors_dtors_priority.s, but a number of other tests that checked absolute output addresses are updated.

This is one out of two missing features to make ld.lld a fully working drop-in replacement for ld.bfd in existing mingw sysroots.


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D52053

Files:
  COFF/Chunks.cpp
  COFF/Chunks.h
  COFF/Driver.cpp
  COFF/Writer.cpp
  COFF/Writer.h
  test/COFF/associative-comdat-mingw.s
  test/COFF/autoimport-arm-data.s
  test/COFF/autoimport-arm64-data.s
  test/COFF/autoimport-list-ptrs.s
  test/COFF/autoimport-refptr.s
  test/COFF/autoimport-x86.s
  test/COFF/common-replacement.s
  test/COFF/ctors_dtors_priority.s
  test/COFF/debug-reloc.s

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52053.165358.patch
Type: text/x-patch
Size: 15506 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180913/5cdc064e/attachment.bin>


More information about the llvm-commits mailing list