File tree Expand file tree Collapse file tree 10 files changed +17
-12
lines changed Expand file tree Collapse file tree 10 files changed +17
-12
lines changed Original file line number Diff line number Diff line change @@ -1120,6 +1120,10 @@ ifdef CONFIG_LD_ORPHAN_WARN
11201120LDFLAGS_vmlinux += --orphan-handling=$(CONFIG_LD_ORPHAN_WARN_LEVEL )
11211121endif
11221122
1123+ ifneq ($(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS ) ,)
1124+ LDFLAGS_vmlinux += --emit-relocs --discard-none
1125+ endif
1126+
11231127# Align the bit size of userspace programs with the kernel
11241128KBUILD_USERCFLAGS += $(filter -m32 -m64 --target=% , $(KBUILD_CPPFLAGS ) $(KBUILD_CFLAGS ) )
11251129KBUILD_USERLDFLAGS += $(filter -m32 -m64 --target=% , $(KBUILD_CPPFLAGS ) $(KBUILD_CFLAGS ) )
Original file line number Diff line number Diff line change @@ -1695,6 +1695,13 @@ config ARCH_HAS_KERNEL_FPU_SUPPORT
16951695 Architectures that select this option can run floating-point code in
16961696 the kernel, as described in Documentation/core-api/floating-point.rst.
16971697
1698+ config ARCH_VMLINUX_NEEDS_RELOCS
1699+ bool
1700+ help
1701+ Whether the architecture needs vmlinux to be built with static
1702+ relocations preserved. This is used by some architectures to
1703+ construct bespoke relocation tables for KASLR.
1704+
16981705source "kernel/gcov/Kconfig"
16991706
17001707source "scripts/gcc-plugins/Kconfig"
Original file line number Diff line number Diff line change @@ -2617,6 +2617,7 @@ config RELOCATABLE
26172617 CPU_MIPS32_R6 || CPU_MIPS64_R6 || \
26182618 CPU_P5600 || CAVIUM_OCTEON_SOC || \
26192619 CPU_LOONGSON64
2620+ select ARCH_VMLINUX_NEEDS_RELOCS
26202621 help
26212622 This builds a kernel image that retains relocation information
26222623 so it can be loaded someplace besides the default 1MB.
Original file line number Diff line number Diff line change @@ -100,10 +100,6 @@ LDFLAGS_vmlinux += -G 0 -static -n -nostdlib
100100KBUILD_AFLAGS_MODULE += -mlong-calls
101101KBUILD_CFLAGS_MODULE += -mlong-calls
102102
103- ifeq ($(CONFIG_RELOCATABLE ) ,y)
104- LDFLAGS_vmlinux += --emit-relocs
105- endif
106-
107103cflags-y += -ffreestanding
108104
109105cflags-$(CONFIG_CPU_BIG_ENDIAN) += -EB
Original file line number Diff line number Diff line change @@ -1077,6 +1077,7 @@ config RELOCATABLE
10771077 bool "Build a relocatable kernel"
10781078 depends on MMU && 64BIT && !XIP_KERNEL
10791079 select MODULE_SECTIONS if MODULES
1080+ select ARCH_VMLINUX_NEEDS_RELOCS
10801081 help
10811082 This builds a kernel as a Position Independent Executable (PIE),
10821083 which retains all relocation metadata required to relocate the
Original file line number Diff line number Diff line change 88
99LDFLAGS_vmlinux := -z norelro
1010ifeq ($(CONFIG_RELOCATABLE ) ,y)
11- LDFLAGS_vmlinux += -shared -Bsymbolic -z notext --emit-relocs
11+ LDFLAGS_vmlinux += -shared -Bsymbolic -z notext
1212 KBUILD_CFLAGS += -fPIE
1313endif
1414ifeq ($(CONFIG_DYNAMIC_FTRACE ) ,y)
Original file line number Diff line number Diff line change @@ -630,6 +630,7 @@ endchoice
630630
631631config RELOCATABLE
632632 def_bool y
633+ select ARCH_VMLINUX_NEEDS_RELOCS
633634 help
634635 This builds a kernel image that retains relocation information
635636 so it can be loaded at an arbitrary address.
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ KBUILD_CFLAGS_MODULE += -fPIC
1515KBUILD_AFLAGS += -m64
1616KBUILD_CFLAGS += -m64
1717KBUILD_CFLAGS += -fPIC
18- LDFLAGS_vmlinux := -no-pie --emit-relocs --discard-none
18+ LDFLAGS_vmlinux := -no-pie
1919extra_tools := relocs
2020aflags_dwarf := -Wa,-gdwarf-2
2121KBUILD_AFLAGS_DECOMPRESSOR := $(CLANG_FLAGS ) -m64 -D__ASSEMBLY__
Original file line number Diff line number Diff line change @@ -2200,6 +2200,7 @@ config RANDOMIZE_BASE
22002200config X86_NEED_RELOCS
22012201 def_bool y
22022202 depends on RANDOMIZE_BASE || (X86_32 && RELOCATABLE)
2203+ select ARCH_VMLINUX_NEEDS_RELOCS
22032204
22042205config PHYSICAL_ALIGN
22052206 hex "Alignment value to which kernel should be aligned"
Original file line number Diff line number Diff line change @@ -251,12 +251,6 @@ endif
251251
252252KBUILD_LDFLAGS += -m elf_$(UTS_MACHINE )
253253
254- ifdef CONFIG_X86_NEED_RELOCS
255- LDFLAGS_vmlinux := --emit-relocs --discard-none
256- else
257- LDFLAGS_vmlinux :=
258- endif
259-
260254#
261255# The 64-bit kernel must be aligned to 2MB. Pass -z max-page-size=0x200000 to
262256# the linker to force 2MB page size regardless of the default page size used
You can’t perform that action at this time.
0 commit comments