This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - Do not use HeaderSize for conditions in PltSection.
ClosedPublic

Authored by grimar on Dec 28 2017, 2:45 AM.

Details

Summary

Found this during experiments with refactoring.

Our PltSection code assumes that InX::Iplt section has zero header size
and that InX::Plt always has non-zero header:
https://github.com/llvm-mirror/lld/blob/master/ELF/SyntheticSections.cpp#L1870

But PPC64 target sets PltHeaderSize to zero:
https://github.com/llvm-mirror/lld/blob/master/ELF/Arch/PPC64.cpp#L68
(I could be wrong about reasons, but I think PPC64 target just does not
implement lazy binding).

Because of that, ppc64-toc-restore.s testcase, for example, sets IsInIplt flag for
symbols, what does not seem to be correct.

I suggest to stop using HeaderSize == 0 in code as condition to find out whether
we are in Plt or Iplt section.

Diff Detail

Repository
rLLD LLVM Linker

Event Timeline

grimar created this revision.Dec 28 2017, 2:45 AM
grimar updated this revision to Diff 128300.Dec 28 2017, 9:01 AM
  • Addressed review comment (IsPlt->IsIplt).
grimar accepted this revision.Dec 29 2017, 4:00 AM

LGTMed by Rafael in mail list. Rui, are you OK with this change ?

This revision is now accepted and ready to land.Dec 29 2017, 4:00 AM
grimar added a comment.Jan 9 2018, 4:22 AM

Ping. Rui ?

ruiu added a comment.Jan 9 2018, 4:07 PM

Isn't it an ABI violation not to write the PLT header for PPC64? If so, we fix that ABI violation rather than "correctly" emitting ABI-violating executables.

ruiu added inline comments.Jan 10 2018, 11:37 PM
ELF/SyntheticSections.cpp
1863

Remove HeaderSize member because it is always Target->PltHeaderSize

ELF/Writer.cpp
372–374

Passing (PltHeaderSize, false) or (0, true) is strange. You should just pass true or false and infer the header size inside the class.

grimar updated this revision to Diff 129413.Jan 11 2018, 2:17 AM
  • Addressed review comments.
ELF/Writer.cpp
372–374

With this suggestion patch looks better IMO, thanks.

ruiu accepted this revision.Jan 11 2018, 1:01 PM

LGTM with these changes.

ELF/SyntheticSections.cpp
1875

OK this change isn't pretty. Pleasse keep HeaderSize and remove getHeaderSize.

ELF/SyntheticSections.h
507–508

That IsIplt is true if it is Iplt is obvious, no? If you change this to something like "true if IPLT. false if the regular PLT", that would be nontrivial. But I doubt we need it though.

This revision was automatically updated to reflect the committed changes.
ruiu added inline comments.Jan 12 2018, 2:31 PM
ELF/SyntheticSections.cpp
1875

Sorry for not being clear, but I didn't mean you should revert all these changes. I'll make a change to redo what your change originally contained.