This is an archive of the discontinued LLVM Phabricator instance.

[ELF2] Move sorting from symbol table to the GNU hash section.
ClosedPublic

Authored by ikudrin on Oct 26 2015, 10:35 AM.

Details

Summary

It is the GNU hash table section which should contain its own data and be responsible for imposing its requirements for the order of dynamic symbols.

Diff Detail

Repository
rL LLVM

Event Timeline

ikudrin updated this revision to Diff 38432.Oct 26 2015, 10:35 AM
ikudrin retitled this revision from to [ELF2] Move sorting from symbol table to the GNU hash section..
ikudrin updated this object.
ikudrin added reviewers: rafael, ruiu.
ikudrin added a project: lld.
ikudrin added a subscriber: llvm-commits.
ruiu added inline comments.Oct 26 2015, 10:46 AM
ELF/OutputSections.cpp
350 ↗(On Diff #38432)

Is NumHashed always the same as HashedSymbols.size()? If so, remove the variable and use HashedSymbols.size() instead.

414–420 ↗(On Diff #38432)

You can use std::partition to separate non-hashed symbols from hashed symbols first, and then sort the latter half.

ELF/OutputSections.h
313–314 ↗(On Diff #38432)

You don't need this constructor. Instead of

HashedSymbolData(X, Y)

you can always do

HashedSymbolData{X, Y}
ikudrin added inline comments.Oct 26 2015, 11:20 AM
ELF/OutputSections.cpp
350 ↗(On Diff #38432)

This class requires the other class to call sortSymbols() method. Plus, it requires that addSymbol() is called the exact number of times, and these calls come from the third place. This assert ensures that everything is in sync.

ruiu added inline comments.Oct 26 2015, 11:22 AM
ELF/OutputSections.h
298 ↗(On Diff #38432)

This looks really weird. You are not using the argument.

ikudrin updated this revision to Diff 38447.Oct 26 2015, 12:09 PM
  • Removed constructor of internal class
  • Reworked the sortSymbols() method.
ikudrin marked 3 inline comments as done.Oct 26 2015, 12:10 PM
ikudrin added inline comments.Oct 26 2015, 12:17 PM
ELF/OutputSections.cpp
349 ↗(On Diff #38447)

The variable is required in the finalize() method. The HashedSymbols is filled in the sortSymbols() method, which is called from finalize() method of the dynamic symbol table. All finalize() methods should not depend on each other and their call order, I think.

ruiu added inline comments.Oct 26 2015, 12:51 PM
ELF/OutputSections.cpp
349 ↗(On Diff #38447)

Can you count the number of symbols that need to be in .gnu.hash here, instead of calling addSymbol for each symbol? That can be as easy as

ArrayRef<Symbol> A = Out<ELFT>::DynSymTab->getSymbols();
NumHashed = std::count(A.begin(), A.end(), includeInGnuHashTable);
405–406 ↗(On Diff #38447)

I think this function should be called "addSymbols" rather than "sortSymbols". This indeed sorts symbols passed to this function, but that's probably secondaly.

ELF/OutputSections.h
299 ↗(On Diff #38447)

Add a blank line here.

ikudrin updated this revision to Diff 38513.Oct 27 2015, 1:41 AM
  • NumHashed is no longer stored in the class.
  • sortSymbols() -> addSymbols().
  • assert()s are removed.
ikudrin marked 3 inline comments as done.Oct 27 2015, 1:41 AM
ruiu accepted this revision.Oct 27 2015, 12:07 PM
ruiu edited edge metadata.

LGTM with a nit. Nice cleanup!

ELF/OutputSections.cpp
338 ↗(On Diff #38513)

Remove this blank line.

This revision is now accepted and ready to land.Oct 27 2015, 12:07 PM
This revision was automatically updated to reflect the committed changes.