This is an archive of the discontinued LLVM Phabricator instance.

[LLD] [COFF] In MinGW mode, ignore relocations against a discarded section
ClosedPublic

Authored by mstorsjo on Sep 27 2018, 4:14 AM.

Details

Summary

When GCC produces a jump table as part of a comdat function, the jump table itself is produced as plain non-comdat rdata section. When linked with ld.bfd, all of those rdata sections are kept, with relocations unchanged in the sections that refer to discarded comdat sections.

This has been observed with GCC 5.x and 7.x.

I know this change is extremely ugly, but I don't really know what else to do about it...

I know I earlier said support for linking GCC produced object files with LLD was a non-goal. After getting support for GNU import libraries and GNU ld compatible CTOR_LIST, using LLD as an actual drop-in replacement for GNU ld in existing setups with GCC actually is totally viable though.

With these three patches, I'm able to link clang.exe with LLD, out of object files compiled with GCC.

Diff Detail

Repository
rL LLVM

Event Timeline

mstorsjo created this revision.Sep 27 2018, 4:14 AM
ruiu accepted this revision.Sep 27 2018, 4:45 AM

LGTM

This is a hack and the fact that we need it is unfortunate, but looks like GNU linkers historically doesn't check that kind of bad relocations, and I don't think there's any other way to workaround. We have a similar code for ELF.

At this point, I have no objection (and actually happy to see) to make lld a drop-in replacement for the GNU linker for MinGW. Thank you for doing this!

This revision is now accepted and ready to land.Sep 27 2018, 4:45 AM
This revision was automatically updated to reflect the committed changes.
rnk added a comment.Oct 1 2018, 11:48 AM

:( This makes me very sad. GCC shouldn't generate broken code.

In D52600#1251446, @rnk wrote:

:( This makes me very sad. GCC shouldn't generate broken code.

Yeah, this one is rather terrifying... FWIW, this case can be reproduced with a pretty small test snippet: http://martin.st/temp/jumptable.cpp, x86_64-w64-mingw32-g++ jumptable.cpp -o - -O2 -S