This is an archive of the discontinued LLVM Phabricator instance.

[ELF][MIPS] Make R_MIPS_LO16 a relative relocation if it references _gp_disp symbol
ClosedPublic

Authored by atanasyan on Apr 14 2016, 8:03 AM.

Details

Summary

The _gp_disp symbol designates offset between start of function and 'gp' pointer into GOT. The following code is a typical MIPS function preamble used to setup $gp register:

lui    $gp, %hi(_gp_disp)
addi   $gp, $gp, %lo(_gp_disp)

To calculate R_MIPS_HI16 / R_MIPS_LO16 relocations results we use the following formulas:

%hi(_gp - P + A)
%lo(_gp - P + A + 4),

where _gp is a value of _gp symbol, A is addend, and P current address.

The R_MIPS_LO16 relocation references _gp_disp symbol is always the second instruction. That is why we need four byte adjustments. The patch assigns R_PC type for R_MIPS_LO16 relocation and adjusts its addend by 4. That fix R_MIPS_LO16 calculation.

For details see p. 4-19 at ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf

Diff Detail

Repository
rL LLVM

Event Timeline

atanasyan updated this revision to Diff 53722.Apr 14 2016, 8:03 AM
atanasyan retitled this revision from to [ELF][MIPS] Make R_MIPS_LO16 a relative relocation if it references _gp_disp symbol.
atanasyan updated this object.
atanasyan added a reviewer: rafael.
atanasyan set the repository for this revision to rL LLVM.
atanasyan added a project: lld.
atanasyan added a subscriber: llvm-commits.
rafael edited edge metadata.Apr 14 2016, 12:03 PM
rafael added a subscriber: rafael.

LGTM, thanks.

This revision was automatically updated to reflect the committed changes.