Replace __toc_start + 0x8000 with .TOC.
PATCH 1/1 Replace __toc_start + 0x8000 with .TOC.
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.
--- arch/powerpc/boot/crt0.S | 2 +- arch/powerpc/boot/zImage.lds.S | 1 - arch/powerpc/include/asm/sections.h | 10 ++-------- arch/powerpc/kernel/head_64.S | 2 +- arch/powerpc/kernel/vmlinux.lds.S | 1 - 5 files changed, 4 insertions(+), 12 deletions(-)
arch/powerpc/boot/crt0.S +1 -1
@@ -28,7 +28,7 @@ p_etext: .8byte _etext p_bss_start: .8byte __bss_start p_end: .8byte _end -p_toc: .8byte __toc_start + 0x8000 - p_base +p_toc: .8byte .TOC. - p_base p_dyn: .8byte __dynamic_start - p_base p_rela: .8byte __rela_dyn_start - p_base p_prom: .8byte 0
arch/powerpc/boot/zImage.lds.S +0 -1
@@ -39,7 +39,6 @@ SECTIONS . = ALIGN(256); .got : { - __toc_start = .; *(.got) *(.toc) }
arch/powerpc/include/asm/sections.h +2 -8
@@ -48,14 +48,8 @@ static inline int in_kernel_text(unsigned long addr)static inline unsigned long kernel_toc_addr (void ) { -/* Defined by the linker, see vmlinux.lds.S */ -extern unsigned long __toc_start; - -/* -* The TOC register (r2) points 32kB into the TOC, so that 64kB of -* the TOC can be addressed using a single machine instruction. -*/ -return (unsigned long )(&__toc_start) +0x8000UL ; +extern unsigned long toc asm(".TOC." ); +return (unsigned long )(&toc); } static inline int overlaps_interrupt_vector_text(unsigned long start,
arch/powerpc/kernel/head_64.S +1 -1
@@ -899,7 +899,7 @@ _GLOBAL(relative_toc) blr .balign 8 -p_toc: .8byte __toc_start + 0x8000 - 0b +p_toc: .8byte .TOC. - 0b /* * This is where the main kernel code starts.
arch/powerpc/kernel/vmlinux.lds.S +0 -1
@@ -328,7 +328,6 @@ SECTIONS . = ALIGN(256); .got : AT(ADDR(.got) - LOAD_OFFSET) { - __toc_start = .; #ifndef CONFIG_RELOCATABLE __prom_init_toc_start = .; arch/powerpc/kernel/prom_init.o*(.toc .got)
Signature · 1 line
2.30.1.766.gb4fecdf3b7-goog
Hi!
Quoted 8 lines · Fangrui Song
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. WhenCONFIG_PPC_OF_BOOT_TRAMPOLINE=y,arch/powerpc/kernel/prom_init.ois built, and LLD computed .TOC. can be different from__toc_startdefined by the linker script.
Quoted 6 lines
Simplify
kernel_toc_addrwith asm label .TOC. so that we can get rid of__toc_start.With this change,
powernv_defconfigwithCONFIG_PPC_OF_BOOT_TRAMPOLINE=yis 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
Quoted 19 lines · Segher Boessenkool
Hi!
Quoted 8 lines · Fangrui Song
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. WhenCONFIG_PPC_OF_BOOT_TRAMPOLINE=y,arch/powerpc/kernel/prom_init.ois built, and LLD computed .TOC. can be different from__toc_startdefined by the linker script.Quoted 6 lines
Simplify
kernel_toc_addrwith asm label .TOC. so that we can get rid of__toc_start.With this change,
powernv_defconfigwithCONFIG_PPC_OF_BOOT_TRAMPOLINE=yis bootable with LLD. There is still an untriaged issue with Alexey's configuration.
Quoted 6 lines
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.