Commit 596b0474 authored by Masahiro Yamada's avatar Masahiro Yamada
Browse files

kbuild: preprocess module linker script

There was a request to preprocess the module linker script like we
do for the vmlinux one. (https://lkml.org/lkml/2020/8/21/512

)

The difference between vmlinux.lds and module.lds is that the latter
is needed for external module builds, thus must be cleaned up by
'make mrproper' instead of 'make clean'. Also, it must be created
by 'make modules_prepare'.

You cannot put it in arch/$(SRCARCH)/kernel/, which is cleaned up by
'make clean'. I moved arch/$(SRCARCH)/kernel/module.lds to
arch/$(SRCARCH)/include/asm/module.lds.h, which is included from
scripts/module.lds.S.

scripts/module.lds is fine because 'make clean' keeps all the
build artifacts under scripts/.

You can add arch-specific sections in <asm/module.lds.h>.

Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
Tested-by: default avatarJessica Yu <jeyu@kernel.org>
Acked-by: default avatarWill Deacon <will@kernel.org>
Acked-by: default avatarGeert Uytterhoeven <geert@linux-m68k.org>
Acked-by: default avatarPalmer Dabbelt <palmerdabbelt@google.com>
Reviewed-by: default avatarKees Cook <keescook@chromium.org>
Acked-by: default avatarJessica Yu <jeyu@kernel.org>
parent 887af6d7
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -505,7 +505,6 @@ KBUILD_CFLAGS_KERNEL :=
KBUILD_AFLAGS_MODULE  := -DMODULE
KBUILD_CFLAGS_MODULE  := -DMODULE
KBUILD_LDFLAGS_MODULE :=
export KBUILD_LDS_MODULE := $(srctree)/scripts/module-common.lds
KBUILD_LDFLAGS :=
CLANG_FLAGS :=

@@ -1395,7 +1394,7 @@ endif
# using awk while concatenating to the final file.

PHONY += modules
modules: $(if $(KBUILD_BUILTIN),vmlinux) modules_check
modules: $(if $(KBUILD_BUILTIN),vmlinux) modules_check modules_prepare
	$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost

PHONY += modules_check
@@ -1412,6 +1411,7 @@ targets += modules.order
# Target to prepare building external modules
PHONY += modules_prepare
modules_prepare: prepare
	$(Q)$(MAKE) $(build)=scripts scripts/module.lds

# Target to install modules
PHONY += modules_install
@@ -1743,7 +1743,9 @@ help:
	@echo  '  clean           - remove generated files in module directory only'
	@echo  ''

PHONY += prepare
# no-op for external module builds
PHONY += prepare modules_prepare

endif # KBUILD_EXTMOD

# Single targets
@@ -1776,7 +1778,7 @@ MODORDER := .modules.tmp
endif

PHONY += single_modpost
single_modpost: $(single-no-ko)
single_modpost: $(single-no-ko) modules_prepare
	$(Q){ $(foreach m, $(single-ko), echo $(extmod-prefix)$m;) } > $(MODORDER)
	$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost

+0 −4
Original line number Diff line number Diff line
@@ -16,10 +16,6 @@ LDFLAGS_vmlinux += --be8
KBUILD_LDFLAGS_MODULE	+= --be8
endif

ifeq ($(CONFIG_ARM_MODULE_PLTS),y)
KBUILD_LDS_MODULE	+= $(srctree)/arch/arm/kernel/module.lds
endif

GZFLAGS		:=-9
#KBUILD_CFLAGS	+=-pipe

+2 −0
Original line number Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0 */
#ifdef CONFIG_ARM_MODULE_PLTS
SECTIONS {
	.plt : { BYTE(0) }
	.init.plt : { BYTE(0) }
}
#endif
+0 −4
Original line number Diff line number Diff line
@@ -115,10 +115,6 @@ endif

CHECKFLAGS	+= -D__aarch64__

ifeq ($(CONFIG_ARM64_MODULE_PLTS),y)
KBUILD_LDS_MODULE	+= $(srctree)/arch/arm64/kernel/module.lds
endif

ifeq ($(CONFIG_DYNAMIC_FTRACE_WITH_REGS),y)
  KBUILD_CPPFLAGS += -DCC_USING_PATCHABLE_FUNCTION_ENTRY
  CC_FLAGS_FTRACE := -fpatchable-function-entry=2
+2 −0
Original line number Diff line number Diff line
#ifdef CONFIG_ARM64_MODULE_PLTS
SECTIONS {
	.plt (NOLOAD) : { BYTE(0) }
	.init.plt (NOLOAD) : { BYTE(0) }
	.text.ftrace_trampoline (NOLOAD) : { BYTE(0) }
}
#endif
Loading