This is an archive of the discontinued LLVM Phabricator instance.

[ELF2] Sort PPC64 special sections
ClosedPublic

Authored by hfinkel on Oct 10 2015, 10:19 AM.

Details

Reviewers
ruiu
rafael
Summary

PPC64 has several special sections that are intended to be accessed from the TOC base pointer. When a .got is present, the TOC base pointer is .got + 0x8000 (as specified by the ABI). Furthermore, the glibc startup code contains an assumption that a 16-bit relocation can hold the offset from the TOC base value to the beginning of the .toc section. Thus, we need to make sure that .toc appears after .got. This much, at least, is required in practice. The other PPC64 special sections (.toc, .toc1, .opd, etc.) should also be close by to optimize access by smaller TOC-base-pointer offsets.

Diff Detail

Event Timeline

hfinkel updated this revision to Diff 37030.Oct 10 2015, 10:19 AM
hfinkel retitled this revision from to [ELF2] Sort PPC64 special sections.
hfinkel updated this object.
hfinkel added reviewers: ruiu, rafael.
hfinkel added a project: lld.
hfinkel added a subscriber: llvm-commits.
ruiu added inline comments.Oct 10 2015, 11:00 AM
ELF/Writer.cpp
361–365

You can simplify this by defining a function, say getPPCRank(StringRef), which returns an integer value according to this table.

0 .tocbss
1 any other name
2 .toc
3 .branch_lt
4 .toc
5 .toc1
6 .opd

Then you can use that function in this function like this

return getPPCRank(A) < getPPCRank(B);
hfinkel updated this revision to Diff 37070.Oct 11 2015, 4:39 PM

Updated to use a ranking function (per review).

ruiu added inline comments.Oct 11 2015, 4:51 PM
ELF/Writer.cpp
311–317

Sorry, I meant

0 .tocbss
1 any other name
2 .got (* was a typo)
3 .branch_lt
4 .toc
5 .toc1
6 .opd

This is my interpretation of your code. I'm not 100% sure that this ranking is correct, though. So please verify.

Also please remove excessive spaces at .Case("...", <*here*><number>)

hfinkel added inline comments.Oct 11 2015, 4:59 PM
ELF/Writer.cpp
311–317

I know, but if I do that, then I'll change the order of .got relative to other like sections for all targets. Is that okay?

ruiu added inline comments.Oct 11 2015, 5:03 PM
ELF/Writer.cpp
311–317

If you don't need that for PPC now, you can leave .got as is.

hfinkel added inline comments.Oct 11 2015, 5:12 PM
ELF/Writer.cpp
311–317

Okay; I'll leave it like this for now. It is okay for my current test cases, and I'm happy to deal with future enhancements if/when they become necessary.

ruiu accepted this revision.Oct 11 2015, 5:15 PM
ruiu edited edge metadata.

OK. LGTM with the StringSwitch style fix.

This revision is now accepted and ready to land.Oct 11 2015, 5:15 PM
hfinkel closed this revision.Oct 12 2015, 1:54 PM

r250100, thanks!