This is an archive of the discontinued LLVM Phabricator instance.

[ELF][MIPS] Implement R_MIPS_GPREL16/R_MIPS_GPREL32 relocation
ClosedPublic

Authored by atanasyan on Dec 23 2015, 2:29 PM.

Details

Summary

The R_MIPS_GPREL16 / R_MIPS_GPREL32 relocations use the following expressions for calculations:

local symbol:  S + A + GP0 - GP
global symbol: S + A - GP

GP  - Represents the final gp value, i.e. _gp symbol
GP0 - Represents the gp value used to create the relocatable object

The GP0 value is taken from the .reginfo data section defined by an object file. To implement that I keep a reference to MipsReginfoInputSection
in the ObjectFile class. This reference is used by the ObjectFile::getMipsGp0 method to return the GP0 value.

Diff Detail

Repository
rL LLVM

Event Timeline

atanasyan updated this revision to Diff 43558.Dec 23 2015, 2:29 PM
atanasyan retitled this revision from to [ELF][MIPS] Implement R_MIPS_GPREL16/R_MIPS_GPREL32 relocation.
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 accepted this revision.Dec 23 2015, 4:25 PM
ruiu edited edge metadata.

LGTM with a few nits.

ELF/InputFiles.h
126 ↗(On Diff #43558)

It is even better if you mention that the function is needed to support R_MIPS_GPREL16 / R_MIPS_GPREL32 relocations.

ELF/InputSection.cpp
190 ↗(On Diff #43558)

Please add a comment here why we need this.

ELF/Target.cpp
1392–1396 ↗(On Diff #43558)
case R_MIPS_GPREL32:
  write32<E>(Loc, SA + int32_t(read32<E>(Loc)) - getMipsGpAddr<ELFT>());
  break;
This revision is now accepted and ready to land.Dec 23 2015, 4:25 PM
This revision was automatically updated to reflect the committed changes.