Commit 9b400d17 authored by Ard Biesheuvel's avatar Ard Biesheuvel Committed by Masahiro Yamada
Browse files

kbuild: Introduce Kconfig symbol for linking vmlinux with relocations



Some architectures build vmlinux with static relocations preserved, but
strip them again from the final vmlinux image. Arch specific tools
consume these static relocations in order to construct relocation tables
for KASLR.

The fact that vmlinux is created, consumed and subsequently updated goes
against the typical, declarative paradigm used by Make, which is based
on rules and dependencies. So as a first step towards cleaning this up,
introduce a Kconfig symbol to declare that the arch wants to consume the
static relocations emitted into vmlinux. This will be wired up further
in subsequent patches.

Signed-off-by: default avatarArd Biesheuvel <ardb@kernel.org>
Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
parent e22bbb8e
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -1120,6 +1120,10 @@ ifdef CONFIG_LD_ORPHAN_WARN
LDFLAGS_vmlinux += --orphan-handling=$(CONFIG_LD_ORPHAN_WARN_LEVEL)
endif

ifneq ($(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS),)
LDFLAGS_vmlinux	+= --emit-relocs --discard-none
endif

# Align the bit size of userspace programs with the kernel
KBUILD_USERCFLAGS  += $(filter -m32 -m64 --target=%, $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS))
KBUILD_USERLDFLAGS += $(filter -m32 -m64 --target=%, $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS))
+7 −0
Original line number Diff line number Diff line
@@ -1695,6 +1695,13 @@ config ARCH_HAS_KERNEL_FPU_SUPPORT
	  Architectures that select this option can run floating-point code in
	  the kernel, as described in Documentation/core-api/floating-point.rst.

config ARCH_VMLINUX_NEEDS_RELOCS
	bool
	help
	  Whether the architecture needs vmlinux to be built with static
	  relocations preserved. This is used by some architectures to
	  construct bespoke relocation tables for KASLR.

source "kernel/gcov/Kconfig"

source "scripts/gcc-plugins/Kconfig"
+1 −0
Original line number Diff line number Diff line
@@ -2617,6 +2617,7 @@ config RELOCATABLE
		   CPU_MIPS32_R6 || CPU_MIPS64_R6 || \
		   CPU_P5600 || CAVIUM_OCTEON_SOC || \
		   CPU_LOONGSON64
	select ARCH_VMLINUX_NEEDS_RELOCS
	help
	  This builds a kernel image that retains relocation information
	  so it can be loaded someplace besides the default 1MB.
+0 −4
Original line number Diff line number Diff line
@@ -100,10 +100,6 @@ LDFLAGS_vmlinux += -G 0 -static -n -nostdlib
KBUILD_AFLAGS_MODULE		+= -mlong-calls
KBUILD_CFLAGS_MODULE		+= -mlong-calls

ifeq ($(CONFIG_RELOCATABLE),y)
LDFLAGS_vmlinux			+= --emit-relocs
endif

cflags-y += -ffreestanding

cflags-$(CONFIG_CPU_BIG_ENDIAN)		+= -EB
+1 −0
Original line number Diff line number Diff line
@@ -1077,6 +1077,7 @@ config RELOCATABLE
	bool "Build a relocatable kernel"
	depends on MMU && 64BIT && !XIP_KERNEL
	select MODULE_SECTIONS if MODULES
	select ARCH_VMLINUX_NEEDS_RELOCS
	help
          This builds a kernel as a Position Independent Executable (PIE),
          which retains all relocation metadata required to relocate the
Loading