This is an archive of the discontinued LLVM Phabricator instance.

[LLD] [COFF] When doing automatic dll imports, replace whole .refptr.<var> chunks with __imp_<var>
ClosedPublic

Authored by mstorsjo on Aug 29 2018, 1:14 PM.

Details

Summary

After fixing up the runtime pseudo relocation, the .refptr.<var> will be a plain pointer with the same value as the IAT entry itself. To save a little binary size and reduce the number of runtime pseudo relocations, redirect references to the IAT entry (via the __imp_<var> symbol) itself and discard the .refptr.<var> chunk (as long as the same section chunk doesn't contain anything else than the single pointer).

Diff Detail

Repository
rL LLVM

Event Timeline

mstorsjo created this revision.Aug 29 2018, 1:14 PM
rnk accepted this revision.Aug 29 2018, 3:09 PM

lgtm

test/COFF/autoimport-refptr.s
35 ↗(On Diff #163169)

Hm, they really should put a colon after the address to make this easier to read. =/

This revision is now accepted and ready to land.Aug 29 2018, 3:09 PM
ruiu added inline comments.Aug 29 2018, 6:03 PM
COFF/Chunks.h
189 ↗(On Diff #163169)

Now Live member has both read and write accessors, so I'd make it a public member and remove this function and isLive.

COFF/SymbolTable.cpp
173 ↗(On Diff #163169)

This probably needs comment as I believe this is hard to understand for those who don't know what the intention of this code is.

mstorsjo added inline comments.Aug 29 2018, 10:07 PM
COFF/Chunks.h
189 ↗(On Diff #163169)

Ok - what about the markLive function, should I remove that one as well? Or do we want to keep it for the sake of the asserts?

ruiu added inline comments.Aug 29 2018, 10:17 PM
COFF/Chunks.h
189 ↗(On Diff #163169)

Looks like the only use of markLive is in MarkLive.cpp, and if you remove that function and inline it, it is obvious that you don't really need these asserts. So, yes, we should remove markLive function.

mstorsjo updated this revision to Diff 163254.Aug 29 2018, 10:18 PM

Dropped the isLive() and discard() accessors and made Live public instead. Kept the markLive accessor since it has got useful asserts.

COFF/SymbolTable.cpp
173 ↗(On Diff #163169)

I added some kind of summary in a comment here.

mstorsjo added inline comments.Aug 30 2018, 9:03 PM
COFF/Chunks.h
189 ↗(On Diff #163169)

Sorry, I missed this comment, as it was added right before I updated the diff yesterday.

Will remove that method as well, and commit this.

mstorsjo added inline comments.Aug 31 2018, 12:46 AM
COFF/SymbolTable.cpp
182 ↗(On Diff #163254)

I added another extra sanity check that the Refptr chunk only contains 1 relocation and that it points at this specific symbol that we're importing, before I committed this.

This revision was automatically updated to reflect the committed changes.