This is an archive of the discontinued LLVM Phabricator instance.

Garbage collect dllimported symbols.
ClosedPublic

Authored by ruiu on May 16 2017, 4:22 PM.

Details

Summary

Previously, the garbage collector (enabled by default or by explicitly
passing /opt:ref) did not kill dllimported symbols. As a result,
dllimported symbols could be added to resulting executables' dllimport
list even if no one was actually using them.

This patch implements dllexported symbol garbage collection. Just like
COMDAT sections, dllimported symbols now have Live bits to manage their
liveness, and MarkLive marks reachable dllimported symbols.

Fixes https://bugs.llvm.org/show_bug.cgi?id=32950

Diff Detail

Repository
rL LLVM

Event Timeline

ruiu created this revision.May 16 2017, 4:22 PM
pcc edited edge metadata.May 16 2017, 4:35 PM

A high level question: we are already using chunks to represent "GOTs" and "PLTs" for imported symbols. Would it not work to move the live bit to Chunk and track liveness of these special chunks in the same way as with regular chunks?

ruiu added a comment.May 16 2017, 4:42 PM

That should theoretically work, but I can imagine that that will be more complicated than this. Chunks for dllimported symbols are created not when they are read from file but when writer needs them, so at the time when MarkLive runs, chunks for dllimported symbols don't exist.

pcc added a comment.May 16 2017, 5:45 PM
In D33264#756872, @ruiu wrote:

That should theoretically work, but I can imagine that that will be more complicated than this. Chunks for dllimported symbols are created not when they are read from file but when writer needs them, so at the time when MarkLive runs, chunks for dllimported symbols don't exist.

I see. We could always try and create the import chunks earlier though. But that seems like a separate potential refactoring.

lld/COFF/MarkLive.cpp
41 ↗(On Diff #99224)

This could just use auto.

lld/COFF/Symbols.h
310 ↗(On Diff #99224)

nit: "to the other symbol."

This revision was automatically updated to reflect the committed changes.
ruiu added inline comments.May 16 2017, 5:50 PM
lld/COFF/MarkLive.cpp
41 ↗(On Diff #99224)

It doesn't compile, as this is a recursive function.

ruiu added a comment.May 16 2017, 5:56 PM

I've submitted this change by mistake, but I got OK from Peter verbally.