From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 37C1FC433FE for ; Tue, 8 Mar 2022 15:58:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348440AbiCHP6L (ORCPT ); Tue, 8 Mar 2022 10:58:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348062AbiCHP4I (ORCPT ); Tue, 8 Mar 2022 10:56:08 -0500 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4EAF34F9E0 for ; Tue, 8 Mar 2022 07:55:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=uY+jcOMFirwczJeMx5tMsqeYilw19841F6sj97KYysQ=; b=lyapG0Pa0xWATfvmzg4G9EXwD+ 4fh5LukSK11kqmUs4dSnLuVURX4iepaaT1FIa+02msh7iS96xayjvn1pVNPHtv+7Jv8uu7oQc6DMy 4w1HtQ02VeYDa5jPBP+aH4f4TtvxDmSRBAhNfqAarhffQ3EtJkEG+T0kkRWjI7d7/83e5QMrrxTFn +5EKB6bIaU8QAbL0DuFbxvPjxmFTFSMKAFFSukbWGqZG3KEvDXZA1y5CJ3sR87rUVvpkI+g73PGu7 mPzuC+nsHr9XkkeQbRjfhRrbvrH//XEWw4jEvaP/p27RgZ1vNXrWvLDnK7Hy0XbDoKs3Im88jBjj0 yi6oM7+A==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1nRcAd-00GUik-E2; Tue, 08 Mar 2022 15:54:43 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 51426302DD9; Tue, 8 Mar 2022 16:54:40 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id E3BCF2B5649DA; Tue, 8 Mar 2022 16:54:39 +0100 (CET) Message-ID: <20220308154319.528181453@infradead.org> User-Agent: quilt/0.66 Date: Tue, 08 Mar 2022 16:30:51 +0100 From: Peter Zijlstra To: x86@kernel.org, joao@overdrivepizza.com, hjl.tools@gmail.com, jpoimboe@redhat.com, andrew.cooper3@citrix.com Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, ndesaulniers@google.com, keescook@chromium.org, samitolvanen@google.com, mark.rutland@arm.com, alyssa.milburn@intel.com, mbenes@suse.cz, rostedt@goodmis.org, mhiramat@kernel.org, alexei.starovoitov@gmail.com, Nathan Chancellor Subject: [PATCH v4 40/45] Kbuild: Allow whole module objtool runs References: <20220308153011.021123062@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Just like we have vmlinux.o objtool runs, add the ability to do whole module objtool runs. Suggested-by: Nathan Chancellor Signed-off-by: Peter Zijlstra (Intel) --- scripts/Makefile.build | 44 ++------------------------------------------ scripts/Makefile.lib | 45 +++++++++++++++++++++++++++++++++++++++++++++ scripts/Makefile.modfinal | 1 + 3 files changed, 48 insertions(+), 42 deletions(-) --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -223,41 +223,6 @@ cmd_record_mcount = $(if $(findstring $( $(sub_cmd_record_mcount)) endif # CONFIG_FTRACE_MCOUNT_USE_RECORDMCOUNT -ifdef CONFIG_STACK_VALIDATION - -objtool := $(objtree)/tools/objtool/objtool - -objtool_args = \ - $(if $(CONFIG_UNWINDER_ORC),orc generate,check) \ - $(if $(part-of-module), --module) \ - $(if $(CONFIG_FRAME_POINTER),, --no-fp) \ - $(if $(CONFIG_GCOV_KERNEL)$(CONFIG_LTO_CLANG), --no-unreachable)\ - $(if $(CONFIG_RETPOLINE), --retpoline) \ - $(if $(CONFIG_X86_SMAP), --uaccess) \ - $(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount) \ - $(if $(CONFIG_SLS), --sls) - -cmd_objtool = $(if $(objtool-enabled), ; $(objtool) $(objtool_args) $@) -cmd_gen_objtooldep = $(if $(objtool-enabled), { echo ; echo '$@: $$(wildcard $(objtool))' ; } >> $(dot-target).cmd) - -endif # CONFIG_STACK_VALIDATION - -ifdef CONFIG_LTO_CLANG - -# Skip objtool for LLVM bitcode -$(obj)/%.o: objtool-enabled := - -else - -# 'OBJECT_FILES_NON_STANDARD := y': skip objtool checking for a directory -# 'OBJECT_FILES_NON_STANDARD_foo.o := 'y': skip objtool checking for a file -# 'OBJECT_FILES_NON_STANDARD_foo.o := 'n': override directory skip for a file - -$(obj)/%.o: objtool-enabled = $(if $(filter-out y%, \ - $(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n),y) - -endif - ifdef CONFIG_TRIM_UNUSED_KSYMS cmd_gen_ksymdeps = \ $(CONFIG_SHELL) $(srctree)/scripts/gen_ksymdeps.sh $@ >> $(dot-target).cmd @@ -292,21 +257,16 @@ ifdef CONFIG_LTO_CLANG # Module .o files may contain LLVM bitcode, compile them into native code # before ELF processing quiet_cmd_cc_lto_link_modules = LTO [M] $@ -cmd_cc_lto_link_modules = \ + cmd_cc_lto_link_modules = \ $(LD) $(ld_flags) -r -o $@ \ $(shell [ -s $(@:.lto.o=.o.symversions) ] && \ echo -T $(@:.lto.o=.o.symversions)) \ --whole-archive $(filter-out FORCE,$^) \ $(cmd_objtool) - -# objtool was skipped for LLVM bitcode, run it now that we have compiled -# modules into native code -$(obj)/%.lto.o: objtool-enabled = y -$(obj)/%.lto.o: part-of-module := y +endif $(obj)/%.lto.o: $(obj)/%.o FORCE $(call if_changed,cc_lto_link_modules) -endif cmd_mod = { \ echo $(if $($*-objs)$($*-y)$($*-m), $(addprefix $(obj)/, $($*-objs) $($*-y) $($*-m)), $(@:.mod=.o)); \ --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -533,3 +533,48 @@ define filechk_offsets echo ""; \ echo "#endif" endef + +# objtool +# --------------------------------------------------------------------------- + +ifdef CONFIG_STACK_VALIDATION + +objtool := $(objtree)/tools/objtool/objtool + +objtool_args = \ + $(if $(CONFIG_UNWINDER_ORC),orc generate,check) \ + $(if $(part-of-module), --module) \ + $(if $(CONFIG_FRAME_POINTER),, --no-fp) \ + $(if $(CONFIG_GCOV_KERNEL)$(CONFIG_LTO_CLANG), --no-unreachable)\ + $(if $(CONFIG_RETPOLINE), --retpoline) \ + $(if $(CONFIG_X86_SMAP), --uaccess) \ + $(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount) \ + $(if $(CONFIG_SLS), --sls) + +cmd_objtool = $(if $(objtool-enabled), ; $(objtool) $(objtool_args) $@) +cmd_objtool_mod = $(if $(objtool-enabled), $(objtool) $(objtool_args) $(@:.ko=.o) ; ) +cmd_gen_objtooldep = $(if $(objtool-enabled), { echo ; echo '$@: $$(wildcard $(objtool))' ; } >> $(dot-target).cmd) + +endif # CONFIG_STACK_VALIDATION + +ifdef CONFIG_LTO_CLANG + +# Skip objtool for LLVM bitcode +$(obj)/%.o: objtool-enabled := + +# objtool was skipped for LLVM bitcode, run it now that we have compiled +# modules into native code +$(obj)/%.lto.o: objtool-enabled = y +$(obj)/%.lto.o: part-of-module := y + +else + +# 'OBJECT_FILES_NON_STANDARD := y': skip objtool checking for a directory +# 'OBJECT_FILES_NON_STANDARD_foo.o := 'y': skip objtool checking for a file +# 'OBJECT_FILES_NON_STANDARD_foo.o := 'n': override directory skip for a file + +$(obj)/%.o: objtool-enabled = $(if $(filter-out y%, \ + $(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n),y) + +endif + --- a/scripts/Makefile.modfinal +++ b/scripts/Makefile.modfinal @@ -32,6 +32,7 @@ ARCH_POSTLINK := $(wildcard $(srctree)/a quiet_cmd_ld_ko_o = LD [M] $@ cmd_ld_ko_o += \ + $(cmd_objtool_mod) \ $(LD) -r $(KBUILD_LDFLAGS) \ $(KBUILD_LDFLAGS_MODULE) $(LDFLAGS_MODULE) \ -T scripts/module.lds -o $@ $(filter %.o, $^); \