This is an archive of the discontinued LLVM Phabricator instance.

[ELF][MIPS] Initial support of MIPS local GOT entries
ClosedPublic

Authored by atanasyan on Jan 19 2016, 11:51 AM.

Details

Summary

Some MIPS relocation (for now R_MIPS_GOT16) requires creation of GOT entries for symbol not included in the dynamic symbol table. They are local symbols and non-local symbols with 'local' visibility. Local GOT entries occupy continuous block between GOT header and regular GOT entries.

The patch adds initial support for handling local GOT entries. The main problem is allocating local GOT entries for local symbols. Such entries should be initialized by high 16-bit of the symbol value. In ideal world there should be no duplicated entries with the same values. But at the moment of the Writer::scanRelocs call we do not know a value of the symbol. In this patch we create new local GOT entry for each relocation against local symbol, though we can exhaust GOT quickly. That needs to be optimized later. When we calculate relocation we know a final symbol value and request local GOT entry index. To do that we maintain map between addresses and local GOT entry indexes. If we start to calculate relocations in parallel we will have to serialize access to this map.

Diff Detail

Repository
rL LLVM

Event Timeline

atanasyan updated this revision to Diff 45287.Jan 19 2016, 11:51 AM
atanasyan retitled this revision from to [ELF][MIPS] Initial support of MIPS local GOT entries.
atanasyan updated this object.
atanasyan added reviewers: ruiu, rafael.
atanasyan set the repository for this revision to rL LLVM.
atanasyan added a project: lld.
atanasyan added a subscriber: llvm-commits.
ruiu added inline comments.Jan 19 2016, 12:52 PM
ELF/OutputSections.cpp
125 ↗(On Diff #45287)

What is 0x8000?

154–156 ↗(On Diff #45287)

This code seems a bit tricky, and I also don't like the idea to look up a table for MIPS local symbols.

How about this? We don't need to assign an index in the GOT to Sym->GotIndex() in addEntry. Instead, we can do that in GotSection::finalize(). We can also change addMipsLocalEntry(SymbolBody *) to just add a given SymbolBody to some vector (say, MipsEntries). In finalize(). we assign GotIndex to all symbols in MipsEntries first and then to all symbols in Entries.

atanasyan added inline comments.Jan 19 2016, 1:16 PM
ELF/OutputSections.cpp
125 ↗(On Diff #45287)

In fact this is a %hi() expression without right-shifting. Like mipsHigh or applyPPCHa().

154–156 ↗(On Diff #45287)

It is unclear how to deal with local symbols which does not have a corresponding SymbolBody.

Now MipsLocalEntries holds number of entries reserved for local GOT entries. Some of these entries are for non-local symbols with SymbolBody and we can keep them in MipsEntries. But other ones are for local symbols, i.e. section + offset in fact.

ruiu added inline comments.Jan 19 2016, 2:39 PM
ELF/OutputSections.cpp
125 ↗(On Diff #45287)

Please add a comment to describe that.

154–156 ↗(On Diff #45287)

Ah, I often forgot the fact that we did not create SymbolBody for a local symbol. This is probably a bold suggestion, but for the sake of discussion, what if we create SymbolBodies for local symbols? How much will it increase link time (I'm not requesting to do that in this patch, though)? That would increase link time, but if it is small, then that may make sense because that would simplify some code a lot.

atanasyan marked an inline comment as done.Jan 20 2016, 3:15 AM
atanasyan added inline comments.
ELF/OutputSections.cpp
154–156 ↗(On Diff #45287)

It is a good idea but let's postpone it a bit. I'm going to optimize local GOT entries allocation to reduce number of such entries. To do that I will need to handle local symbols in a more complicated way than just counting GOT16 relocations against them. Maybe in that case SymbolBody for local symbol becomes mandatory.

ruiu added inline comments.Jan 20 2016, 12:22 PM
ELF/OutputSections.cpp
125 ↗(On Diff #45287)

Is this done? Maybe you forgot to upload the latest patch?

atanasyan updated this revision to Diff 45433.Jan 20 2016, 12:41 PM
  • Add comment to explain 'magical' expression
ruiu edited edge metadata.Jan 20 2016, 2:42 PM

LGTM assuming that we are not going to keep MipsLocalGotPos indefinitely. We need to simplify this in future.

ELF/InputSection.cpp
224 ↗(On Diff #45433)

Typo: oif

This revision was automatically updated to reflect the committed changes.