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.