WSL2-Linux-Kernel/arch/powerpc/boot
Alan Modra 63ecb08533 powerpc/toc: Future proof kernel toc
[ Upstream commit a3ad84da07 ]

This patch future-proofs the kernel against linker changes that might
put the toc pointer at some location other than .got+0x8000, by
replacing __toc_start+0x8000 with .TOC. throughout.  If the kernel's
idea of the toc pointer doesn't agree with the linker, bad things
happen.

prom_init.c code relocating its toc is also changed so that a symbolic
__prom_init_toc_start toc-pointer relative address is calculated
rather than assuming that it is always at toc-pointer - 0x8000.  The
length calculations loading values from the toc are also avoided.
It's a little incestuous to do that with unreloc_toc picking up
adjusted values (which is fine in practice, they both adjust by the
same amount if all goes well).

I've also changed the way .got is aligned in vmlinux.lds and
zImage.lds, mostly so that dumping out section info by objdump or
readelf plainly shows the alignment is 256.  This linker script
feature was added 2005-09-27, available in FSF binutils releases from
2.17 onwards.  Should be safe to use in the kernel, I think.

Finally, put *(.got) before the prom_init.o entry which only needs
*(.toc), so that the GOT header goes in the correct place.  I don't
believe this makes any difference for the kernel as it would for
dynamic objects being loaded by ld.so.  That change is just to stop
lusers who blindly copy kernel scripts being led astray.  Of course,
this change needs the prom_init.c changes.

Some notes on .toc and .got.

.toc is a compiler generated section of addresses.  .got is a linker
generated section of addresses, generally built when the linker sees
R_*_*GOT* relocations.  In the case of powerpc64 ld.bfd, there are
multiple generated .got sections, one per input object file.  So you
can somewhat reasonably write in a linker script an input section
statement like *prom_init.o(.got .toc) to mean "the .got and .toc
section for files matching *prom_init.o".  On other architectures that
doesn't make sense, because the linker generally has just one .got
section.  Even on powerpc64, note well that the GOT entries for
prom_init.o may be merged with GOT entries from other objects.  That
means that if prom_init.o references, say, _end via some GOT
relocation, and some other object also references _end via a GOT
relocation, the GOT entry for _end may be in the range
__prom_init_toc_start to __prom_init_toc_end and if the kernel does
something special to GOT/TOC entries in that range then the value of
_end as seen by objects other than prom_init.o will be affected.  On
the other hand the GOT entry for _end may not be in the range
__prom_init_toc_start to __prom_init_toc_end.  Which way it turns out
is deterministic but a detail of linker operation that should not be
relied on.

A feature of ld.bfd is that input .toc (and .got) sections matching
one linker input section statement may be sorted, to put entries used
by small-model code first, near the toc base.  This is why scripts for
powerpc64 normally use *(.got .toc) rather than *(.got) *(.toc), since
the first form allows more freedom to sort.

Another feature of ld.bfd is that indirect addressing sequences using
the GOT/TOC may be edited by the linker to relative addressing.  In
many cases relative addressing would be emitted by gcc for
-mcmodel=medium if you appropriately decorate variable declarations
with non-default visibility.

The original patch is here:
https://lore.kernel.org/linuxppc-dev/20210310034813.GM6042@bubble.grove.modra.org/

Signed-off-by: Alan Modra <amodra@au1.ibm.com>
[aik: removed non-relocatable which is gone in 24d33ac5b8]
[aik: added <=2.24 check]
[aik: because of llvm-as, kernel_toc_addr() uses "mr" instead of global register variable]
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20211221055904.555763-2-aik@ozlabs.ru
Stable-dep-of: 1b1e38002648 ("powerpc: add crtsavres.o to always-y instead of extra-y")
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-01-25 14:52:32 -08:00
..
dts powerpc: dts: t1040rdb: fix compatible string for Rev A boards 2023-03-17 08:48:54 +01:00
.gitignore
4xx.c
4xx.h
44x.h
Makefile powerpc/boot: Explicitly disable usage of SPE instructions 2022-10-26 12:34:25 +02:00
README
addnote.c
bamboo.c
cpm-serial.c
crt0.S powerpc/toc: Future proof kernel toc 2024-01-25 14:52:32 -08:00
crtsavres.S
cuboot-8xx.c
cuboot-52xx.c
cuboot-83xx.c
cuboot-85xx-cpm2.c
cuboot-85xx.c
cuboot-824x.c
cuboot-acadia.c
cuboot-amigaone.c
cuboot-bamboo.c
cuboot-ebony.c
cuboot-hotfoot.c
cuboot-katmai.c
cuboot-kilauea.c
cuboot-mpc7448hpc2.c
cuboot-pq2.c
cuboot-rainier.c
cuboot-sam440ep.c
cuboot-sequoia.c
cuboot-taishan.c
cuboot-warp.c
cuboot-yosemite.c
cuboot.c
cuboot.h
dcr.h
decompress.c powerpc/boot: Fix a typo in partial_decompress() comment 2021-05-17 15:27:16 +10:00
devtree.c powerpc/boot: Fixup device-tree on little endian 2021-06-21 21:16:32 +10:00
div64.S
dummy.c
ebony.c
elf.h
elf_util.c
ep88xc.c
ep8248e.c
epapr-wrapper.c
epapr.c
fixed-head.S
fixup-headers.sed
fsl-soc.c
fsl-soc.h
gamecube-head.S
gamecube.c
hack-coff.c
holly.c
install.sh powerpc: make the install target not depend on any build artifact 2021-08-04 10:53:38 +10:00
io.h
libfdt-wrapper.c
libfdt_env.h
main.c
microwatt.c powerpc/boot: Add a boot wrapper for Microwatt 2021-06-21 21:16:32 +10:00
mktree.c
motload-head.S
mpc8xx.c
mpc8xx.h
mpc52xx-psc.c
mvme5100.c
mvme7100.c
ns16550.c powerpc/boot: Fixup device-tree on little endian 2021-06-21 21:16:32 +10:00
of.c
of.h
ofconsole.c
oflib.c
opal-calls.S
opal.c
ops.h
page.h
planetcore.c
planetcore.h
ppc_asm.h
ppcboot-hotfoot.h
ppcboot.h
pq2.c
pq2.h
ps3-head.S
ps3-hvcall.S
ps3.c
pseries-head.S
redboot-8xx.c
redboot-83xx.c
redboot.h
reg.h
rs6000.h
serial.c
simple_alloc.c
simpleboot.c
stdbool.h
stdint.h
stdio.c
stdio.h
stdlib.c
stdlib.h
string.S
string.h
swab.h
treeboot-akebono.c
treeboot-bamboo.c
treeboot-currituck.c
treeboot-ebony.c
treeboot-iss4xx.c
types.h
ugecon.c
ugecon.h
util.S
wii-head.S
wii.c
wrapper powerpc: retire sbc8548 board support 2021-08-27 00:48:11 +10:00
xz_config.h
zImage.coff.lds.S
zImage.lds.S powerpc/toc: Future proof kernel toc 2024-01-25 14:52:32 -08:00
zImage.ps3.lds.S powerpc/ps3: Re-align DTB in image 2021-06-10 21:44:57 +10:00

README

To extract the kernel vmlinux, System.map, .config or initrd from the zImage binary:

objcopy -j .kernel:vmlinux -O binary zImage vmlinux.gz
objcopy -j .kernel:System.map -O binary zImage System.map.gz
objcopy -j .kernel:.config -O binary zImage config.gz
objcopy -j .kernel:initrd -O binary zImage.initrd initrd.gz


	Peter