From patchwork Mon Nov 14 11:43:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Slaby X-Patchwork-Id: 13042179 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 B154FC4332F for ; Mon, 14 Nov 2022 11:46:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236818AbiKNLqr (ORCPT ); Mon, 14 Nov 2022 06:46:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236779AbiKNLqH (ORCPT ); Mon, 14 Nov 2022 06:46:07 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F110523392; Mon, 14 Nov 2022 03:45:05 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8B9556106E; Mon, 14 Nov 2022 11:45:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 31EBBC433D6; Mon, 14 Nov 2022 11:45:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668426305; bh=cDaL2fr4ds1QFPZqTUk+kKTp3g2JDWGKaf0MMC6B8X0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=axz9z9rmp0DF1yNW2Noyvv4Ams50QT88IMMv7mytIv0BAoxo3ZprIJOr3jD2qNkrH hLr2L8iLnT9EqQrGmrVi+ERKM2z7/wk2jkUtqr2gQggsZfBszIRDNeWhDZG0m/xMPI g6leDXiyanYdsK11/1nbv9vxpama8/y0C7iVa5DVRx60ByfqeVTVBFztfRXZJdEy1G vlLWZCVQlFb/1TNrxcaswglRAzWwC4BgmYFyM8qtqLiXtG+5cBribG3CViVtlQEqZE ZksYWKtDotJ7HbrcxfDMelz0cNtFB3Cf4kpoaaIORBy+haBnZdaPlB7QSUCHuNlwsq 7N3JHoXdEPk5Q== From: "Jiri Slaby (SUSE)" To: linux-kernel@vger.kernel.org Cc: Andi Kleen , Masahiro Yamada , Michal Marek , Nick Desaulniers , linux-kbuild@vger.kernel.org, Martin Liska , Jiri Slaby Subject: [PATCH 28/46] scripts, lto: re-add gcc-ld Date: Mon, 14 Nov 2022 12:43:26 +0100 Message-Id: <20221114114344.18650-29-jirislaby@kernel.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221114114344.18650-1-jirislaby@kernel.org> References: <20221114114344.18650-1-jirislaby@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org From: Andi Kleen The primary goal of the script is to mangle linker command line arguments into something which gcc understands. Such as converting "-z now" into "-Wl,-z,now". The script was removed by commit 86879fd277e8 (scripts: remove obsolete gcc-ld script) as there was no use in the kernel. It had been added long time ago to support exactly these lto patches, so we need to add it back now. Since the removed version, it is improved a bit: * some missing linker and gcc command line arguments were added, and * when V=1 is specified, it prints the final gcc command line [js] rebase + commit message massage Cc: Masahiro Yamada Cc: Michal Marek Cc: Nick Desaulniers Cc: linux-kbuild@vger.kernel.org Signed-off-by: Andi Kleen Signed-off-by: Martin Liska Signed-off-by: Jiri Slaby --- scripts/gcc-ld | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 scripts/gcc-ld diff --git a/scripts/gcc-ld b/scripts/gcc-ld new file mode 100755 index 000000000000..13e85ece8d04 --- /dev/null +++ b/scripts/gcc-ld @@ -0,0 +1,40 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 +# run gcc with ld options +# used as a wrapper to execute link time optimizations +# yes virginia, this is not pretty + +ARGS="-nostdlib" + +for j in "$@" ; do + if [ "$j" = -v ] ; then + exec `$CC -print-prog-name=ld` -v + fi +done + +while [ "$1" != "" ] ; do + case "$1" in + -save-temps*|-m32|-m64) N="$1" ;; + -r) N="$1" ;; + -flinker-output*) N="$1" ;; + -[Wg]*) N="$1" ;; + -[olv]|-[Ofd]*|-nostdlib) N="$1" ;; + --end-group|--start-group|--whole-archive|--no-whole-archive|\ +--no-undefined|--hash-style*|--build-id*|--eh-frame-hdr|-Bsymbolic) + N="-Wl,$1" ;; + -[RTFGhIezcbyYu]*|\ +--script|--defsym|-init|-Map|--oformat|-rpath|\ +-rpath-link|--sort-section|--section-start|-Tbss|-Tdata|-Ttext|-soname|\ +--version-script|--dynamic-list|--version-exports-symbol|--wrap|-m|-z) + A="$1" ; shift ; N="-Wl,$A,$1" ;; + -[m]*) N="$1" ;; + -*) N="-Wl,$1" ;; + *) N="$1" ;; + esac + ARGS="$ARGS $N" + shift +done + +[ -n "$V" ] && echo >&2 $CC $ARGS + +exec $CC $ARGS From patchwork Mon Nov 14 11:43:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Slaby X-Patchwork-Id: 13042180 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 D24F7C4332F for ; Mon, 14 Nov 2022 11:46:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236748AbiKNLqv (ORCPT ); Mon, 14 Nov 2022 06:46:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236602AbiKNLqO (ORCPT ); Mon, 14 Nov 2022 06:46:14 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98790233BD; Mon, 14 Nov 2022 03:45:08 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id CCE9C61087; Mon, 14 Nov 2022 11:45:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 731AFC433D7; Mon, 14 Nov 2022 11:45:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668426307; bh=rax9Sk0B97anfjE870tVIfylOGOMvkqIjn17Y4+e0zw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ig5CDdXql15Gd4fTP+IlvjoNHuzHJ1zDAzs4QbD1+lazKnKCGuM6a3Uft+OMx66Xt 8U15M+SeRg6aVyP0214WZo5NmzOwzkrpzlLdbt6OLr1347K9G60URIFBT2/NARAjcD pycuPOnQGZmhBS/w2xZXJquS8UwgI3vi0Zc1ItKB2gra8PWZ/qPLncpVkxiczC9CJr j9/JIbQMIt/EEdfFRm9cP8A+6YX4oU5qO6oEBnbkU3+FZQEE4MrOHFVE0I5u0Pxf+N E9RFsrchKpk8KrzeUB7FDEDS2psNEjuwE451izXf/2+67zbtlMJtUy5FXJyWrNSZEt O9bKWwNdvdvuw== From: "Jiri Slaby (SUSE)" To: linux-kernel@vger.kernel.org Cc: Andi Kleen , Masahiro Yamada , Michal Marek , Nick Desaulniers , linux-kbuild@vger.kernel.org, Martin Liska , Jiri Slaby Subject: [PATCH 29/46] scripts, lto: use CONFIG_LTO for many LTO specific actions Date: Mon, 14 Nov 2022 12:43:27 +0100 Message-Id: <20221114114344.18650-30-jirislaby@kernel.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221114114344.18650-1-jirislaby@kernel.org> References: <20221114114344.18650-1-jirislaby@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org From: Andi Kleen The clang LTO and the gcc LTO share some changes in Makefiles and build scripts. Change the common ones to use CONFIG_LTO instead of CONFIG_LTO_CLANG so that they can be used by gcc too. [js] fix scripts/link-vmlinux.sh too Cc: Masahiro Yamada Cc: Michal Marek Cc: Nick Desaulniers Cc: linux-kbuild@vger.kernel.org Signed-off-by: Andi Kleen Signed-off-by: Martin Liska Signed-off-by: Jiri Slaby --- Makefile | 2 +- include/asm-generic/vmlinux.lds.h | 2 +- kernel/kallsyms.c | 2 +- scripts/Makefile.build | 2 +- scripts/Makefile.lib | 2 +- scripts/link-vmlinux.sh | 2 +- scripts/module.lds.S | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 58cd4f5e1c3a..0b723c903819 100644 --- a/Makefile +++ b/Makefile @@ -992,7 +992,7 @@ endif endif endif -ifdef CONFIG_LTO +ifdef CONFIG_LTO_CLANG KBUILD_CFLAGS += -fno-lto $(CC_FLAGS_LTO) KBUILD_AFLAGS += -fno-lto export CC_FLAGS_LTO diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h index 3dc5824141cd..5e2179dd41d5 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -96,7 +96,7 @@ * RODATA_MAIN is not used because existing code already defines .rodata.x * sections to be brought in with rodata. */ -#if defined(CONFIG_LD_DEAD_CODE_DATA_ELIMINATION) || defined(CONFIG_LTO_CLANG) +#if defined(CONFIG_LD_DEAD_CODE_DATA_ELIMINATION) || defined(CONFIG_LTO) #define TEXT_MAIN .text .text.[0-9a-zA-Z_]* #define DATA_MAIN .data .data.[0-9a-zA-Z_]* .data..L* .data..compoundliteral* .data.$__unnamed_* .data.$L* #define SDATA_MAIN .sdata .sdata.[0-9a-zA-Z_]* diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c index 60c20f301a6b..1d4557ae090f 100644 --- a/kernel/kallsyms.c +++ b/kernel/kallsyms.c @@ -167,7 +167,7 @@ static bool cleanup_symbol_name(char *s) { char *res; - if (!IS_ENABLED(CONFIG_LTO_CLANG)) + if (!IS_ENABLED(CONFIG_LTO)) return false; /* diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 564a20ce2667..0a28e3884efe 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -153,7 +153,7 @@ is-single-obj-m = $(and $(part-of-module),$(filter $@, $(obj-m)),y) # When a module consists of a single object, there is no reason to keep LLVM IR. # Make $(LD) covert LLVM IR to ELF here. -ifdef CONFIG_LTO_CLANG +ifdef CONFIG_LTO cmd_ld_single_m = $(if $(is-single-obj-m), ; $(LD) $(ld_flags) -r -o $(tmp-target) $@; mv $(tmp-target) $@) endif diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index 3aa384cec76b..ac918fd84d96 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -269,7 +269,7 @@ objtool-args = $(objtool-args-y) \ $(if $(delay-objtool), --link) \ $(if $(part-of-module), --module) -delay-objtool := $(or $(CONFIG_LTO_CLANG),$(CONFIG_X86_KERNEL_IBT)) +delay-objtool := $(or $(CONFIG_LTO),$(CONFIG_X86_KERNEL_IBT)) cmd_objtool = $(if $(objtool-enabled), ; $(objtool) $(objtool-args) $@) cmd_gen_objtooldep = $(if $(objtool-enabled), { echo ; echo '$@: $$(wildcard $(objtool))' ; } >> $(dot-target).cmd) diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh index 918470d768e9..652f33be9549 100755 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -60,7 +60,7 @@ vmlinux_link() # skip output file argument shift - if is_enabled CONFIG_LTO_CLANG || is_enabled CONFIG_X86_KERNEL_IBT; then + if is_enabled CONFIG_LTO || is_enabled CONFIG_X86_KERNEL_IBT; then # Use vmlinux.o instead of performing the slow LTO link again. objs=vmlinux.o libs= diff --git a/scripts/module.lds.S b/scripts/module.lds.S index da4bddd26171..b36b0527b0a8 100644 --- a/scripts/module.lds.S +++ b/scripts/module.lds.S @@ -27,7 +27,7 @@ SECTIONS { __kcfi_traps : { KEEP(*(.kcfi_traps)) } #endif -#ifdef CONFIG_LTO_CLANG +#ifdef CONFIG_LTO /* * With CONFIG_LTO_CLANG, LLD always enables -fdata-sections and * -ffunction-sections, which increases the size of the final module. From patchwork Mon Nov 14 11:43:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Slaby X-Patchwork-Id: 13042181 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 06469C433FE for ; Mon, 14 Nov 2022 11:47:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235697AbiKNLrb (ORCPT ); Mon, 14 Nov 2022 06:47:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236796AbiKNLqe (ORCPT ); Mon, 14 Nov 2022 06:46:34 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7BFC423EAC; Mon, 14 Nov 2022 03:45:11 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0562F6108D; Mon, 14 Nov 2022 11:45:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B6DE6C433B5; Mon, 14 Nov 2022 11:45:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668426310; bh=U88ByfantOuqzsZrA5yzPeb/FIn96646m0chM2LVf7Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nCVxoEI+5LJxBX9rN6Wc4juqda9V3epctKjzV0CwK6X+3ichJiOIK60Tu2gpnW8ph wOAUVqcC1DzgiZSNap1P1bfMgvh5IKkk+HrZG9yDldZkvc9ZMIneUY9LvIXSzW7SA5 pod26Nz6sLlRYYh/pyp7q21H7bN1si2MZEeOm1mEDfYOIBK/nqolX9f/QstqZNR4w/ /91dtHhwKmPvVUoQ3QcthWqBXqzarLnpckf5WCFtmsmZY2KAaNgA76W9ARF8ZLQ1bP E7rTL9Z7ENOYAFF9VKlIIMG/lntAB6YMs9mPj4biyKADkCzOVnfGzr5x8wL5qRed3+ Qhg0VmAt/jt9A== From: "Jiri Slaby (SUSE)" To: linux-kernel@vger.kernel.org Cc: Andi Kleen , Masahiro Yamada , Michal Marek , Nick Desaulniers , linux-kbuild@vger.kernel.org, Richard Biener , Jan Hubicka , "H . J . Lu" , Don Zickus , Martin Liska , Bagas Sanjaya , Jiri Slaby Subject: [PATCH 30/46] Kbuild, lto: Add Link Time Optimization support Date: Mon, 14 Nov 2022 12:43:28 +0100 Message-Id: <20221114114344.18650-31-jirislaby@kernel.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221114114344.18650-1-jirislaby@kernel.org> References: <20221114114344.18650-1-jirislaby@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org From: Andi Kleen This patch adds gcc LTO support. It leverages some of the existing support for clang LTO. With LTO, gcc will do whole program optimizations for the whole kernel and each module. This increases compile time, but can generate faster and smaller code and allows the compiler to do global checking. For example the compiler can complain now about type mismatches for symbols between different files. LTO allows gcc to inline functions between different files and do various other optimization across the whole binary. The LTO patches have been used for many years by various users, mostly to make their kernel smaller. The original versions date back to 2012. This version has a lot of outdated cruft dropped and doesn't need any special tool chain (except for new enough) anymore. This adds the basic Kbuild plumbing for LTO: * Add a new LDFINAL variable that controls the final link for vmlinux or module. In this case we call gcc-ld instead of ld, to run the LTO step. * Add Makefile support to enable LTO For more information see Documentation/kbuild/lto-build.rst Thanks to H.J. Lu, Joe Mario, Honza Hubicka, Richard Biener, Don Zickus, Changlong Xie, Gleb Schukin, Martin Liska, various github contributors, who helped with this project (and probably some more who I forgot, sorry). [js] pass -flto only once (the one with jobserver) [ml] "-m: command not found" and whitespace fix [bs] fixed Documentation issues: * blank line padding before single requirement list * use bullet list for FAQ * use bullet lists for external link references list * add LTO documentation to toc index Cc: Masahiro Yamada Cc: Michal Marek Cc: Nick Desaulniers Cc: linux-kbuild@vger.kernel.org Cc: Richard Biener Cc: Jan Hubicka Cc: H.J. Lu Cc: Don Zickus Signed-off-by: Andi Kleen Signed-off-by: Martin Liska Signed-off-by: Bagas Sanjaya Signed-off-by: Jiri Slaby --- Documentation/kbuild/index.rst | 2 + Documentation/kbuild/lto-build.rst | 76 ++++++++++++++++++++++++++++++ Makefile | 4 +- arch/Kconfig | 52 ++++++++++++++++++++ scripts/Makefile.build | 9 ++-- scripts/Makefile.lto | 43 +++++++++++++++++ scripts/Makefile.modfinal | 2 +- scripts/Makefile.vmlinux | 3 +- scripts/Makefile.vmlinux_o | 4 +- scripts/link-vmlinux.sh | 7 +-- 10 files changed, 190 insertions(+), 12 deletions(-) create mode 100644 Documentation/kbuild/lto-build.rst create mode 100644 scripts/Makefile.lto diff --git a/Documentation/kbuild/index.rst b/Documentation/kbuild/index.rst index cee2f99f734b..1937eee7c437 100644 --- a/Documentation/kbuild/index.rst +++ b/Documentation/kbuild/index.rst @@ -22,6 +22,8 @@ Kernel Build System gcc-plugins llvm + lto-build + .. only:: subproject and html Indices diff --git a/Documentation/kbuild/lto-build.rst b/Documentation/kbuild/lto-build.rst new file mode 100644 index 000000000000..3fb17342e72f --- /dev/null +++ b/Documentation/kbuild/lto-build.rst @@ -0,0 +1,76 @@ +===================================================== +gcc link time optimization (LTO) for the Linux kernel +===================================================== + +Link Time Optimization allows the compiler to optimize the complete program +instead of just each file. + +The compiler can inline functions between files and do various other global +optimizations, like specializing functions for common parameters, +determing when global variables are clobbered, making functions pure/const, +propagating constants globally, removing unneeded data and others. + +It will also drop unused functions which can make the kernel +image smaller in some circumstances, in particular for small kernel +configurations. + +For small monolithic kernels it can throw away unused code very effectively +(especially when modules are disabled) and usually shrinks +the code size. + +Build time and memory consumption at build time will increase, depending +on the size of the largest binary. Modular kernels are less affected. +With LTO incremental builds are less incremental, as always the whole +binary needs to be re-optimized (but not re-parsed) + +Oopses can be somewhat more difficult to read, due to the more aggressive +inlining: it helps to use scripts/faddr2line. + +It is currently incompatible with live patching. + +Normal "reasonable" builds work with less than 4GB of RAM, but very large +configurations like allyesconfig typically need more memory. The actual +memory needed depends on the available memory (gcc sizes its garbage +collector pools based on that or on the ulimit -m limits) and +the compiler version. + +Requirements: +------------- + +- Enough memory: 4GB for a standard build, more for allyesconfig + The peak memory usage happens single threaded (when lto-wpa merges types), + so dialing back -j options will not help much. + +A 32bit hosted compiler is unlikely to work due to the memory requirements. +You can however build a kernel targeted at 32bit on a 64bit host. + +FAQs: +----- + +* I get a section type attribute conflict + + Usually because of someone doing const __initdata (should be + const __initconst) or const __read_mostly (should be just const). Check + both symbols reported by gcc. + +References: +----------- + +* Presentation on Kernel LTO + (note, performance numbers/details totally outdated.) + + http://halobates.de/kernel-lto.pdf + +* Generic gcc LTO: + + * http://www.ucw.cz/~hubicka/slides/labs2013.pdf + * http://www.hipeac.net/system/files/barcelona.pdf + +* Somewhat outdated too (from GCC site): + + * http://gcc.gnu.org/projects/lto/lto.pdf + * http://gcc.gnu.org/projects/lto/whopr.pdf + +Happy Link-Time-Optimizing! + +Andi Kleen diff --git a/Makefile b/Makefile index 0b723c903819..d0dfb5ca2b21 100644 --- a/Makefile +++ b/Makefile @@ -482,6 +482,7 @@ KBUILD_HOSTLDLIBS := $(HOST_LFS_LIBS) $(HOSTLDLIBS) # Make variables (CC, etc...) CPP = $(CC) -E +LDFINAL = $(LD) ifneq ($(LLVM),) CC = $(LLVM_PREFIX)clang$(LLVM_SUFFIX) LD = $(LLVM_PREFIX)ld.lld$(LLVM_SUFFIX) @@ -604,7 +605,7 @@ export RUSTC RUSTDOC RUSTFMT RUSTC_OR_CLIPPY_QUIET RUSTC_OR_CLIPPY BINDGEN CARGO export HOSTRUSTC KBUILD_HOSTRUSTFLAGS export CPP AR NM STRIP OBJCOPY OBJDUMP READELF PAHOLE RESOLVE_BTFIDS LEX YACC AWK INSTALLKERNEL export PERL PYTHON3 CHECK CHECKFLAGS MAKE UTS_MACHINE HOSTCXX -export KGZIP KBZIP2 KLZOP LZMA LZ4 XZ ZSTD +export KGZIP KBZIP2 KLZOP LZMA LZ4 XZ ZSTD LDFINAL export KBUILD_HOSTCXXFLAGS KBUILD_HOSTLDFLAGS KBUILD_HOSTLDLIBS LDFLAGS_MODULE export KBUILD_USERCFLAGS KBUILD_USERLDFLAGS @@ -1085,6 +1086,7 @@ include-$(CONFIG_KMSAN) += scripts/Makefile.kmsan include-$(CONFIG_UBSAN) += scripts/Makefile.ubsan include-$(CONFIG_KCOV) += scripts/Makefile.kcov include-$(CONFIG_RANDSTRUCT) += scripts/Makefile.randstruct +include-$(CONFIG_LTO_GCC) += scripts/Makefile.lto include-$(CONFIG_GCC_PLUGINS) += scripts/Makefile.gcc-plugins include $(addprefix $(srctree)/, $(include-y)) diff --git a/arch/Kconfig b/arch/Kconfig index 8f138e580d1a..ad52c8fddfb4 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -689,6 +689,21 @@ config HAS_LTO_CLANG The compiler and Kconfig options support building with Clang's LTO. +config ARCH_SUPPORTS_LTO_GCC + bool + +# Some ar versions leak file descriptors when using the LTO +# plugin and cause strange errors when ulimit -n is too low. +# Pick an arbitrary threshold, which should be enough for most +# kernel configs. This was a regression that is only +# in some transient binutils version, so either older or +# new enough is ok. +# This might not be the exact range with this bug. +config BAD_AR + depends on LD_VERSION = 23000 + depends on $(shell,ulimit -n) < 4000 + def_bool y + choice prompt "Link Time Optimization (LTO)" default LTO_NONE @@ -736,8 +751,45 @@ config LTO_CLANG_THIN https://clang.llvm.org/docs/ThinLTO.html If unsure, say Y. + +config LTO_GCC + bool "gcc LTO" + depends on ARCH_SUPPORTS_LTO_GCC && CC_IS_GCC + depends on GCC_VERSION >= 100300 + depends on LD_VERSION >= 22700 + depends on !BAD_AR + select LTO + help + Enable whole program (link time) optimizations (LTO) for the whole + kernel and each module. This usually increases compile time, + especially for incremential builds, but tends to generate better code + as well as some global checks. + + It allows the compiler to inline functions between different files + and do other global optimization, like propagating constants between + functions, determine side effects of functions, avoid unnecessary + register saving around functions, or optimize unused function + arguments. It also allows the compiler to drop unused functions. + + With this option the compiler will also do some global checking over + different source files. + + This requires a gcc 10.3 or later compiler and binutils >= 2.27. + + On larger non modular configurations this may need more than 4GB of + RAM for the link phase, as well as a 64bit host compiler. + + For more information see Documentation/kbuild/lto-build.rst endchoice +config LTO_CP_CLONE + bool "Allow aggressive cloning for function specialization" + depends on LTO_GCC + help + Allow the compiler to clone and specialize functions for specific + arguments when it determines these arguments are commonly + called. Experimential. Will increase text size. + config ARCH_SUPPORTS_CFI_CLANG bool help diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 0a28e3884efe..9b522c9efcb6 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -154,7 +154,7 @@ is-single-obj-m = $(and $(part-of-module),$(filter $@, $(obj-m)),y) # When a module consists of a single object, there is no reason to keep LLVM IR. # Make $(LD) covert LLVM IR to ELF here. ifdef CONFIG_LTO -cmd_ld_single_m = $(if $(is-single-obj-m), ; $(LD) $(ld_flags) -r -o $(tmp-target) $@; mv $(tmp-target) $@) +cmd_ld_single_m = $(if $(is-single-obj-m), ; $(LDFINAL) $(ld_flags) -r -o $(tmp-target) $@; mv $(tmp-target) $@) endif quiet_cmd_cc_o_c = CC $(quiet_modtag) $@ @@ -265,7 +265,8 @@ $(obj)/%.usyms: $(obj)/%.o FORCE $(call if_changed,undefined_syms) quiet_cmd_cc_lst_c = MKLST $@ - cmd_cc_lst_c = $(CC) $(c_flags) -g -c -o $*.o $< && \ + cmd_cc_lst_c = $(if $(CONFIG_LTO),$(warning Listing in LTO mode does not match final binary)) \ + $(CC) $(c_flags) -g -c -o $*.o $< && \ $(CONFIG_SHELL) $(srctree)/scripts/makelst $*.o \ System.map $(OBJDUMP) > $@ @@ -446,8 +447,8 @@ $(obj)/modules.order: $(obj-m) FORCE $(obj)/lib.a: $(lib-y) FORCE $(call if_changed,ar) -quiet_cmd_ld_multi_m = LD [M] $@ - cmd_ld_multi_m = $(LD) $(ld_flags) -r -o $@ @$(patsubst %.o,%.mod,$@) $(cmd_objtool) +quiet_cmd_ld_multi_m = LDFINAL [M] $@ + cmd_ld_multi_m = $(LDFINAL) $(ld_flags) -r -o $@ @$(patsubst %.o,%.mod,$@) $(cmd_objtool) define rule_ld_multi_m $(call cmd_and_savecmd,ld_multi_m) diff --git a/scripts/Makefile.lto b/scripts/Makefile.lto new file mode 100644 index 000000000000..33ac0da2bb47 --- /dev/null +++ b/scripts/Makefile.lto @@ -0,0 +1,43 @@ +# +# Support for gcc link time optimization +# + +DISABLE_LTO_GCC := +export DISABLE_LTO_GCC + +ifdef CONFIG_LTO_GCC + CC_FLAGS_LTO_GCC := -flto + DISABLE_LTO_GCC := -fno-lto + + KBUILD_CFLAGS += ${CC_FLAGS_LTO_GCC} + + CC_FLAGS_LTO := -flto + export CC_FLAGS_LTO + + lto-flags-y := -flinker-output=nolto-rel -flto=jobserver + lto-flags-y += -fwhole-program + + lto-flags-$(CONFIG_LTO_CP_CLONE) += -fipa-cp-clone + + # allow extra flags from command line + lto-flags-y += ${LTO_EXTRA_CFLAGS} + + # For LTO we need to use gcc to do the linking, not ld + # directly. Use a wrapper to convert the ld command line + # to gcc + LDFINAL := ${CONFIG_SHELL} ${srctree}/scripts/gcc-ld \ + ${lto-flags-y} + + # LTO gcc creates a lot of files in TMPDIR, and with /tmp as tmpfs + # it's easy to drive the machine OOM. Use the object directory + # instead for temporaries. + # This has the drawback that there might be some junk more visible + # after interrupted compilations, but you would have that junk + # there anyways in /tmp. + TMPDIR ?= $(objtree) + export TMPDIR + + # use plugin aware tools + AR = $(CROSS_COMPILE)gcc-ar + NM = $(CROSS_COMPILE)gcc-nm +endif # CONFIG_LTO_GCC diff --git a/scripts/Makefile.modfinal b/scripts/Makefile.modfinal index 25bedd83644b..c52536c91c8c 100644 --- a/scripts/Makefile.modfinal +++ b/scripts/Makefile.modfinal @@ -32,7 +32,7 @@ ARCH_POSTLINK := $(wildcard $(srctree)/arch/$(SRCARCH)/Makefile.postlink) quiet_cmd_ld_ko_o = LD [M] $@ cmd_ld_ko_o += \ - $(LD) -r $(KBUILD_LDFLAGS) \ + $(LDFINAL) -r $(KBUILD_LDFLAGS) \ $(KBUILD_LDFLAGS_MODULE) $(LDFLAGS_MODULE) \ -T scripts/module.lds -o $@ $(filter %.o, $^); \ $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true) diff --git a/scripts/Makefile.vmlinux b/scripts/Makefile.vmlinux index 49946cb96844..8871e55f881b 100644 --- a/scripts/Makefile.vmlinux +++ b/scripts/Makefile.vmlinux @@ -26,7 +26,8 @@ ARCH_POSTLINK := $(wildcard $(srctree)/arch/$(SRCARCH)/Makefile.postlink) # Final link of vmlinux with optional arch pass after final link cmd_link_vmlinux = \ - $< "$(LD)" "$(KBUILD_LDFLAGS)" "$(LDFLAGS_vmlinux)"; \ + $< "$(LD)" "$(LDFINAL)" "$(KBUILD_LDFLAGS)" \ + "$(LDFLAGS_vmlinux)"; \ $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true) targets += vmlinux diff --git a/scripts/Makefile.vmlinux_o b/scripts/Makefile.vmlinux_o index 1c86895cfcf8..1f646b16aa70 100644 --- a/scripts/Makefile.vmlinux_o +++ b/scripts/Makefile.vmlinux_o @@ -44,9 +44,9 @@ objtool-args = $(vmlinux-objtool-args-y) --link # Link of vmlinux.o used for section mismatch analysis # --------------------------------------------------------------------------- -quiet_cmd_ld_vmlinux.o = LD $@ +quiet_cmd_ld_vmlinux.o = LDFINAL $@ cmd_ld_vmlinux.o = \ - $(LD) ${KBUILD_LDFLAGS} -r -o $@ \ + $(LDFINAL) ${KBUILD_LDFLAGS} -r -o $@ \ $(addprefix -T , $(initcalls-lds)) \ --whole-archive vmlinux.a --no-whole-archive \ --start-group $(KBUILD_VMLINUX_LIBS) --end-group \ diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh index 652f33be9549..c89258bcf818 100755 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -29,8 +29,9 @@ set -e LD="$1" -KBUILD_LDFLAGS="$2" -LDFLAGS_vmlinux="$3" +LDFINAL="$2" +KBUILD_LDFLAGS="$3" +LDFLAGS_vmlinux="$4" is_enabled() { grep -q "^$1=y" include/config/auto.conf @@ -82,7 +83,7 @@ vmlinux_link() ldlibs="-lutil -lrt -lpthread" else wl= - ld="${LD}" + ld="${LDFINAL}" ldflags="${KBUILD_LDFLAGS} ${LDFLAGS_vmlinux}" ldlibs= fi From patchwork Mon Nov 14 11:43:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Slaby X-Patchwork-Id: 13042182 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 7D013C433FE for ; Mon, 14 Nov 2022 11:48:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236699AbiKNLsB (ORCPT ); Mon, 14 Nov 2022 06:48:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236874AbiKNLrM (ORCPT ); Mon, 14 Nov 2022 06:47:12 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9488E25EBD; Mon, 14 Nov 2022 03:45:23 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 45B37B80E26; Mon, 14 Nov 2022 11:45:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EF98FC433C1; Mon, 14 Nov 2022 11:45:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668426320; bh=DJF+imgy2HAxwvL4BHvytn2wHCCnLG9Lu7S4hynUjxw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F4KLVe8QD97rdiLvx0ybBKluX02uyPznww0DIzficAchO+9g5a627u9P/z0nD682k OtGx4Ppr4+qjnsK0CkMv+SJsF0CikUkpWdPEu+cbAUS9yjVgtS+Us8ZZVPC4LU1JPv b/N4tv8tXiXLdB6DTEZ4/BkwygPZqexBuh20hhiOgsgGptRq0/GoyA0HFXDr5URhsZ DxACqxfyXs4loradezI38i/S0zOEhS/+Q/nDm3n/ltR8xMwKH8R9r1WwM1F3XKjqw/ Kb3EVH4XNqZyglviCHlikYMRMFV+K+T9v2iDSBhFPuODIOEC2c9zsk8bnkcJfhc1iZ LEZf0p+BLa2nA== From: "Jiri Slaby (SUSE)" To: linux-kernel@vger.kernel.org Cc: Andi Kleen , Masahiro Yamada , Michal Marek , Nick Desaulniers , linux-kbuild@vger.kernel.org, Andi Kleen , Martin Liska , Jiri Slaby Subject: [PATCH 34/46] scripts, lto: disable gcc LTO for some mod sources Date: Mon, 14 Nov 2022 12:43:32 +0100 Message-Id: <20221114114344.18650-35-jirislaby@kernel.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221114114344.18650-1-jirislaby@kernel.org> References: <20221114114344.18650-1-jirislaby@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org From: Andi Kleen The mod tools scan assembler (devicetable-offsets.s) to generate symbols into devicetable-offsets.h and binary (empty.o) to find out ELF setup. That doesn't work with LTO. So just disable LTO for empty.o and devicetable-offsets.s. Cc: Masahiro Yamada Cc: Michal Marek Cc: Nick Desaulniers Cc: linux-kbuild@vger.kernel.org Signed-off-by: Andi Kleen Signed-off-by: Martin Liska Signed-off-by: Jiri Slaby --- scripts/mod/Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/mod/Makefile b/scripts/mod/Makefile index c9e38ad937fd..aa3465d6bc4a 100644 --- a/scripts/mod/Makefile +++ b/scripts/mod/Makefile @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 OBJECT_FILES_NON_STANDARD := y CFLAGS_REMOVE_empty.o += $(CC_FLAGS_LTO) +CFLAGS_REMOVE_empty.o += $(CC_FLAGS_LTO_GCC) hostprogs-always-y += modpost mk_elfconfig always-y += empty.o @@ -9,6 +10,8 @@ modpost-objs := modpost.o file2alias.o sumversion.o devicetable-offsets-file := devicetable-offsets.h +$(obj)/devicetable-offsets.s: KBUILD_CFLAGS += $(DISABLE_LTO_GCC) + $(obj)/$(devicetable-offsets-file): $(obj)/devicetable-offsets.s FORCE $(call filechk,offsets,__DEVICETABLE_OFFSETS_H__) From patchwork Mon Nov 14 11:43:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Slaby X-Patchwork-Id: 13042183 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 69A23C43217 for ; Mon, 14 Nov 2022 11:48:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236828AbiKNLsI (ORCPT ); Mon, 14 Nov 2022 06:48:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236931AbiKNLr3 (ORCPT ); Mon, 14 Nov 2022 06:47:29 -0500 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5010222508; Mon, 14 Nov 2022 03:45:28 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id DFF2ACE0F52; Mon, 14 Nov 2022 11:45:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 66E11C433D7; Mon, 14 Nov 2022 11:45:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668426323; bh=2VZ4ODzq0c+qrTqaRhf/GBj3Hij1v5FmA5K2QGdY/7A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WhEo3a5Lx3UZZADPhb5Wp70Y2vIT2YeqX9rt3iHUK9eS+k/5sSbR2h9BZZZHUn7OB t3cI5HGlUnqznWOwYP2wjqyreX+9nSEH+r97DCMAmR1B5BZZnM02A97aSEpHsDmnGV Q6iV21VOlcdoSFRKninhJTHK3XUoCvEKM3s7HXBrOWaCLmbDxs7EIB8U/yIKLMLd74 iUwYaDPgNw9YryLoADxfO/+sdnwJr69IK7wRzQsrU1h6X+1yMqSZG9CgBE0Uxv9NNM FNtdG/7I+sxoMD3Gk6bglBTDaKot5bWBlP5pfqsDQ48tN8Hyt83yGvoh4IeUp4VSxB tJO24okcYNl3w== From: "Jiri Slaby (SUSE)" To: linux-kernel@vger.kernel.org Cc: Andi Kleen , Masahiro Yamada , Michal Marek , Nick Desaulniers , linux-kbuild@vger.kernel.org, Martin Liska , Jiri Slaby Subject: [PATCH 35/46] Kbuild, lto: disable gcc LTO for bounds+asm-offsets Date: Mon, 14 Nov 2022 12:43:33 +0100 Message-Id: <20221114114344.18650-36-jirislaby@kernel.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221114114344.18650-1-jirislaby@kernel.org> References: <20221114114344.18650-1-jirislaby@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org From: Andi Kleen Disable LTO when generating the bounds+asm-offsets.s files which are scanned for C constants. With a LTO build, the file would contain the gcc IR in assembler form, which breaks the scanning scripts. Cc: Masahiro Yamada Cc: Michal Marek Cc: Nick Desaulniers Cc: linux-kbuild@vger.kernel.org Signed-off-by: Andi Kleen Signed-off-by: Martin Liska Signed-off-by: Jiri Slaby --- Kbuild | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Kbuild b/Kbuild index 464b34a08f51..40744d76d416 100644 --- a/Kbuild +++ b/Kbuild @@ -11,6 +11,8 @@ bounds-file := include/generated/bounds.h targets := kernel/bounds.s +kernel/bounds.s: KBUILD_CFLAGS += $(DISABLE_LTO_GCC) + $(bounds-file): kernel/bounds.s FORCE $(call filechk,offsets,__LINUX_BOUNDS_H__) @@ -30,6 +32,7 @@ offsets-file := include/generated/asm-offsets.h targets += arch/$(SRCARCH)/kernel/asm-offsets.s arch/$(SRCARCH)/kernel/asm-offsets.s: $(timeconst-file) $(bounds-file) +arch/$(SRCARCH)/kernel/asm-offsets.s: KBUILD_CFLAGS += $(DISABLE_LTO_GCC) $(offsets-file): arch/$(SRCARCH)/kernel/asm-offsets.s FORCE $(call filechk,offsets,__ASM_OFFSETS_H__) From patchwork Mon Nov 14 11:43:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Slaby X-Patchwork-Id: 13042184 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 E1379C4332F for ; Mon, 14 Nov 2022 11:48:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236247AbiKNLsL (ORCPT ); Mon, 14 Nov 2022 06:48:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236947AbiKNLra (ORCPT ); Mon, 14 Nov 2022 06:47:30 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07582222B4; Mon, 14 Nov 2022 03:45:30 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 9A2BC61093; Mon, 14 Nov 2022 11:45:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3DC2FC433B5; Mon, 14 Nov 2022 11:45:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668426329; bh=VHTSznvRU1NJt50Gn5cdfooru5h/hvP+AUl+sJEGPhU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vH2xVVq9a7oMkBu897W0gAjD0uxcCuvGq364us9j38XwBhoYpK8lFuUcFpiWDuxut Rsu0/3S/RibVjT4IyA5Ub6bRkMIFahMLJwEj0f0edsEqkwxelhgus+v7RrQCCfLaZl yen5wyyk4N+ExrJ4A27S61XQL3Gi4R11PvTXF6VSm+z9OG0ugUmGYAZ2tYiI+92bq8 VksRgFcyAPLh+LqhvXh0lLNY46bkwx/tzkFbOSiak1O6hcRKUI5jXUvXny8xqmM125 4+VUObmU1Ll+vN5aesZZUCHC75DdkqIjkZ5a+I8GAGHUQ4gfH9jf9Ytd/AE+00JKhF BioFZgDVl2A4w== From: "Jiri Slaby (SUSE)" To: linux-kernel@vger.kernel.org Cc: Andi Kleen , Masahiro Yamada , Michal Marek , Nick Desaulniers , linux-kbuild@vger.kernel.org, Martin Liska , Jiri Slaby Subject: [PATCH 38/46] Kbuild, lto: don't include weak source file symbols in System.map Date: Mon, 14 Nov 2022 12:43:36 +0100 Message-Id: <20221114114344.18650-39-jirislaby@kernel.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221114114344.18650-1-jirislaby@kernel.org> References: <20221114114344.18650-1-jirislaby@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org From: Andi Kleen The gcc LTO build can generate some extra weak source code file name symbols on the second kallsyms link like: 0000000002fdf20a W head64.c.552cf5a6 This causes the "Inconsistent kallsyms data" error due to mismatches in the stage1 vs stage2 kallsyms link. Filter those out when generating the System.map. Cc: Masahiro Yamada Cc: Michal Marek Cc: Nick Desaulniers Cc: linux-kbuild@vger.kernel.org Signed-off-by: Andi Kleen Signed-off-by: Martin Liska Signed-off-by: Jiri Slaby --- scripts/mksysmap | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/mksysmap b/scripts/mksysmap index 16a08b8ef2f8..0f19a44ab136 100755 --- a/scripts/mksysmap +++ b/scripts/mksysmap @@ -34,6 +34,7 @@ # U - undefined global symbols # N - debugging symbols # w - local weak symbols +# W - weak symbols if they contain .c. # readprofile starts reading symbols when _stext is found, and # continue until it finds a symbol which is not either of 'T', 't', @@ -57,4 +58,5 @@ $NM -n $1 | grep -v \ -e ' __kstrtab_' \ -e ' __kstrtabns_' \ -e ' L0$' \ + -e ' W .*\.c\.' \ > $2 From patchwork Mon Nov 14 11:43:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Slaby X-Patchwork-Id: 13042185 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 68928C4332F for ; Mon, 14 Nov 2022 11:49:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236861AbiKNLtD (ORCPT ); Mon, 14 Nov 2022 06:49:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236625AbiKNLsY (ORCPT ); Mon, 14 Nov 2022 06:48:24 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28BF026577; Mon, 14 Nov 2022 03:45:43 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id BBC0361090; Mon, 14 Nov 2022 11:45:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 600C5C433C1; Mon, 14 Nov 2022 11:45:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668426342; bh=LDDWnbc0G82XezA7Wy98vToKYOH6Yv/7cEWA4wpWfUg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T7n13i8yGgCA6xfsV2rnP2Sn2LRC3XAIWA67SLNgXWXfb/KLM+FpdCj3dH7Y7MK0K ZFpnJPsia5D9y+j37HQE+wvcQCcPCYKPwpaIDH51AgBam6gDc6YnjzSOGzjhAQtPPZ BuV4mFX63jbFtrHwGzWF9uefmuk5uCwWd1AOjOwgT4jwgucnZo4DcyvqVMncXkX/Xi ww1vFk+Vd4oYdxIVzT2mt40FyMs70o9Y5xW55gLvnX0UaCWguDqZvgBrD98tHkTAfc qiUDD4bphIEkYCn0zqfMmUAy4ulNVj39L1XzJ3XsV5tmWEYlmcMH5X/1DnAGDPj/st KXI7Ob2C7SEtQ== From: "Jiri Slaby (SUSE)" To: linux-kernel@vger.kernel.org Cc: Andi Kleen , Masahiro Yamada , Michal Marek , Nick Desaulniers , linux-kbuild@vger.kernel.org, Martin Liska , Jiri Slaby Subject: [PATCH 43/46] scripts, lto: check C symbols for modversions Date: Mon, 14 Nov 2022 12:43:41 +0100 Message-Id: <20221114114344.18650-44-jirislaby@kernel.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221114114344.18650-1-jirislaby@kernel.org> References: <20221114114344.18650-1-jirislaby@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org From: Andi Kleen The gcc LTO nm doesn't output assembler symbols, which makes the symversions check fail because ksymtab is defined in assembler. Instead, check for a C symbol that is generated too. Cc: Masahiro Yamada Cc: Michal Marek Cc: Nick Desaulniers Cc: linux-kbuild@vger.kernel.org Signed-off-by: Andi Kleen Signed-off-by: Martin Liska Signed-off-by: Jiri Slaby --- scripts/Makefile.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 9b522c9efcb6..dafa8aeed9c2 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -173,7 +173,7 @@ ifdef CONFIG_MODVERSIONS # be compiled and linked to the kernel and/or modules. gen_symversions = \ - if $(NM) $@ 2>/dev/null | grep -q __ksymtab; then \ + if $(NM) $@ 2>/dev/null | grep -q __kstrtab; then \ $(call cmd_gensymtypes_$(1),$(KBUILD_SYMTYPES),$(@:.o=.symtypes)) \ >> $(dot-target).cmd; \ fi From patchwork Mon Nov 14 11:43:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Slaby X-Patchwork-Id: 13042186 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 9B134C433FE for ; Mon, 14 Nov 2022 11:49:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236797AbiKNLtO (ORCPT ); Mon, 14 Nov 2022 06:49:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236791AbiKNLso (ORCPT ); Mon, 14 Nov 2022 06:48:44 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05AA122BCB; Mon, 14 Nov 2022 03:45:47 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id B5E0FB80E6C; Mon, 14 Nov 2022 11:45:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9F72EC433D7; Mon, 14 Nov 2022 11:45:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668426344; bh=G+vw37jjgRCPwdc1JxfhASj9yJQMYjGyuVjD7aOBanE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eNTVR7Yx8lZnY0lqCRyi5JIDpYvNn2+K4wTQzUi5xXUVgDX06l8t75Ij7EeS8NQlZ o06lTGdDbvZHpYMT522j6EAJwd06l5nk1A7aNKe/tvWylCIsMdnE4KM+MTEalUJRzI ayuXBvGeo9yYSyVLjfdNsFq03GLKfLBDxCQdPwFKwk1g+8y0oTLsjLruT9Q0Sw7xHT qPNVVdhkm6DKE/RlJDKRg+AcDo61w7nHGAkorUnJttKILR7M3vUgjwJzVqc814df+2 JOcdH2JCbjj+mVGZQyq0t+w1L2DXuin1C9565yCq5EFq0jwP4qFGVTDa0cZzh//G7T /KxlRioeirYBQ== From: "Jiri Slaby (SUSE)" To: linux-kernel@vger.kernel.org Cc: Andi Kleen , Masahiro Yamada , Michal Marek , Nick Desaulniers , linux-kbuild@vger.kernel.org, Martin Liska , Jiri Slaby Subject: [PATCH 44/46] scripts/bloat-o-meter, lto: handle gcc LTO Date: Mon, 14 Nov 2022 12:43:42 +0100 Message-Id: <20221114114344.18650-45-jirislaby@kernel.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221114114344.18650-1-jirislaby@kernel.org> References: <20221114114344.18650-1-jirislaby@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org From: Andi Kleen gcc LTO can add .lto_priv postfixes to symbols. Ignore those in bloat-o-meter to allow comparison of non-LTO with LTO kernels. Cc: Masahiro Yamada Cc: Michal Marek Cc: Nick Desaulniers Cc: linux-kbuild@vger.kernel.org Signed-off-by: Andi Kleen Signed-off-by: Martin Liska Signed-off-by: Jiri Slaby --- scripts/bloat-o-meter | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/bloat-o-meter b/scripts/bloat-o-meter index f9553f60a14a..ab994b3bf6e2 100755 --- a/scripts/bloat-o-meter +++ b/scripts/bloat-o-meter @@ -45,7 +45,7 @@ def getsizes(file, format): if name == "linux_banner": continue if name == "vermagic": continue # statics and some other optimizations adds random .NUMBER - name = re_NUMBER.sub('', name) + name = re_NUMBER.sub('', name).replace(".lto_priv", "") sym[name] = sym.get(name, 0) + int(size, 16) return sym