This is an archive of the discontinued LLVM Phabricator instance.

Merge SymbolBody and Symbol into one class, SymbolBody.
ClosedPublic

Authored by ruiu on Oct 29 2017, 9:06 AM.

Details

Summary

SymbolBody and Symbol were separated classes due to a historical reason.
Symbol used to be a pointer to a SymbolBody, and the relationship
between Symbol and SymbolBody was n:1.

r2681780 changed that. Since that patch, SymbolBody and Symbol are
allocated next to each other to improve memory locality, and they have
1:1 relationship now. So, the separation of Symbol and SymbolBody no
longer makes sense.

This patch merges them into one class. In order to avoid updating too
many places, I chose SymbolBody as a unified name. I'll rename it Symbol
in a follow-up patch.

Diff Detail

Repository
rL LLVM

Event Timeline

ruiu created this revision.Oct 29 2017, 9:06 AM
ruiu updated this revision to Diff 120751.Oct 29 2017, 9:15 AM
  • minor updates to remove redundant assignments and update comments.

I assume a corresponding change will also be made for COFF afterward?

pcc edited edge metadata.Oct 29 2017, 12:10 PM

I think this change makes sense at least from a stylistic perspective. The original idea of the split was to separate symbol properties from symbol name properties, but that created other issues like where to put member functions.

This change will increase the size of a local symbol by two words, so it would probably be worth doing some perf measurements.

Might want to update docs/NewLLD.rst as well.

lld/ELF/Symbols.h
54 ↗(On Diff #120751)

This comment needs to be updated.

152 ↗(On Diff #120751)

I think this change will allow you to remove this field and replace it with a comparison on binding. Probably should be done in a follow-up though.

411 ↗(On Diff #120751)

Why drop the asserts?

415 ↗(On Diff #120751)

Also want LazyObject here.

ruiu updated this revision to Diff 120756.Oct 29 2017, 2:01 PM
  • Updated the document.
ruiu added a comment.Oct 29 2017, 2:07 PM

The size of the symbol remains the same 88 bytes. If we have to pack it better, we can do it by tweaking some members of SymbolBody, but looks like the program isn't very sensitive to the size of Symbol.

lld/ELF/Symbols.h
54 ↗(On Diff #120751)

Done.

411 ↗(On Diff #120751)

Resurrected.

415 ↗(On Diff #120751)

Done.

pcc accepted this revision.Oct 29 2017, 2:44 PM
In D39406#910260, @ruiu wrote:

The size of the symbol remains the same 88 bytes.

Yes, the size of global symbols will be the same, but you're increasing the sizes of the unparented local symbols. I'd expect there to be a large number of these (especially with function sections).

If we have to pack it better, we can do it by tweaking some members of SymbolBody, but looks like the program isn't very sensitive to the size of Symbol.

If that's what you've measured, this seems fine to me.

lld/docs/NewLLD.rst
167 ↗(On Diff #120756)

Is it worth keeping this para (maybe move into SymbolTable)?

This revision is now accepted and ready to land.Oct 29 2017, 2:44 PM
ruiu updated this revision to Diff 120758.Oct 29 2017, 3:12 PM
  • Updated the doc.
ruiu added a comment.Oct 29 2017, 3:12 PM

If we have to pack it better, we can do it by tweaking some members of SymbolBody, but looks like the program isn't very sensitive to the size of Symbol.

If that's what you've measured, this seems fine to me.

Yes, that's what I measured. I tried to link clang without debug info (w/debug wasn't a good test because it spent most of its execution time to merge strings), and the difference before and after was a noise.

grimar edited edge metadata.Oct 30 2017, 2:49 AM

Looks a good change to simplify the rest LLD code for me. Comments below:

  1. nit: you want to fix description "r2681780" -> "r268178"
  2. There are 3 very similar places that set or copy symbol's flags. I marked them as (1), (2), (3) below. It looks easy to forget to update these places when adding new flags, so I would suggest to introduce some helper, like void lld::setSymbolAttributes(SymbolBody *S, uint8_t Binding, uint16_t VersionId ...); or something different, perhaps some static member of SymbolBody, that would remove this code duplication and make code less error prone.
lld/ELF/SymbolTable.cpp
262 ↗(On Diff #120758)

(1)

lld/ELF/Symbols.cpp
153 ↗(On Diff #120758)

(3)

lld/ELF/Symbols.h
417 ↗(On Diff #120758)

(2)

ruiu added inline comments.Oct 30 2017, 2:02 PM
lld/ELF/SymbolTable.cpp
262 ↗(On Diff #120758)

Yes, that code is almost duplicate. I'll factor this out in a follow-up patch.

grimar accepted this revision.Oct 31 2017, 1:44 AM

LGTM.

This revision was automatically updated to reflect the committed changes.