From nobody Mon Jun 22 14:10:42 2026 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 0E9C7C433EF for ; Tue, 22 Mar 2022 20:24:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233481AbiCVUZk (ORCPT ); Tue, 22 Mar 2022 16:25:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233132AbiCVUZe (ORCPT ); Tue, 22 Mar 2022 16:25:34 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C48866605; Tue, 22 Mar 2022 13:24:04 -0700 (PDT) Date: Tue, 22 Mar 2022 20:24:01 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1647980642; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nz/sukE6PInVvM9h+ofEmBCoxy87nddE04sngK80dBA=; b=k4IUlwag23zNNwqPUOpfD0gnY1oHfAMtHyjNMUDPxWqpGzLphj4Mwh/0lE+wbdel2kjMys mts5c8BVNqmTtciXRVo3W89+g0dEOLfu6R3AyWYM8Wki6YMlVsHASIkqu1qh2cdBYa8EUY 6DTOMWLa2SC6dQGWriXMaCfjoV6WoXt+4+0eLVOK32SGj6YgOz/pG94aJuu7RDs9JTlmYH AN/cD+X/nNrd3EqyBMylVoumF891NgvYFxUhtc+jirmxi6OMOU1ttgruf+MiM4AY0BGBEs LTC2OPr9sgF2CNX/MD1W2NiaEk4pFfUHHdUMaIX9MIQQu/r5MdlshZDfStif5w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1647980642; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nz/sukE6PInVvM9h+ofEmBCoxy87nddE04sngK80dBA=; b=B+SFKg38g0Leyn3zP6XTfVwI0tPT/2eDm9KIyEuz+bEZZQJc1jVpr4yHvSB++np+0eP98u poPtxHWEzGYi07DQ== From: "tip-bot2 for Peter Zijlstra" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/core] kbuild: Fixup the IBT kbuild changes Cc: Masahiro Yamada , "Peter Zijlstra (Intel)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: References: MIME-Version: 1.0 Message-ID: <164798064161.389.18177166280677198728.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the x86/core branch of tip: Commit-ID: d31ed5d767c0452b4f49846d80a0bfeafa3a4ded Gitweb: https://git.kernel.org/tip/d31ed5d767c0452b4f49846d80a0bfeaf= a3a4ded Author: Peter Zijlstra AuthorDate: Fri, 18 Mar 2022 12:19:27 +01:00 Committer: Peter Zijlstra CommitterDate: Tue, 22 Mar 2022 21:12:04 +01:00 kbuild: Fixup the IBT kbuild changes Masahiro-san deemed my kbuild changes to support whole module objtool runs too terrible to live and gracefully provided an alternative. Suggested-by: Masahiro Yamada Signed-off-by: Peter Zijlstra (Intel) Link: https://lkml.kernel.org/r/CAK7LNAQ2mYMnOKMQheVi+6byUFE3KEkjm1zcndNUfe= 0tORGvug@mail.gmail.com --- scripts/Makefile.build | 66 +++++++++++------------------------------ scripts/Makefile.lib | 4 +- scripts/mod/modpost.c | 12 +++---- 3 files changed, 27 insertions(+), 55 deletions(-) diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 926d254..2173a67 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -86,18 +86,12 @@ ifdef need-builtin targets-for-builtin +=3D $(obj)/built-in.a endif =20 -targets-for-modules :=3D +targets-for-modules :=3D $(patsubst %.o, %.mod, $(filter %.o, $(obj-m))) =20 -ifdef CONFIG_LTO_CLANG -targets-for-modules +=3D $(patsubst %.o, %.lto.o, $(filter %.o, $(obj-m))) -endif - -ifdef CONFIG_X86_KERNEL_IBT -targets-for-modules +=3D $(patsubst %.o, %.objtool, $(filter %.o, $(obj-m)= )) +ifneq ($(CONFIG_LTO_CLANG)$(CONFIG_X86_KERNEL_IBT),) +targets-for-modules +=3D $(patsubst %.o, %.prelink.o, $(filter %.o, $(obj-= m))) endif =20 -targets-for-modules +=3D $(patsubst %.o, %.mod, $(filter %.o, $(obj-m))) - ifdef need-modorder targets-for-modules +=3D $(obj)/modules.order endif @@ -244,31 +238,16 @@ objtool_args =3D \ $(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount) \ $(if $(CONFIG_SLS), --sls) =20 -cmd_objtool =3D $(if $(objtool-enabled), ; $(objtool) $(objtool_args) $(@:= .objtool=3D.o)) -cmd_gen_objtooldep =3D $(if $(objtool-enabled), { echo ; echo '$(@:.objtoo= l=3D.o): $$(wildcard $(objtool))' ; } >> $(dot-target).cmd) +cmd_objtool =3D $(if $(objtool-enabled), ; $(objtool) $(objtool_args) $@) +cmd_gen_objtooldep =3D $(if $(objtool-enabled), { echo ; echo '$@: $$(wild= card $(objtool))' ; } >> $(dot-target).cmd) =20 endif # CONFIG_STACK_VALIDATION =20 -ifdef CONFIG_LTO_CLANG +ifneq ($(CONFIG_LTO_CLANG)$(CONFIG_X86_KERNEL_IBT),) =20 # Skip objtool for LLVM bitcode $(obj)/%.o: objtool-enabled :=3D =20 -# objtool was skipped for LLVM bitcode, run it now that we have compiled -# modules into native code -$(obj)/%.lto.o: objtool-enabled =3D y -$(obj)/%.lto.o: part-of-module :=3D y - -else ifdef CONFIG_X86_KERNEL_IBT - -# Skip objtool on individual files -$(obj)/%.o: objtool-enabled :=3D - -# instead run objtool on the module as a whole, right before -# the final link pass with the linker script. -$(obj)/%.objtool: objtool-enabled =3D y -$(obj)/%.objtool: part-of-module :=3D y - else =20 # 'OBJECT_FILES_NON_STANDARD :=3D y': skip objtool checking for a directory @@ -310,19 +289,24 @@ $(obj)/%.o: $(src)/%.c $(recordmcount_source) FORCE $(call if_changed_rule,cc_o_c) $(call cmd,force_checksrc) =20 -ifdef CONFIG_LTO_CLANG +ifneq ($(CONFIG_LTO_CLANG)$(CONFIG_X86_KERNEL_IBT),) # Module .o files may contain LLVM bitcode, compile them into native code # before ELF processing -quiet_cmd_cc_lto_link_modules =3D LTO [M] $@ - cmd_cc_lto_link_modules =3D \ +quiet_cmd_cc_prelink_modules =3D LD [M] $@ + cmd_cc_prelink_modules =3D \ $(LD) $(ld_flags) -r -o $@ \ - $(shell [ -s $(@:.lto.o=3D.o.symversions) ] && \ - echo -T $(@:.lto.o=3D.o.symversions)) \ + $(shell [ -s $(@:.prelink.o=3D.o.symversions) ] && \ + echo -T $(@:.prelink.o=3D.o.symversions)) \ --whole-archive $(filter-out FORCE,$^) \ $(cmd_objtool) =20 -$(obj)/%.lto.o: $(obj)/%.o FORCE - $(call if_changed,cc_lto_link_modules) +# objtool was skipped for LLVM bitcode, run it now that we have compiled +# modules into native code +$(obj)/%.prelink.o: objtool-enabled =3D y +$(obj)/%.prelink.o: part-of-module :=3D y + +$(obj)/%.prelink.o: $(obj)/%.o FORCE + $(call if_changed,cc_prelink_modules) endif =20 cmd_mod =3D { \ @@ -333,18 +317,6 @@ cmd_mod =3D { \ $(obj)/%.mod: $(obj)/%$(mod-prelink-ext).o FORCE $(call if_changed,mod) =20 -# -# Since objtool will re-write the file it will change the timestamps, ther= efore -# it is critical that the %.objtool file gets a timestamp *after* objtool = runs. -# -# Additionally, care must be had with ordering this rule against the other= rules -# that take %.o as a dependency. -# -cmd_objtool_mod =3D true $(cmd_objtool) ; touch $@ - -$(obj)/%.objtool: $(obj)/%$(mod-prelink-ext).o FORCE - $(call if_changed,objtool_mod) - quiet_cmd_cc_lst_c =3D MKLST $@ cmd_cc_lst_c =3D $(CC) $(c_flags) -g -c -o $*.o $< && \ $(CONFIG_SHELL) $(srctree)/scripts/makelst $*.o \ @@ -498,7 +470,7 @@ $(obj)/lib.a: $(lib-y) FORCE # Do not replace $(filter %.o,^) with $(real-prereqs). When a single object # module is turned into a multi object module, $^ will contain header file # dependencies recorded in the .*.cmd file. -ifdef CONFIG_LTO_CLANG +ifneq ($(CONFIG_LTO_CLANG)$(CONFIG_X86_KERNEL_IBT),) quiet_cmd_link_multi-m =3D AR [M] $@ cmd_link_multi-m =3D \ $(cmd_update_lto_symversions); \ diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index 79be57f..8bfc923 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -230,11 +230,11 @@ dtc_cpp_flags =3D -Wp,-MMD,$(depfile).pre.tmp -nostd= inc \ $(addprefix -I,$(DTC_INCLUDE)) \ -undef -D__DTS__ =20 -ifeq ($(CONFIG_LTO_CLANG),y) +ifneq ($(CONFIG_LTO_CLANG)$(CONFIG_X86_KERNEL_IBT),) # With CONFIG_LTO_CLANG, .o files in modules might be LLVM bitcode, so we # need to run LTO to compile them into native code (.lto.o) before further # processing. -mod-prelink-ext :=3D .lto +mod-prelink-ext :=3D .prelink endif =20 # Useful for describing the dependency of composite objects diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 6bfa332..09c3ab0 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -1989,9 +1989,9 @@ static char *remove_dot(char *s) if (m && (s[n + m] =3D=3D '.' || s[n + m] =3D=3D 0)) s[n] =3D 0; =20 - /* strip trailing .lto */ - if (strends(s, ".lto")) - s[strlen(s) - 4] =3D '\0'; + /* strip trailing .prelink */ + if (strends(s, ".prelink")) + s[strlen(s) - 8] =3D '\0'; } return s; } @@ -2015,9 +2015,9 @@ static void read_symbols(const char *modname) /* strip trailing .o */ tmp =3D NOFAIL(strdup(modname)); tmp[strlen(tmp) - 2] =3D '\0'; - /* strip trailing .lto */ - if (strends(tmp, ".lto")) - tmp[strlen(tmp) - 4] =3D '\0'; + /* strip trailing .prelink */ + if (strends(tmp, ".prelink")) + tmp[strlen(tmp) - 8] =3D '\0'; mod =3D new_module(tmp); free(tmp); }