On Sat, Mar 6, 2021 at 10:25 PM Segher Boessenkool <seg...@kernel.crashing.org> wrote: > > Hi! > > On Sat, Mar 06, 2021 at 09:14:33PM -0800, Fangrui Song wrote: > > TOC relocations are like GOT relocations on other architectures. > > However, unlike other architectures, GNU ld's ppc64 port defines .TOC. > > relative to the .got output section instead of the linker synthesized > > .got input section. LLD defines .TOC. as the .got input section plus > > 0x8000. When CONFIG_PPC_OF_BOOT_TRAMPOLINE=y, > > arch/powerpc/kernel/prom_init.o is built, and LLD computed .TOC. can be > > different from __toc_start defined by the linker script. > > > > Simplify kernel_toc_addr with asm label .TOC. so that we can get rid of > > __toc_start. > > > > With this change, powernv_defconfig with CONFIG_PPC_OF_BOOT_TRAMPOLINE=y > > is bootable with LLD. There is still an untriaged issue with Alexey's > > configuration. > > Do you have any explanation why this *does* work, while the original > doesn't? Some explanation that says *what* is wrong. To me it doesn't > look like the kernel script is. > > > Segher
The kernel code probably wants to access .TOC. (the TOC base symbol) via __toc_start+0x8000. If the kernel understood TOC base is different from the linker understood TOC base (.TOC.), there should be a problem. By using .TOC. in the kernel code, the two concepts are guaranteed to match.