Page MenuHomePhabricator

[PowerPC] Fix issue where binary uses a .got but is missing a .TOC.
Needs ReviewPublic

Authored by stefanp on Fri, Nov 13, 7:25 AM.

Details

Reviewers
nemanjai
MaskRay
espindola
NeHuang
sfertile
Group Reviewers
Restricted Project
Summary

From the PowerPC ELFv2 ABI section 4.2.3. Global Offset Table.

The GOT consists of an 8-byte header that contains the TOC base (the first TOC
base when multiple TOCs are present), followed by an array of 8-byte addresses.

Due to the introduction of PC Relative code it is now possible to require a GOT
without having a .TOC. symbol in the object that is being linked. Since LLD uses
the .TOC. symbol to determine whether or not a GOT is required the GOT header is
not setup correctly and the 8-byte header is missing.

This patch allows the Power PC GOT setup to happen when an element is added to
the GOT instead of at the very begining. When this header is added a .TOC.
symbol is also added.

Diff Detail

Event Timeline

stefanp created this revision.Fri, Nov 13, 7:25 AM
Herald added a project: Restricted Project. · View Herald Transcript
stefanp requested review of this revision.Fri, Nov 13, 7:25 AM
stefanp added a reviewer: Restricted Project.
MaskRay added inline comments.Mon, Nov 16, 11:24 PM
lld/ELF/SyntheticSections.cpp
710

Can you use an approach similar to GotPltSection::hasGotPltOffset?

stefanp added inline comments.Tue, Nov 17, 4:03 AM
lld/ELF/SyntheticSections.cpp
710

I'm sorry but I'm not sure what you are looking for.
I assume you mean GotPltSection::hasGotPltOffRel.

Are you looking to replace

if (config->emachine != EM_PPC64 || ElfSym::globalOffsetTable)
    return;

with something like:

if (hasGotHeader || ElfSym::globalOffsetTable)
    return;

Where I can then set hasGotHeader from the GotSection constructor and/or PPC specific code?

Or:
Should I set numEntries += target->gotHeaderEntriesNum; from PPC specific code?

NeHuang added inline comments.Wed, Nov 18, 1:14 PM
lld/test/ELF/ppc64-ld-got-dtprel.s
28

is the computation proper here? To me, &.got[2] is different from &.got[1]

MaskRay added inline comments.Wed, Nov 18, 2:14 PM
lld/ELF/SyntheticSections.cpp
710

We should drop setupPPCDelayedInit and compute the size of GotSection with an approach similar to GotPltSection::hasGotPltOffset

stefanp added inline comments.Mon, Nov 23, 4:36 AM
lld/ELF/SyntheticSections.cpp
710

I cannot find GotPltSection::hasGotPltOffset it is not in the code.

There are a couple of ways that I could remove

numEntries += target->gotHeaderEntriesNum;

from this function including adding it to Symbol::getGotOffset() in the same way that Symbol::getGotPltOffset() does. However, I still have to add the .TOC. symbol and so I cannot remove setupPPCDelayedInit completely.

I'm sorry but I'm still confused about this comment...