This is an archive of the discontinued LLVM Phabricator instance.

[PPC64] Add .toc section after .got section
ClosedPublic

Authored by syzaara on Apr 19 2018, 12:06 PM.

Details

Summary

PPC64 maintains a compiler managed got in the .toc section. When accessing a global variable through got-indirect access, a .toc entry is created for the variable. The relocation for the got-indirect access will refer to the .toc section rather than the symbol that is actually accessed. The .toc entry contains the address of the global variable. We evaluate the offset from r2 (which is the TOC base) to the address of the toc entry for the global variable. Currently, the .toc is not near the .got. This causes errors because the offset from r2 to the toc section is too large. The linker needs to add all the .toc input sections to the .got output section, merging the compiler managed got with the linker got. This ensures that the offsets from the TOC base to the toc entries are not too large.

This patch puts the .toc section right after the .got section.

Diff Detail

Event Timeline

syzaara created this revision.Apr 19 2018, 12:06 PM
ruiu added a comment.Apr 19 2018, 4:30 PM

I wonder if you really need to merge .toc into .got. If I understand your description correctly, it doesn't matter whether they are merged or not as long as they are close enough. So I'm wondering if you can just manipulate the section output order so that .toc and .got are output next to each other.

I wonder if you really need to merge .toc into .got. If I understand your description correctly, it doesn't matter whether they are merged or not as long as they are close enough. So I'm wondering if you can just manipulate the section output order so that .toc and .got are output next to each other.

Changing the output order to add .toc right after .got will be functionally correct. However, we also want to be similar to gold and bfd. The other linkers don't display toc as its own output section, but rather add it to the got output section.

@ruiu Hi Rui, can you please finish reviewing this?

I wonder if you really need to merge .toc into .got. If I understand your description correctly, it doesn't matter whether they are merged or not as long as they are close enough. So I'm wondering if you can just manipulate the section output order so that .toc and .got are output next to each other.

This would work, but I think we eventually want to merge them together just to match the behaviors of bfd and gold anyway. If that's the case we may as well just perform that merging now.

syzaara updated this revision to Diff 147346.May 17 2018, 10:21 AM

Change the sorting so that .toc is emitted right after .got rather than adding it into the got.

@ruiu Hi Rui, I've changed the output section order now. Can you take a look at this patch again?

ruiu accepted this revision.May 17 2018, 10:57 AM

I'm sorry that I missed this patch. LGTM

I'm fine if you eventually have to merge .toc and .got. As a reviewer, I believe that my role is to ask if something isn't clear. I asked a question because I was genuinely wondering, and it didn't mean that I was requesting you to make a change.

This revision is now accepted and ready to land.May 17 2018, 10:57 AM
syzaara retitled this revision from [PPC64] Add .toc input sections to end of .got output section to [PPC64] Add .toc section after .got section.May 24 2018, 8:48 AM
syzaara edited the summary of this revision. (Show Details)
This revision was automatically updated to reflect the committed changes.