This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Add IpltSection
ClosedPublic

Authored by MaskRay on Dec 14 2019, 6:08 PM.

Details

Summary

PltSection is used by both PLT and IPLT. The PLT section may have a
header while the IPLT section does not. Split off IpltSection from
PltSection to be clearer.

Unlike other targets, PPC64 cannot use the same code sequence for PLT
and IPLT. This helps make a future PPC64 patch (D71509) more isolated.

On EM_386 and EM_X86_64, when PLT is empty while IPLT is not, currently
we are inconsistent whether the PLT header is attached to in.plt or
in.iplt . Consistently attach the HEADER to in.plt can make the -z
retpolineplt logic simpler. It also makes jmp point to an
aesthetically better place for non-retpolineplt cases.

Diff Detail

Event Timeline

MaskRay created this revision.Dec 14 2019, 6:08 PM
ruiu accepted this revision.Dec 15 2019, 9:39 PM

LGTM

lld/ELF/Arch/AArch64.cpp
66–67

For consistency, I'd write one line per an assignment.

lld/ELF/SyntheticSections.cpp
2516

Can you use a range-based for loop?

lld/ELF/Target.h
48

I'd add a comment saying that all but PPC64 use the same format for .plt and .iplt entries.

This revision is now accepted and ready to land.Dec 15 2019, 9:39 PM
MaskRay updated this revision to Diff 233993.Dec 15 2019, 10:41 PM
MaskRay marked an inline comment as done.

pltEntrySize = ipltEntrySize = 16;

=>

pltEntrySize = 16;
ipltEntrySize = 16;

MaskRay updated this revision to Diff 233994.Dec 15 2019, 10:49 PM
MaskRay marked 2 inline comments as done.

Add a comment to writeIplt
Use range-based loop

grimar added inline comments.Dec 16 2019, 12:54 AM
lld/ELF/SyntheticSections.cpp
2489–2490

The comment seems to be broken, should it be
Some architectures adds additional symbols?

2511

You do not need curly bracers around a single line.

2538

Should it be target->ipltEntrySize? How about adding a helper to
remove the duplication we have in PltSection::addSymbols() and here?

Looks good to me. One minor nit about a stale comment. I'll be out of office for the next few weeks, I'll check to make sure there isn't anything critical but otherwise might be a bit slow to respond.

lld/ELF/SyntheticSections.h
664–665

This comment looks like it will no longer be true.

MaskRay marked 6 inline comments as done.Dec 16 2019, 8:34 AM
MaskRay added inline comments.
lld/ELF/SyntheticSections.cpp
2511

https://reviews.llvm.org/D71520 will add another line here. So the curly brace is added beforehand to minimize diff:)

2538

Thanks for catching this!

ipltEntrySize = pltEntrySize on all targets which we support Iplt before https://reviews.llvm.org/D71509

Looks like I forgot to attach a test there and caught the issue.

Regarding the duplication with PltSection::addSymbols. The former has an addition call to addPltHeaderSymbols. The functions are simply anyway, and may not be simple to deduplicate.

MaskRay updated this revision to Diff 234077.Dec 16 2019, 8:35 AM
MaskRay marked 2 inline comments as done.

Address comments

MaskRay updated this revision to Diff 234102.Dec 16 2019, 10:33 AM
MaskRay edited the summary of this revision. (Show Details)

On EM_386 and EM_X86_64, consistently attach PLT header to in.plt to make jmp look better.
There is no correctness issue because push; jmp are not called anyway.

MaskRay updated this revision to Diff 234111.Dec 16 2019, 11:14 AM

Rebase. De-template IpltSection::addEntry. PltSection::addEntry has been de-templated in a separate commit.

MaskRay updated this revision to Diff 234137.Dec 16 2019, 1:35 PM
d.value = sym.pltIndex * target->pltEntrySize;

>

d.value = sym.pltIndex * target->ipltEntrySize;

It only affects EM_PPC64 (D71509).

grimar accepted this revision.Dec 17 2019, 12:00 AM

LGTM

This revision was automatically updated to reflect the committed changes.
jrtc27 added inline comments.Dec 17 2019, 3:31 AM
lld/ELF/SyntheticSections.h
685

PltSection cannot can only contain entries -> PltSection can only contain entries

MaskRay marked 2 inline comments as done.Dec 17 2019, 5:18 PM
MaskRay added inline comments.
lld/ELF/SyntheticSections.h
685

Thanks. Fixed.