This is an archive of the discontinued LLVM Phabricator instance.

ELF2: Make SymbolTable a template class.
ClosedPublic

Authored by ruiu on Oct 7 2015, 8:04 PM.

Details

Reviewers
rafael
Summary

SymbolTable was not a template class. Instead we had switch-case-based
type dispatch to call desired functions. We had to do that because
SymbolTable was created before we know what ELF type objects had been
passed.

Every time I tried to add a new function to the symbol table, I had to
define a dispatcher which consist of a single switch statement.

It also brought an restriction what the driver can do. For example,
we cannot add undefined symbols before any files are added to the symbol
table. That's because no symbols can be added until the symbol table
knows the ELF type, but when it knows about that, it's too late.

In this patch, the driver makes a decision on what ELF type objects
are being handled. Then the driver creates a SymbolTable object for
an appropriate ELF type.

Diff Detail

Event Timeline

ruiu updated this revision to Diff 36822.Oct 7 2015, 8:04 PM
ruiu retitled this revision from to ELF2: Make SymbolTable a template class..
ruiu updated this object.
ruiu added a reviewer: rafael.
ruiu added a subscriber: llvm-commits.
ruiu updated this revision to Diff 36823.Oct 7 2015, 8:06 PM
ruiu updated this revision to Diff 36911.Oct 8 2015, 5:28 PM

Change SymbolTable::get{Shared,Object}Files type so that they return not ELFFileBase but ELFFile<ELFT>.

rafael added inline comments.Oct 9 2015, 1:00 PM
ELF/Driver.cpp
165

We can get here with

ld.lld2 -u foo has_a_foo.a

no? This is not a regression, but please make it an explicit error. Something like "-m or at least a .o file required".

241

Why do you need these extra loops? You can keep checking for incompatible files as they are created, no?

ELF/OutputSections.cpp
281–284

Other than dropping the "Base" this is independent. Please commit first and rebase.

357–358

This too.

ruiu added inline comments.Oct 9 2015, 1:05 PM
ELF/Driver.cpp
241

I wanted to separate this error checking code from addFile for the sake of simplicity. There we create files and here we check for consistency. In this way we also don't have to propagate -m's argument just to include that into an error message.

ruiu updated this revision to Diff 36987.Oct 9 2015, 1:39 PM
ruiu updated this object.

Address review comments

ELF/Driver.cpp
165

Done.

rafael accepted this revision.Oct 9 2015, 1:58 PM
rafael edited edge metadata.

LGTM

ELF/Driver.cpp
165

Please add a test.

This revision is now accepted and ready to land.Oct 9 2015, 1:58 PM
Eugene.Zelenko added a subscriber: Eugene.Zelenko.

Committed in r249902.