This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - Avoid reusing DynsymIndex for -r
AbandonedPublic

Authored by grimar on Jan 16 2017, 8:37 AM.

Details

Reviewers
ruiu
rafael
Summary

DynsymIndex was used as symbol table index for -r.
Also it was reused in the same way in D28612 for
--emit-relocs, though it introduced few restrictions.
Since DynsymIndex is busy with symtab index,
there is no way to create .dynsym table.

Patch shows one of possible way to avoid reusing this variable.

Another and much simpler way would be just to add
SymtabIndex variable to Symbol class.

I am not sure what is better.

Diff Detail

Event Timeline

grimar updated this revision to Diff 84566.Jan 16 2017, 8:37 AM
grimar retitled this revision from to [DEMO] - Avoid reusing DynsymIndex for -r.
grimar updated this object.
grimar added a reviewer: grimar.
grimar retitled this revision from [DEMO] - Avoid reusing DynsymIndex for -r to [ELF] - Avoid reusing DynsymIndex for -r.Jan 16 2017, 8:52 AM
grimar updated this object.
grimar edited reviewers, added: ruiu, rafael; removed: grimar.
grimar added subscribers: grimar, evgeny777, llvm-commits.
rafael edited edge metadata.Jan 17 2017, 10:20 AM

Keeping the Symbol type small is important for the common case, so I think this is better than adding another member variable.

If this is too slow -r, we can probably reorder the loop to gain some speed.

Rui, what do you think?

ruiu added inline comments.Jan 21 2017, 4:30 PM
ELF/InputSection.cpp
233

This function seems too heavy to run for each relocation. It is probably not ok to do this much here.

ruiu edited edge metadata.Jan 21 2017, 4:47 PM

So I took a look at the code, and I think the current implementation of the -r option in regard to symbol indices is unnecessarily complicated. The logic is scattered over Writer.cpp and SyntheticSections.cpp, and we are handling -r in an obscure way there. It needs fixing from a broader perspective (e.g. moving the logic to SynethticSections) instead of a local fix.

grimar abandoned this revision.Jan 23 2017, 6:29 AM
In D28773#652532, @ruiu wrote:

So I took a look at the code, and I think the current implementation of the -r option in regard to symbol indices is unnecessarily complicated. The logic is scattered over Writer.cpp and SyntheticSections.cpp, and we are handling -r in an obscure way there. It needs fixing from a broader perspective (e.g. moving the logic to SynethticSections) instead of a local fix.

Done in D29021.

ELF/InputSection.cpp
233

That affects only -relocatable.

But anyways, since this patch is abandoned and D29021 which landed instead also contains linear search,
I had in mind two possible optimizations for new SymbolTableSection::getSymbolIndex()

  1. We can cache the result for Body in place of call (copyRelocations) and call getSymbolIndex only if result is not in cache.
  2. We can add some new member for doing mapping from Body to index to SymbolTableSection class. To replace linear search with mapping call.

As an alternative we can do nothing for now and see if somebody mets perfomance issues with relocatable option.

What do you think ?