From: Masahiro Yamada <masahiroy@kernel.org>
To: linux-kbuild@vger.kernel.org
Cc: Nick Desaulniers <ndesaulniers@google.com>,
linux-kernel@vger.kernel.org,
Josh Poimboeuf <jpoimboe@redhat.com>,
Masahiro Yamada <masahiroy@kernel.org>,
Michal Marek <michal.lkml@markovi.net>,
Nathan Chancellor <nathan@kernel.org>, Tom Rix <trix@redhat.com>,
llvm@lists.linux.dev
Subject: [PATCH 3/4] kbuild: move vmlinux.o link to scripts/Makefile.vmlinux_o
Date: Sun, 29 May 2022 00:47:03 +0900 [thread overview]
Message-ID: <20220528154704.2576290-3-masahiroy@kernel.org> (raw)
In-Reply-To: <20220528154704.2576290-1-masahiroy@kernel.org>
This is a preparation for the objtool move in the next commit.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---
scripts/Makefile.vmlinux_o | 61 ++++++++++++++++++++++++++++++++++++++
scripts/link-vmlinux.sh | 41 +------------------------
2 files changed, 62 insertions(+), 40 deletions(-)
create mode 100644 scripts/Makefile.vmlinux_o
diff --git a/scripts/Makefile.vmlinux_o b/scripts/Makefile.vmlinux_o
new file mode 100644
index 000000000000..a9b375ca86d5
--- /dev/null
+++ b/scripts/Makefile.vmlinux_o
@@ -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)
diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
index b593cb1a8137..90680b6bd710 100755
--- a/scripts/link-vmlinux.sh
+++ b/scripts/link-vmlinux.sh
@@ -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 objects in vmlinux
--
2.32.0
next prev parent reply other threads:[~2022-05-28 15:49 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-28 15:47 [PATCH 1/4] kbuild: remove redundant cleanups in scripts/link-vmlinux.sh Masahiro Yamada
2022-05-28 15:47 ` [PATCH 2/4] kbuild: clean .tmp_* pattern by make clean Masahiro Yamada
2022-05-29 14:40 ` Sedat Dilek
2022-05-29 17:32 ` Masahiro Yamada
2022-05-30 9:34 ` Sedat Dilek
2022-06-01 19:49 ` Nicolas Schier
2022-06-03 13:22 ` Masahiro Yamada
2022-05-28 15:47 ` Masahiro Yamada [this message]
2022-05-29 14:42 ` [PATCH 3/4] kbuild: move vmlinux.o link to scripts/Makefile.vmlinux_o Sedat Dilek
2022-05-28 15:47 ` [PATCH 4/4] kbuild: factor out the common objtool arguments Masahiro Yamada
2022-05-29 14:46 ` Sedat Dilek
2022-05-29 17:34 ` Masahiro Yamada
2022-05-30 9:36 ` Sedat Dilek
2022-05-29 14:37 ` [PATCH 1/4] kbuild: remove redundant cleanups in scripts/link-vmlinux.sh Sedat Dilek
2022-05-29 17:30 ` Masahiro Yamada
2022-05-30 9:33 ` Sedat Dilek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220528154704.2576290-3-masahiroy@kernel.org \
--to=masahiroy@kernel.org \
--cc=jpoimboe@redhat.com \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=michal.lkml@markovi.net \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=trix@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®