This is an archive of the discontinued LLVM Phabricator instance.

Garbage collect dllimported symbols.
ClosedPublic

Authored by ruiu on May 24 2017, 2:42 PM.

Details

Summary

This is a different implementation than r303225 (which was reverted
in r303270, re-submitted in r303304 and then re-reverted in r303527).

In the previous patch, I tried to add Live bit to each dllimported
symbol. It turned out that it didn't work with "oldnames.lib" which
contains a lot of weak aliases to dllimported symbols.

The way we handle weak aliases is to check if undefined symbols
can be resolved using weak aliases, and if so, memcpy the Defined
symbols to weak Undefined symbols, so that any references to weak
aliases automatically see defined symbols instead of undefined ones.

This memcpy happens before MarkLive kicks in.

That means we may have multiple copies of dllimported symbols. So
turning on one instance's Live bit is not enough.

This patch moves the Live bit to dllimport file. Since multiple
copies of dllsymbols still point to the same file, we can use it as the
central repository to keep track of liveness.

Diff Detail

Repository
rL LLVM

Event Timeline

ruiu created this revision.May 24 2017, 2:42 PM
ruiu edited the summary of this revision. (Show Details)May 24 2017, 2:47 PM
pcc edited edge metadata.May 24 2017, 2:50 PM

Can you construct a test case that shows that we handle weak externals correctly?

lld/COFF/Writer.cpp
454 ↗(On Diff #100165)

I guess this means that we are not gc'ing unused thunks any more. But I guess this isn't a regression, so it seems fine to me.

ruiu updated this revision to Diff 100170.May 24 2017, 3:01 PM
  • Added a test
ruiu added inline comments.May 24 2017, 3:02 PM
lld/COFF/Writer.cpp
454 ↗(On Diff #100165)

Yes, that is correct. But in practice we are interested only in eliminating dependencies to DLL files and not to each symbol in a DLL, so it should be fine.

pcc accepted this revision.May 24 2017, 3:21 PM

LGTM

lld/test/COFF/dllimport-gc.test
27 ↗(On Diff #100170)

I think you can remove this line.

37 ↗(On Diff #100170)

Can this just be NumberOfRelocations: 0?

This revision is now accepted and ready to land.May 24 2017, 3:21 PM
This revision was automatically updated to reflect the committed changes.