linux/arch/powerpc/kernel
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: 1b1e380026 ("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
..
ptrace powerpc: Don't try to copy PPR for task with NULL pt_regs 2023-04-05 11:25:00 +02:00
syscalls compat: remove some compat entry points 2021-09-08 15:32:35 -07:00
trace powerpc/ftrace: Fix stack teardown in ftrace_no_trace 2023-12-20 15:17:43 +01:00
vdso32 powerpc updates for 5.13 2021-04-30 12:22:28 -07:00
vdso64 powerpc/vdso: Don't use r30 to avoid breaking Go lang 2021-07-29 23:13:12 +10:00
.gitignore
align.c powerpc: Rename probe_kernel_read_inst() 2021-04-21 22:52:33 +10:00
asm-offsets.c Merge branch 'fixes' into next 2021-09-03 22:54:12 +10:00
audit.c
btext.c powerpc/btext: add missing of_node_put 2022-01-27 11:04:57 +01:00
cacheinfo.c powerpc/smp: Use existing L2 cache_map cpumask to find L3 cache siblings 2021-08-04 10:53:39 +10:00
cacheinfo.h
compat_audit.c
cpu_setup_6xx.S
cpu_setup_44x.S
cpu_setup_fsl_booke.S powerpc: Retire e200 core (mpc555x processor) 2020-12-05 21:49:18 +11:00
cpu_setup_pa6t.S
cpu_setup_power.c powerpc/perf: MMCR0 control for PMU registers under PMCC=00 2020-12-04 01:01:29 +11:00
cpu_setup_ppc970.S
cputable.c arch: powerpc: Stop building and using oprofile 2021-01-29 10:05:51 +05:30
crash_dump.c powerpc: Don't use 'struct ppc_inst' to reference instruction location 2021-06-17 00:09:00 +10:00
dawr.c powerpc: rename powerpc_debugfs_root to arch_debugfs_dir 2021-08-13 22:04:26 +10:00
dbell.c powerpc: handle irq_enter/irq_exit in interrupt handler wrappers 2021-02-09 00:10:49 +11:00
dma-iommu.c powerpc/iommu: Incorrect DDW Table is referenced for SR-IOV device 2023-05-24 17:36:55 +01:00
dma-mask.c
dma-swiotlb.c
dt_cpu_ftrs.c arch: powerpc: Stop building and using oprofile 2021-01-29 10:05:51 +05:30
early_32.c
eeh_cache.c powerpc: rename powerpc_debugfs_root to arch_debugfs_dir 2021-08-13 22:04:26 +10:00
eeh_driver.c pci-v5.9-changes 2020-08-07 18:48:15 -07:00
eeh_event.c
eeh_pe.c powerpc/eeh: Delete eeh_pe->config_addr 2020-10-07 22:34:47 +11:00
eeh_sysfs.c powerpc/eeh: Pass eeh_dev to eeh_ops->resume_notify() 2020-07-26 23:34:20 +10:00
eeh.c powerpc: rename powerpc_debugfs_root to arch_debugfs_dir 2021-08-13 22:04:26 +10:00
entry_32.S powerpc/47x: Fix 47x syscall return crash 2023-10-25 11:58:59 +02:00
entry_64.S powerpc/rtas: Keep MSR[RI] set when calling RTAS 2022-06-09 10:22:42 +02:00
epapr_hcalls.S
epapr_paravirt.c powerpc: Don't use 'struct ppc_inst' to reference instruction location 2021-06-17 00:09:00 +10:00
exceptions-64e.S powerpc: flexible GPR range save/restore macros 2022-07-12 16:35:02 +02:00
exceptions-64s.S powerpc: flexible GPR range save/restore macros 2022-07-12 16:35:02 +02:00
fadump.c powerpc/fadump: reset dump area size if fadump memory reserve fails 2023-09-19 12:22:41 +02:00
firmware.c powerpc: fix unbalanced node refcount in check_kvm_guest() 2021-11-18 19:16:51 +01:00
fpu.S powerpc: Don't clobber f0/vs0 during fp|altivec register save 2023-12-08 08:48:01 +01:00
fsl_booke_entry_mapping.S powerpc/booke: Avoid link stack corruption in several places 2021-08-25 13:35:47 +10:00
head_8xx.S powerpc/8xx: Fix pinned TLBs with CONFIG_STRICT_KERNEL_RWX 2021-11-25 09:48:44 +01:00
head_32.h powerpc/32s: Do kuep_lock() and kuep_unlock() in assembly 2023-10-25 11:58:59 +02:00
head_40x.S powerpc/40x: Map 32Mbytes of memory at startup 2022-01-27 11:05:01 +01:00
head_44x.S powerpc/booke: Avoid link stack corruption in several places 2021-08-25 13:35:47 +10:00
head_64.S powerpc/toc: Future proof kernel toc 2024-01-25 14:52:32 -08:00
head_book3s_32.S powerpc/32s: Do kuep_lock() and kuep_unlock() in assembly 2023-10-25 11:58:59 +02:00
head_booke.h powerpc: flexible GPR range save/restore macros 2022-07-12 16:35:02 +02:00
head_fsl_booke.S powerpc/85xx: Fix math emulation exception 2023-11-08 17:26:45 +01:00
hw_breakpoint_constraints.c powerpc/watchpoint: Disable pagefaults when getting user instruction 2023-10-06 13:18:18 +02:00
hw_breakpoint.c powerpc/watchpoints: Annotate atomic context in more places 2023-10-06 13:18:18 +02:00
idle_6xx.S powerpc/mm: Switch obsolete dssall to .long 2022-06-14 18:36:27 +02:00
idle_book3e.S
idle_book3s.S powerpc/idle: Don't corrupt back chain when going idle 2021-10-20 21:37:58 +11:00
idle_e500.S powerpc/32: Return directly from power_save_ppc32_restore() 2021-03-29 13:22:10 +11:00
idle.c powerpc/mm: Switch obsolete dssall to .long 2022-06-14 18:36:27 +02:00
ima_arch.c
interrupt_64.S powerpc: flexible GPR range save/restore macros 2022-07-12 16:35:02 +02:00
interrupt.c powerpc/32s: Do kuep_lock() and kuep_unlock() in assembly 2023-10-25 11:58:59 +02:00
io-workarounds.c powerpc: Fix reverse map real-mode address lookup with huge vmalloc 2021-05-28 22:54:27 +10:00
io.c
iomap.c powerpc: inline iomap accessors 2020-12-04 01:01:09 +11:00
iommu.c powerpc/iommu: Fix notifiers being shared by PCI and VIO buses 2023-09-19 12:22:42 +02:00
irq.c powerpc/64: warn if local irqs are enabled in NMI or hardirq context 2021-10-07 19:54:55 +11:00
isa-bridge.c mm/vmalloc: remove unmap_kernel_range 2021-04-30 11:20:40 -07:00
jump_label.c powerpc: Don't use 'struct ppc_inst' to reference instruction location 2021-06-17 00:09:00 +10:00
kdebugfs.c powerpc: rename powerpc_debugfs_root to arch_debugfs_dir 2021-08-13 22:04:26 +10:00
kgdb.c powerpc/64s: avoid reloading (H)SRR registers if they are still valid 2021-06-25 00:06:55 +10:00
kprobes-ftrace.c powerpc/64s: avoid reloading (H)SRR registers if they are still valid 2021-06-25 00:06:55 +10:00
kprobes.c powerpc/kprobes: Fix null pointer reference in arch_prepare_kprobe() 2022-10-26 12:35:23 +02:00
kvm_emul.S
kvm.c gup: Turn fault_in_pages_{readable,writeable} into fault_in_{readable,writeable} 2022-05-01 17:22:28 +02:00
l2cr_6xx.S powerpc/mm: Switch obsolete dssall to .long 2022-06-14 18:36:27 +02:00
legacy_serial.c powerpc/legacy_serial: Fix UBSAN: array-index-out-of-bounds 2021-05-12 11:07:39 +10:00
Makefile powerpc/64s: Disable stack variable initialisation for prom_init 2022-08-17 14:23:05 +02:00
mce_power.c powerpc/powernv: Fix machine check reporting of async store errors 2021-06-21 21:13:19 +10:00
mce.c powerpc/mce: Fix access error in mce handler 2021-09-13 22:34:12 +10:00
misc_32.S powerpc: Avoid link stack corruption in misc asm functions 2021-08-25 13:35:47 +10:00
misc_64.S powerpc: Avoid link stack corruption in misc asm functions 2021-08-25 13:35:47 +10:00
misc.S powerpc: Avoid link stack corruption in misc asm functions 2021-08-25 13:35:47 +10:00
module_32.c powerpc/modules: Use PPC_RAW_xx() macros 2021-06-16 00:16:48 +10:00
module_64.c powerpc/module_64: Fix livepatching for RO modules 2021-12-22 09:32:49 +01:00
module.c powerpc/modules: Don't WARN on first module allocation attempt 2022-01-27 11:04:08 +01:00
msi.c
note.S
nvram_64.c printk: introduce a kmsg_dump iterator 2021-03-08 11:43:27 +01:00
of_platform.c powerpc/eeh: Remove eeh_dev_phb_init_dynamic() 2020-07-26 23:34:19 +10:00
optprobes_head.S powerpc: flexible GPR range save/restore macros 2022-07-12 16:35:02 +02:00
optprobes.c powerpc/kprobes: Fix Oops by passing ppc_inst as a pointer to emulate_step() on ppc32 2021-06-25 14:46:51 +10:00
paca.c Revert "powerpc/rtas: Implement reentrant rtas call" 2022-10-15 07:59:02 +02:00
pci_32.c
pci_64.c mm/vmalloc: remove unmap_kernel_range 2021-04-30 11:20:40 -07:00
pci_dn.c powerpc/pci_dn: Add missing of_node_put() 2022-10-26 12:35:22 +02:00
pci_of_scan.c
pci-common.c powerpc/pci: Fix get_phb_number() locking 2022-08-25 11:40:23 +02:00
pci-hotplug.c
pmc.c
ppc32.h
ppc_save_regs.S powerpc: update ppc_save_regs to save current r1 in pt_regs 2023-07-23 13:47:13 +02:00
proc_powerpc.c
process.c powerpc: Enable execve syscall exit tracepoint 2022-06-29 09:03:30 +02:00
prom_init_check.sh powerpc/prom_init: Fix kernel config grep 2022-07-07 17:53:24 +02:00
prom_init.c powerpc/prom_init: Fix improper check of prom_getprop() 2022-01-27 11:04:06 +01:00
prom_parse.c
prom.c powerpc/64: Init jump labels before parse_early_param() 2022-08-25 11:40:45 +02:00
reloc_32.S powerpc: Avoid link stack corruption in misc asm functions 2021-08-25 13:35:47 +10:00
reloc_64.S powerpc/64: Add UADDR64 relocation support 2022-05-09 09:14:44 +02:00
rtas_flash.c powerpc/rtas_flash: allow user copy to flash block cache objects 2023-08-26 14:23:31 +02:00
rtas_pci.c
rtas-proc.c powerpc/rtas: rename RTAS_RMOBUF_MAX to RTAS_USER_REGION_SIZE 2021-04-14 23:04:16 +10:00
rtas-rtc.c powerpc/rtas-rtc: remove unused constant 2021-06-25 14:47:20 +10:00
rtas.c powerpc/rtas: use memmove for potentially overlapping buffer copy 2023-05-11 23:00:34 +09:00
rtasd.c powerpc: Replace deprecated CPU-hotplug functions. 2021-08-10 23:14:56 +10:00
secure_boot.c powerpc/pseries: Detect secure and trusted boot state of the system. 2020-07-16 14:49:53 +10:00
security.c powerpc/security: Fix Speculation_Store_Bypass reporting on Power10 2023-07-23 13:47:47 +02:00
secvar-ops.c
secvar-sysfs.c powerpc/secvar: fix refcount leak in format_show() 2022-04-13 20:59:08 +02:00
setup_32.c powerpc: Don't use 'struct ppc_inst' to reference instruction location 2021-06-17 00:09:00 +10:00
setup_64.c powerpc: rename powerpc_debugfs_root to arch_debugfs_dir 2021-08-13 22:04:26 +10:00
setup-common.c powerpc/mm: Fix boot crash with FLATMEM 2023-11-08 17:26:48 +01:00
setup.h powerpc: remove unneeded semicolons 2021-02-09 00:10:50 +11:00
signal_32.c powerpc/signal32: Force inlining of __unsafe_save_user_regs() and save_tm_user_regs_unsafe() 2023-07-23 13:47:12 +02:00
signal_64.c gup: Turn fault_in_pages_{readable,writeable} into fault_in_{readable,writeable} 2022-05-01 17:22:28 +02:00
signal.c entry: rseq: Call rseq_handle_notify_resume() in tracehook_notify_resume() 2021-09-22 10:24:01 -04:00
signal.h powerpc/signal32: Fix sigset_t copy 2021-11-25 09:48:44 +01:00
smp-tbsync.c
smp.c powerpc/fadump: Fix inaccurate CPU state info in vmcore generated with panic 2022-01-27 11:05:02 +01:00
stacktrace.c powerpc/stacktrace: Include linux/delay.h 2021-08-03 22:33:37 +10:00
suspend.c
swsusp_32.S powerpc/mm: Switch obsolete dssall to .long 2022-06-14 18:36:27 +02:00
swsusp_64.c
swsusp_asm64.S powerpc/mm: Switch obsolete dssall to .long 2022-06-14 18:36:27 +02:00
swsusp_booke.S
swsusp.c
sys_ppc32.c powerpc: Fix fallocate and fadvise64_64 compat parameter combination 2022-10-26 12:35:22 +02:00
syscalls.c powerpc: Fix fallocate and fadvise64_64 compat parameter combination 2022-10-26 12:35:22 +02:00
sysfs.c powerpc/smp: Fix OOPS in topology_init() 2021-08-07 08:53:59 +10:00
systbl_chk.sh
systbl.S powerpc: align syscall table for ppc32 2022-09-08 12:28:03 +02:00
tau_6xx.c powerpc/tau: Add 'static' storage qualifier to 'tau_work' definition 2021-08-20 17:00:53 +10:00
time.c powerpc/kcsan: Exclude udelay to prevent recursive instrumentation 2023-03-17 08:49:01 +01:00
tm.S powerpc/tm: Fix more userspace r13 corruption 2022-07-12 16:35:02 +02:00
traps.c powerpc: Only define __parse_fpscr() when required 2023-11-20 11:08:26 +01:00
ucall.S
udbg_16550.c powerpc/microwatt: Use standard 16550 UART for console 2021-06-21 21:16:31 +10:00
udbg.c isystem: ship and use stdarg.h 2021-08-19 09:02:55 +09:00
uprobes.c powerpc/64s: avoid reloading (H)SRR registers if they are still valid 2021-06-25 00:06:55 +10:00
vdso32_wrapper.S powerpc/vdso: fix unnecessary rebuilds of vgettimeofday.o 2021-01-30 22:23:42 +11:00
vdso64_wrapper.S powerpc/vdso: fix unnecessary rebuilds of vgettimeofday.o 2021-01-30 22:23:42 +11:00
vdso.c powerpc/vdso: Add support for time namespaces 2021-04-14 23:04:44 +10:00
vecemu.c
vector.S powerpc: Don't clobber f0/vs0 during fp|altivec register save 2023-12-08 08:48:01 +01:00
vmlinux.lds.S powerpc/toc: Future proof kernel toc 2024-01-25 14:52:32 -08:00
watchdog.c powerpc/watchdog: Fix missed watchdog reset due to memory ordering race 2022-01-27 11:04:57 +01:00