OSDN Git Service

kbuild: move vmlinux.o link to scripts/Makefile.vmlinux_o
authorMasahiro Yamada <masahiroy@kernel.org>
Sat, 28 May 2022 15:47:03 +0000 (00:47 +0900)
committerMasahiro Yamada <masahiroy@kernel.org>
Sat, 4 Jun 2022 21:20:57 +0000 (06:20 +0900)
This is a preparation for moving the objtool rule in the next commit.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Tested-by: Sedat Dilek <sedat.dilek@gmail.com> # LLVM-14 (x86-64)
scripts/Makefile.vmlinux_o [new file with mode: 0644]
scripts/link-vmlinux.sh

diff --git a/scripts/Makefile.vmlinux_o b/scripts/Makefile.vmlinux_o
new file mode 100644 (file)
index 0000000..a9b375c
--- /dev/null
@@ -0,0 +1,61 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+PHONY := __default
+__default: vmlinux.o
+
+include include/config/auto.conf
+include $(srctree)/scripts/Kbuild.include
+
+# Generate a linker script to ensure correct ordering of initcalls for Clang LTO
+# ---------------------------------------------------------------------------
+
+quiet_cmd_gen_initcalls_lds = GEN     $@
+      cmd_gen_initcalls_lds = \
+       $(PYTHON3) $(srctree)/scripts/jobserver-exec \
+       $(PERL) $(real-prereqs) > $@
+
+.tmp_initcalls.lds: $(srctree)/scripts/generate_initcall_order.pl \
+               $(KBUILD_VMLINUX_OBJS) $(KBUILD_VMLINUX_LIBS) FORCE
+       $(call if_changed,gen_initcalls_lds)
+
+targets := .tmp_initcalls.lds
+
+ifdef CONFIG_LTO_CLANG
+initcalls-lds := .tmp_initcalls.lds
+endif
+
+# Link of vmlinux.o used for section mismatch analysis
+# ---------------------------------------------------------------------------
+
+quiet_cmd_ld_vmlinux.o = LD      $@
+      cmd_ld_vmlinux.o = \
+       $(LD) ${KBUILD_LDFLAGS} -r -o $@ \
+       $(addprefix -T , $(initcalls-lds)) \
+       --whole-archive $(KBUILD_VMLINUX_OBJS) --no-whole-archive \
+       --start-group $(KBUILD_VMLINUX_LIBS) --end-group \
+
+define rule_ld_vmlinux.o
+       $(call cmd_and_savecmd,ld_vmlinux.o)
+endef
+
+vmlinux.o: $(initcalls-lds) $(KBUILD_VMLINUX_OBJS) $(KBUILD_VMLINUX_LIBS) FORCE
+       $(call if_changed_rule,ld_vmlinux.o)
+
+targets += vmlinux.o
+
+# Add FORCE to the prequisites of a target to force it to be always rebuilt.
+# ---------------------------------------------------------------------------
+
+PHONY += FORCE
+FORCE:
+
+# Read all saved command lines and dependencies for the $(targets) we
+# may be building above, using $(if_changed{,_dep}). As an
+# optimization, we don't need to read them if the target does not
+# exist, we will rebuild anyway in that case.
+
+existing-targets := $(wildcard $(sort $(targets)))
+
+-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
+
+.PHONY: $(PHONY)
index 3f51b08..bf685d4 100755 (executable)
@@ -45,45 +45,6 @@ info()
        printf "  %-7s %s\n" "${1}" "${2}"
 }
 
-# Generate a linker script to ensure correct ordering of initcalls.
-gen_initcalls()
-{
-       info GEN .tmp_initcalls.lds
-
-       ${PYTHON3} ${srctree}/scripts/jobserver-exec            \
-       ${PERL} ${srctree}/scripts/generate_initcall_order.pl   \
-               ${KBUILD_VMLINUX_OBJS} ${KBUILD_VMLINUX_LIBS}   \
-               > .tmp_initcalls.lds
-}
-
-# Link of vmlinux.o used for section mismatch analysis
-# ${1} output file
-modpost_link()
-{
-       local objects
-       local lds=""
-
-       objects="--whole-archive                                \
-               ${KBUILD_VMLINUX_OBJS}                          \
-               --no-whole-archive                              \
-               --start-group                                   \
-               ${KBUILD_VMLINUX_LIBS}                          \
-               --end-group"
-
-       if is_enabled CONFIG_LTO_CLANG; then
-               gen_initcalls
-               lds="-T .tmp_initcalls.lds"
-
-               # This might take a while, so indicate that we're doing
-               # an LTO link
-               info LTO ${1}
-       else
-               info LD ${1}
-       fi
-
-       ${LD} ${KBUILD_LDFLAGS} -r -o ${1} ${lds} ${objects}
-}
-
 objtool_link()
 {
        local objtoolcmd;
@@ -336,7 +297,7 @@ fi;
 ${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init need-builtin=1
 
 #link vmlinux.o
-modpost_link vmlinux.o
+${MAKE} -f "${srctree}/scripts/Makefile.vmlinux_o"
 objtool_link vmlinux.o
 
 # Generate the list of in-tree objects in vmlinux