This is an archive of the discontinued LLVM Phabricator instance.

[ELF][MIPS] Fix handling of _gp/_gp_disp/__gnu_local_gp symbols
ClosedPublic

Authored by atanasyan on Nov 22 2016, 9:27 PM.

Details

Summary

Offset between beginning of a .got section and _gp symbols used in MIPS GOT relocations calculations. Usually the expression looks like VA + Offset - GP, where VA is the .got section address, Offset - offset of the GOT entry, GP - offset between .got and _gp. Also there two "magic" symbols _gp_disp and __gnu_local_gp which hold the offset mentioned above. These symbols might be referenced by MIPS relocations.

Now the linker always defines _gp symbol and uses hardcoded value for its initialization. So offset between .got and _gp is 0x7ff0. The _gp_disp and gnu_local_gp defined if required and initialized by 0x7ff0. In fact that is not correct because _gp symbol might be defined by a linker script and holds arbitrary value. In that case we need to use this value in relocation calculation and initialize _gp_disp and gnu_local_gp properly.

The patch fixes the problem and completes fixing the bug #30311.
https://llvm.org/bugs/show_bug.cgi?id=30311

Diff Detail

Repository
rL LLVM

Event Timeline

atanasyan updated this revision to Diff 79024.Nov 22 2016, 9:27 PM
atanasyan retitled this revision from to [ELF][MIPS] Fix handling of _gp/_gp_disp/__gnu_local_gp symbols.
atanasyan updated this object.
atanasyan added a reviewer: ruiu.
atanasyan set the repository for this revision to rL LLVM.
atanasyan added a project: lld.
atanasyan added subscribers: llvm-commits, emaste.
ruiu accepted this revision.Nov 23 2016, 10:59 AM
ruiu edited edge metadata.

LGTM

ELF/SyntheticSections.h
125 ↗(On Diff #79024)

nit: getGp for consistency.

ELF/Writer.cpp
1421 ↗(On Diff #79024)

Compute this value only once.

This revision is now accepted and ready to land.Nov 23 2016, 10:59 AM
This revision was automatically updated to reflect the committed changes.