From nobody Sat Feb 7 18:20:44 2026 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 122CD7711E for ; Sun, 28 Jul 2024 20:30:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722198652; cv=none; b=brB6Q3dMiLGUMlNLPyxSyb/VNPqqpE6fv8kwRllcmXKv2riLDA0trWJOR5Kiy/bR/ej9ZDg/rpVfTINqqJvdmdqYOVSrNoIALUQ3pthgPi1kqs5HOUTdNOkgi7lBRIxLNwtImWUnzoXRe4A5/11V/6hffSXFLyVwbKil9S+GctE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722198652; c=relaxed/simple; bh=1slrsF4Hlf8Hp/QXTPOV94EZfMBZN7LxrqA/xBkKf3M=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=U3vdG8QO64CzEmJPnwposRJS3JDtNywd7s0+fPHTZ40QDlgWT41m//jueoBd6fsB8gmwlKJiWoThteE1Pscbf+gUOl3bkkfIWorFg7a8FfpThkKLu9P2MVJkYs6i7bMfGPg4ytzb3gXdRIloCYnDkTTBWUSkZ6Hy92WF8DB3S/4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--xur.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=HeKaN+rQ; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--xur.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="HeKaN+rQ" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e0b2fb62a07so3114948276.0 for ; Sun, 28 Jul 2024 13:30:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722198649; x=1722803449; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=QVHCT9RvsK3VuE7zEDFg518c3S1iQ9syBfgTZJ1sM2A=; b=HeKaN+rQDkrYNnt4dSwJOFMxwG/dJnniwWOnJvsO+aE2OQaymEVui80kE/7PyMlEx7 wjmeYjWgHYCyUbwT0+ekxk6i09djpwrROrGB6nSrj6U5hXe4e3AeRPONS1zeFnB+tbTd 4fnIX1XuOS6wHcdXfv8pCeFsU+3Syi6SaiH773+yyhoodG1dHzrXABvZVmjqID3Lrglv 7lpsGGn82Lbtcds5iDGg3rOYBmrK/OZQWqaMbGXpI1bwh3psip030UXLNAov+TdDTJUv 4ZpBnpLUzmvleOy0DwMojBSbIjoDikDpudMoV8EWc6goJPCrcco/0U9q4oaEBgQtuSh6 kIpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722198649; x=1722803449; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=QVHCT9RvsK3VuE7zEDFg518c3S1iQ9syBfgTZJ1sM2A=; b=Nm5GayXWbRRw9VoLL6tQ7lL+wjRvb2VmKzhIK8w3O4l/Ss8nTIsH8MBRADVnov5z+c YhQ4VnIZuCtJvx/fUKEHJxkdlrdHW8tnnvuE9w5ihPwd3WBD3/LzZ2bRPfz55g4NP2g5 w0X5n5jYcVGNCsbpMZCzZ6kZTI3di1/0ukhk2uGf3+A5Jk0NAn/2ULDrq469keuSeLeB 98TUDyQGZOJcHmxt6e+k31hJ4UQW6ffhltERKT0nRCoV8Il5lROK5CMEYS/LTbNwH7GS 2iB0AqaP3DO8lFpgz/KMBsQ3vISJoVLlr/bat3tCD2i/Ps4SxavKV9TbjafhnMuPramI kO1w== X-Forwarded-Encrypted: i=1; AJvYcCV5k9DgQrzQNSzadAzAg/sZ+A0wncXWQYapMptZY3q9xpkhPe15a1+4bFM2bAvN1XIEaFkbiS34p40Cr3OmhiocTaUEtk55U97qSVOf X-Gm-Message-State: AOJu0YxMFY++DaqPzMSCJIl9Ef2mMPk40n4wn3hxd7q3rZVLk2/Sv9Wu xVZeRPyk+0FQud87I9CRFUk+HvczVIhOQ2io9d6Wjk1baimJ1dQulXICOn2+NGcRIA== X-Google-Smtp-Source: AGHT+IGo5aItSeb/vpdkLjP2AUowaXTsHznCqCbQFmsWxXPcX/0j5k8mMdMzFSuWVf/Jc9tAP6jYCv0= X-Received: from xur.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:2330]) (user=xur job=sendgmr) by 2002:a25:9707:0:b0:e08:a80c:8742 with SMTP id 3f1490d57ef6-e0b54467758mr135369276.5.1722198648804; Sun, 28 Jul 2024 13:30:48 -0700 (PDT) Date: Sun, 28 Jul 2024 13:29:54 -0700 In-Reply-To: <20240728203001.2551083-1-xur@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240728203001.2551083-1-xur@google.com> X-Mailer: git-send-email 2.46.0.rc1.232.g9752f9e123-goog Message-ID: <20240728203001.2551083-2-xur@google.com> Subject: [PATCH 1/6] Add AutoFDO support for Clang build From: Rong Xu To: Rong Xu , Han Shen , Sriraman Tallam , David Li , Jonathan Corbet , Masahiro Yamada , Nathan Chancellor , Nicolas Schier , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H . Peter Anvin" , Ard Biesheuvel , Arnd Bergmann , Josh Poimboeuf , Peter Zijlstra , Nick Desaulniers , Bill Wendling , Justin Stitt , Vegard Nossum , John Moon , Andrew Morton , Heiko Carstens , Luis Chamberlain , Samuel Holland , Mike Rapoport , "Paul E . McKenney" , Rafael Aquini , Petr Pavlu , Eric DeVolder , Bjorn Helgaas , Randy Dunlap , Benjamin Segall , Breno Leitao , Wei Yang , Brian Gerst , Juergen Gross , Palmer Dabbelt , Alexandre Ghiti , Kees Cook , Sami Tolvanen , Xiao Wang , Jan Kiszka Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-efi@vger.kernel.org, linux-arch@vger.kernel.org, llvm@lists.linux.dev, Krzysztof Pszeniczny , Stephane Eranian Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add the build support for using Clang's AutoFDO. Building the kernel with AutoFDO does not reduce the optimization level from the compiler. AutoFDO uses hardware sampling to gather information about the frequency of execution of different code paths within a binary. This information is then used to guide the compiler's optimization decisions, resulting in a more efficient binary. Experiments showed that the kernel can improve up to 10% in latency. The support requires a Clang compiler after LLVM 17. This submission is limited to x86 platforms that support PMU features like LBR on Intel machines and AMD Zen3 BRS. Support for SPE on ARM 1, and BRBE on ARM 1 is part of planned future work. Here is an example workflow for AutoFDO kernel: 1) Build the kernel on the HOST machine with LLVM enabled, for example, $ make menuconfig LLVM=3D1 Turn on AutoFDO build config: CONFIG_AUTOFDO_CLANG=3Dy With a configuration that has LLVM enabled, use the following command: scripts/config -e AUTOFDO_CLANG After getting the config, build with $ make LLVM=3D1 2) Install the kernel on the TEST machine. 3) Run the load tests. The '-c' option in perf specifies the sample event period. We suggest using a suitable prime number, like 500009, for this purpose. For Intel platforms: $ perf record -e BR_INST_RETIRED.NEAR_TAKEN:k -a -N -b -c \ -o -- For AMD platforms: The supported system are: Zen3 with BRS, or Zen4 with amd_lbr_v2 For Zen3: $ cat proc/cpuinfo | grep " brs" For Zen4: $ cat proc/cpuinfo | grep amd_lbr_v2 $ perf record --pfm-events RETIRED_TAKEN_BRANCH_INSTRUCTIONS:k -a \ -N -b -c -o -- 4) (Optional) Download the raw perf file to the HOST machine. 5) To generate an AutoFDO profile, two offline tools are available: create_llvm_prof and llvm_profgen. The create_llvm_prof tool is part of the AutoFDO project and can be found on GitHub (https://github.com/google/autofdo), version v0.30.1 or later. The llvm_profgen tool is included in the LLVM compiler itself. It's important to note that the version of llvm_profgen doesn't need to match the version of Clang. It needs to be the LLVM 19 release or later, or from the LLVM trunk. $ llvm-profgen --kernel --binary=3D --perfdata=3D= \ -o or $ create_llvm_prof --binary=3D --profile=3D \ --format=3Dextbinary -o Note that multiple AutoFDO profile files can be merged into one via: $ llvm-profdata merge -o ... 6) Rebuild the kernel using the AutoFDO profile file with the same config as step 1, (Note CONFIG_AUTOFDO_CLANG needs to be enabled): $ make LLVM=3D1 CLANG_AUTOFDO_PROFILE=3D Co-developed-by: Han Shen Signed-off-by: Han Shen Signed-off-by: Rong Xu Suggested-by: Sriraman Tallam Suggested-by: Krzysztof Pszeniczny Suggested-by: Nick Desaulniers Suggested-by: Stephane Eranian --- Documentation/dev-tools/autofdo.rst | 203 ++++++++++++++++++++++++++++ Documentation/dev-tools/index.rst | 1 + MAINTAINERS | 7 + Makefile | 1 + arch/Kconfig | 20 +++ arch/x86/Kconfig | 1 + scripts/Makefile.autofdo | 20 +++ scripts/Makefile.lib | 10 ++ tools/objtool/check.c | 1 + 9 files changed, 264 insertions(+) create mode 100644 Documentation/dev-tools/autofdo.rst create mode 100644 scripts/Makefile.autofdo diff --git a/Documentation/dev-tools/autofdo.rst b/Documentation/dev-tools/= autofdo.rst new file mode 100644 index 000000000000..e3f7ee8ee6bb --- /dev/null +++ b/Documentation/dev-tools/autofdo.rst @@ -0,0 +1,203 @@ +.. SPDX-License-Identifier: GPL-2.0 + +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +Using AutoFDO with the Linux kernel +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +This enables AutoFDO build support for the kernel when using +the Clang compiler. AutoFDO (Auto-Feedback-Directed Optimization) +is a type of profile-guided optimization (PGO) used to enhance the +performance of binary executables. It gathers information about the +frequency of execution of various code paths within a binary using +hardware sampling. This data is then used to guide the compiler's +optimization decisions, resulting in a more efficient binary. AutoFDO +is a powerful optimization technique, and data indicates that it can +significantly improve kernel performance. It's especially beneficial +for workloads affected by front-end stalls. + +For AutoFDO builds, unlike non-FDO builds, the user must supply a +profile. Acquiring an AutoFDO profile can be done in several ways. +AutoFDO profiles are created by converting hardware sampling using +the "perf" tool. It is crucial that the workload used to create these +perf files is representative; they must exhibit runtime +characteristics similar to the workloads that are intended to be +optimized. Failure to do so will result in the compiler optimizing +for the wrong objective. + +The AutoFDO profile often encapsulates the program's behavior. If the +performance-critical codes are architecture-independent, the profile +can be applied across platforms to achieve performance gains. For +instance, using the profile generated on Intel architecture to build +a kernel for AMD architecture can also yield performance improvements. + +There are two methods for acquiring a representative profile: +(1) Sample real workloads using a production environment. +(2) Generate the profile using a representative load test. +When enabling the AutoFDO build configuration without providing an +AutoFDO profile, the compiler only modifies the dwarf information in +the kernel without impacting runtime performance. It's advisable to +use a kernel binary built with the same AutoFDO configuration to +collect the perf profile. While it's possible to use a kernel built +with different options, it may result in inferior performance. + +One can collect profiles using AutoFDO build for the previous kernel. +AutoFDO employs relative line numbers to match the profiles, offering +some tolerance for source changes. This mode is commonly used in a +production environment for profile collection. + +In a profile collection based on a load test, the AutoFDO collection +process consists of the following steps: + +#. Initial build: The kernel is built with AutoFDO options + without a profile. + +#. Profiling: The above kernel is then run with a representative + workload to gather execution frequency data. This data is + collected using hardware sampling, via perf. AutoFDO is most + effective on platforms supporting advanced PMU features like + LBR on Intel machines. + +#. AutoFDO profile generation: Perf output file is converted to + the AutoFDO profile via offline tools. + +The support requires a Clang compiler LLVM 17 or later. + +Preparation +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +Configure the kernel with: + + .. code-block:: make + + CONFIG_AUTOFDO_CLANG=3Dy + +Customization +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +You can enable or disable AutoFDO build for individual file and directorie= s by +adding a line similar to the following to the respective kernel Makefile: + +- For enabling a single file (e.g. foo.o) + + .. code-block:: make + + AUTOFDO_PROFILE_foo.o :=3D y + +- For enabling all files in one directory + + .. code-block:: make + + AUTOFDO_PROFILE :=3D y + +- For disabling one file + + .. code-block:: make + + AUTOFDO_PROFILE_foo.o :=3D n + +- For disabling all files in one directory + + .. code-block:: make + + AUTOFDO_PROFILE :=3D n + + +Workflow +=3D=3D=3D=3D=3D=3D=3D=3D + +Here is an example workflow for AutoFDO kernel: + + + +1) Build the kernel on the HOST machine with LLVM enabled, for example, + + .. code-block:: make + + $ make menuconfig LLVM=3D1 + + + Turn on AutoFDO build config: + + .. code-block:: make + + CONFIG_AUTOFDO_CLANG=3Dy + + With a configuration that with LLVM enabled, use the following command: + + .. code-block:: sh + + $ scripts/config -e AUTOFDO_CLANG + + After getting the config, build with + + .. code-block:: make + + $ make LLVM=3D1 + +2) Install the kernel on the TEST machine. + +3) Run the load tests. The '-c' option in perf specifies the sample + event period. We suggest using a suitable prime number, like 500009, + for this purpose. + + - For Intel platforms: + + .. code-block:: sh + + $ perf record -e BR_INST_RETIRED.NEAR_TAKEN:k -a -N -b -c = -o -- + + - For AMD platforms: For Intel platforms: + The supported systems are: Zen3 with BRS, or Zen4 with amd_lbr_v2. To= check, + For Zen3: + + .. code-block:: sh + + $ cat proc/cpuinfo | grep " brs" + + For Zen4: + + .. code-block:: sh + + $ cat proc/cpuinfo | grep amd_lbr_v2 + + The following command generated the perf data file: + + .. code-block:: sh + + $ perf record --pfm-events RETIRED_TAKEN_BRANCH_INSTRUCTIONS:k -a= -N -b \ + -c -o -- + +4) (Optional) Download the raw perf file to the HOST machine. + +5) To generate an AutoFDO profile, two offline tools are available: + create_llvm_prof and llvm_profgen. The create_llvm_prof tool is part + of the AutoFDO project and can be found on GitHub + (https://github.com/google/autofdo), version v0.30.1 or later. + The llvm_profgen tool is included in the LLVM compiler itself. It's + important to note that the version of llvm_profgen doesn't need to match + the version of Clang. It needs to be the LLVM 19 release of Clang + or later, or just from the LLVM trunk. + + .. code-block:: sh + + $ llvm-profgen --kernel --binary=3D --perfdata=3D -o + + or + .. code-block:: sh + + $ create_llvm_prof --binary=3D --profile=3D -= -format=3Dextbinary -o + + Note that multiple AutoFDO profile files can be merged into one via: + + .. code-block:: sh + + $ llvm-profdata merge -o = ... + + +6) Rebuild the kernel using the AutoFDO profile file with the same config = as step 1, + (Note CONFIG_AUTOFDO_CLANG needs to be enabled): + + .. code-block:: sh + + $ make LLVM=3D1 CLANG_AUTOFDO_PROFILE=3D +M: Han Shen +S: Supported +F: Documentation/dev-tools/autofdo.rst +F: scripts/Makefile.autofdo + AUXILIARY BUS DRIVER M: Greg Kroah-Hartman R: Dave Ertman diff --git a/Makefile b/Makefile index 06aa6402b385..5ae30cc94a26 100644 --- a/Makefile +++ b/Makefile @@ -1024,6 +1024,7 @@ include-$(CONFIG_UBSAN) +=3D scripts/Makefile.ubsan include-$(CONFIG_KCOV) +=3D scripts/Makefile.kcov include-$(CONFIG_RANDSTRUCT) +=3D scripts/Makefile.randstruct include-$(CONFIG_GCC_PLUGINS) +=3D scripts/Makefile.gcc-plugins +include-$(CONFIG_AUTOFDO_CLANG) +=3D scripts/Makefile.autofdo =20 include $(addprefix $(srctree)/, $(include-y)) =20 diff --git a/arch/Kconfig b/arch/Kconfig index 975dd22a2dbd..e12599c4ab63 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -802,6 +802,26 @@ config LTO_CLANG_THIN If unsure, say Y. endchoice =20 +config ARCH_SUPPORTS_AUTOFDO_CLANG + bool + +config AUTOFDO_CLANG + bool "Enable Clang's AutoFDO build (EXPERIMENTAL)" + depends on ARCH_SUPPORTS_AUTOFDO_CLANG + depends on CC_IS_CLANG && CLANG_VERSION >=3D 170000 + help + This option enables Clang=E2=80=99s AutoFDO build. When + an AutoFDO profile is specified in variable + CLANG_AUTOFDO_PROFILE during the build process, + Clang uses the profile to optimize the kernel. + + If no profile is specified, AutoFDO options are + still passed to Clang to facilitate the collection + of perf data for creating an AutoFDO profile in + subsequent builds. + + If unsure, say N. + config ARCH_SUPPORTS_CFI_CLANG bool help diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 1d7122a1883e..dca526b1364f 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -122,6 +122,7 @@ config X86 select ARCH_USES_CFI_TRAPS if X86_64 && CFI_CLANG select ARCH_SUPPORTS_LTO_CLANG select ARCH_SUPPORTS_LTO_CLANG_THIN + select ARCH_SUPPORTS_AUTOFDO_CLANG select ARCH_USE_BUILTIN_BSWAP select ARCH_USE_CMPXCHG_LOCKREF if X86_CMPXCHG64 select ARCH_USE_MEMTEST diff --git a/scripts/Makefile.autofdo b/scripts/Makefile.autofdo new file mode 100644 index 000000000000..882fa7e801ba --- /dev/null +++ b/scripts/Makefile.autofdo @@ -0,0 +1,20 @@ +# SPDX-License-Identifier: GPL-2.0 + +# Enable available and selected Clang AutoFDO features. + +CFLAGS_AUTOFDO_CLANG :=3D -fdebug-info-for-profiling -mllvm -enable-fs-dis= criminator=3Dtrue -mllvm -improved-fs-discriminator=3Dtrue + +ifdef CLANG_AUTOFDO_PROFILE +CFLAGS_AUTOFDO_CLANG +=3D -fprofile-sample-use=3D$(CLANG_AUTOFDO_PROFILE) +endif + +ifdef CONFIG_LTO_CLANG +ifdef CONFIG_LTO_CLANG_THIN +ifdef CLANG_AUTOFDO_PROFILE +KBUILD_LDFLAGS +=3D --lto-sample-profile=3D$(CLANG_AUTOFDO_PROFILE) +endif +KBUILD_LDFLAGS +=3D --mllvm=3D-enable-fs-discriminator=3Dtrue --mllvm=3D-i= mproved-fs-discriminator=3Dtrue -plugin-opt=3Dthinlto +endif +endif + +export CFLAGS_AUTOFDO_CLANG diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index 9f06f6aaf7fc..c2cab5adaf25 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -209,6 +209,16 @@ _c_flags +=3D $(if $(patsubst n%,, \ -D__KCSAN_INSTRUMENT_BARRIERS__) endif =20 +# +# Enable Clang's AutoFDO build flags for a file or directory depending on +# variables AUTOFDO_PROFILE_obj.o and AUTOFDO_PROFILE. +# +ifeq ($(CONFIG_AUTOFDO_CLANG),y) +_c_flags +=3D $(if $(patsubst n%,, \ + $(AUTOFDO_PROFILE_$(target-stem).o)$(AUTOFDO_PROFILE)y), \ + $(CFLAGS_AUTOFDO_CLANG)) +endif + # $(src) for including checkin headers from generated source files # $(obj) for including generated headers from checkin source files ifeq ($(KBUILD_EXTMOD),) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 0a33d9195b7a..254913498c3c 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -4488,6 +4488,7 @@ static int validate_ibt(struct objtool_file *file) !strcmp(sec->name, "__jump_table") || !strcmp(sec->name, "__mcount_loc") || !strcmp(sec->name, ".kcfi_traps") || + !strcmp(sec->name, ".llvm.call-graph-profile") || strstr(sec->name, "__patchable_function_entries")) continue; =20 --=20 2.46.0.rc1.232.g9752f9e123-goog From nobody Sat Feb 7 18:20:44 2026 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7DF6F77F1B for ; Sun, 28 Jul 2024 20:30:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722198655; cv=none; b=BQeqPaxf5iyG7Kq2u+9iXZlOPQIn6Bvdvqm5+rDeXh8878q+ms6/AKvG/oUiBzdWVI1avTytwK6iZTi/QN/zo+jFPbe93DddmvPTbdW5LmOuhtkQ3jQjAezasg3oa+PdYj/fPVC7bTiWY1txpw2swm/fu1eZXM37TYbRxrRj3lw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722198655; c=relaxed/simple; bh=FBqzozWJhNvJ4oM6y6ThYCUCO6Sc4TGcBQGQrbyCu+w=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=KNj1YhlKLTMTQSsx/zVxgEDF3c+FQXrDqKUGyXJdXbxQm2y7BqDZT4ZZrcYfqJDQDHOxKtO1OY9lAqooUJx1ogZB5qHl2XPdcWMVMHO3WWEPqkAv6CpYj9s9khqltSiYnV2VJZ2rmGpr2WT05SzzWh4NJXvS2p5Y3Ei+pdC1vV0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--xur.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=HAVlKJ+S; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--xur.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="HAVlKJ+S" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e035949cc4eso2702649276.1 for ; Sun, 28 Jul 2024 13:30:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722198653; x=1722803453; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=dHGeCL3vH0qLBFDWm8avFROR6jr66E4NssJlgZilgo4=; b=HAVlKJ+SJ0zr2QU0Hj8jIIqFPWrKyHppDOHwHx0bYw71kSbxvOi3wzNGlfIldXotVY XJn4QUqdeqqVQZ7aV8FWy1AvyABNTrsSIon8fGaLifNKG3jpdFsqbicdAOgbEQRbftfn 5UhiLxdmlMs5fBykUeB80RsiSKur/ydE6sFCwaDE7vuAjlFw/2fKwcAg8Vp//FZ9Cpuv n+dylMmRXCxKHoyVV3HstJvQXrE5x17xbL9C52iQu8ER9uTENgITIch54+NqnTng4GcX dD2gl07jrln7rJVH/QFxi5qAxXCsAkEAjUlNTffGJd4gyMepzFg68ddzIl6NeZDJB1WC KUeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722198653; x=1722803453; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=dHGeCL3vH0qLBFDWm8avFROR6jr66E4NssJlgZilgo4=; b=LghHGIW6tY4hf/SuoAvuhKGzAQJrJ306wL4fiqsmWV2rQ/ghqGvQIW2P6ikXKWkFJd SpvMQINx7GcQ8xXYLeu7ngtKRrFKA9lbusTRfjNftw4X0Ofi1VFanpZqoqrJiMeNVZ4w uhGXIUsmP5vYLFMSaBmGGweom0aBr4ZcCzYccIe5dJfvEfPAxMRyl2BQ6MQ2Pl0EbJ5g AgQvfdevEAzfjqNBiKr1tEH7Heb5AH+29E8TMuhi3yCg2di0NnpfmflJME1283M2p61V 9/tn2oT2R1tw8E5v2L3uKaubvQkLNo13nHnWCm3Kz7XlJW3UYUbvWK7ay/3fcki00HcI fM2g== X-Forwarded-Encrypted: i=1; AJvYcCUqdAV00ibtcg7TU2PX6zWInpCuUv8VX/xO5aP7YonHlUdtiI+7DJPSpaJR11H6i63whEmmvB/fCssll6ZlItJz7e3ML3RQcOtsAkk9 X-Gm-Message-State: AOJu0Yzj+UgpmmJ2KFOiHRskFfsmOMG1YCtWf29M1WmLHdk3yMfZKPQY 1zWiZkmh41Np1SEb4h4lu5oXG7FvuI4YnWVvrv9D2vdMPD5AxPMkCyif7jySbX7K0A== X-Google-Smtp-Source: AGHT+IFbB1GtuSWiJ25Z5CJHBsZeUzd/7OcS+ZwDnzKKXYJCUjO8F45P4dz+nwWaMnszX5UCfblv1II= X-Received: from xur.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:2330]) (user=xur job=sendgmr) by 2002:a05:6902:1248:b0:e0b:10e9:88f8 with SMTP id 3f1490d57ef6-e0b545590famr362781276.8.1722198652426; Sun, 28 Jul 2024 13:30:52 -0700 (PDT) Date: Sun, 28 Jul 2024 13:29:55 -0700 In-Reply-To: <20240728203001.2551083-1-xur@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240728203001.2551083-1-xur@google.com> X-Mailer: git-send-email 2.46.0.rc1.232.g9752f9e123-goog Message-ID: <20240728203001.2551083-3-xur@google.com> Subject: [PATCH 2/6] objtool: Fix unreachable instruction warnings for weak funcitons From: Rong Xu To: Rong Xu , Han Shen , Sriraman Tallam , David Li , Jonathan Corbet , Masahiro Yamada , Nathan Chancellor , Nicolas Schier , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H . Peter Anvin" , Ard Biesheuvel , Arnd Bergmann , Josh Poimboeuf , Peter Zijlstra , Nick Desaulniers , Bill Wendling , Justin Stitt , Vegard Nossum , John Moon , Andrew Morton , Heiko Carstens , Luis Chamberlain , Samuel Holland , Mike Rapoport , "Paul E . McKenney" , Rafael Aquini , Petr Pavlu , Eric DeVolder , Bjorn Helgaas , Randy Dunlap , Benjamin Segall , Breno Leitao , Wei Yang , Brian Gerst , Juergen Gross , Palmer Dabbelt , Alexandre Ghiti , Kees Cook , Sami Tolvanen , Xiao Wang , Jan Kiszka Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-efi@vger.kernel.org, linux-arch@vger.kernel.org, llvm@lists.linux.dev, Krzysztof Pszeniczny Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In the presence of both weak and strong function definitions, the linker drops the weak symbol in favor of a strong symbol, but leaves the code in place. Code in ignore_unreachable_insn() has some heuristics to suppress the warning, but it does not work when -ffunction-sections is enabled. Suppose function foo has both strong and weak definitions. Case 1: The strong definition has an annotated section name, like .init.text. Only the weak definition will be placed into .text.foo. But since the section has no symbols, there will be no "hole" in the section. Case 2: Both sections are without an annotated section name. Both will be placed into .text.foo section, but there will be only one symbol (the strong one). If the weak code is before the strong code, there is no "hole" as it fails to find the right-most symbol before the offset. The fix is to use the first node to compute the hole if hole.sym is empty. If there is no symbol in the section, the first node will be NULL, in which case, -1 is returned to skip the whole section. Co-developed-by: Han Shen Signed-off-by: Han Shen Signed-off-by: Rong Xu Suggested-by: Sriraman Tallam Suggested-by: Krzysztof Pszeniczny --- tools/objtool/elf.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c index 3d27983dc908..fa88bb254ccc 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -224,12 +224,15 @@ int find_symbol_hole_containing(const struct section = *sec, unsigned long offset) if (n) return 0; /* not a hole */ =20 - /* didn't find a symbol for which @offset is after it */ - if (!hole.sym) - return 0; /* not a hole */ + /* + * @offset >=3D sym->offset + sym->len, find symbol after it. + * Use the first node in rb_tree when hole.sym is NULL. + */ + if (hole.sym) + n =3D rb_next(&hole.sym->node); + else + n =3D rb_first_cached(&sec->symbol_tree); =20 - /* @offset >=3D sym->offset + sym->len, find symbol after it */ - n =3D rb_next(&hole.sym->node); if (!n) return -1; /* until end of address space */ =20 --=20 2.46.0.rc1.232.g9752f9e123-goog From nobody Sat Feb 7 18:20:44 2026 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3BB3878C9A for ; Sun, 28 Jul 2024 20:30:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722198658; cv=none; b=Mx4SjUFizSMKIHnoR9UAz98ZHt8N+JyTu/NDbMK44kbPs+bFik1VIDwv211k51WgDeIKHYFXhOf3dII0Sm0hkT6hYO5UiJp8ZcG6zX8cWsfMepgX6CVPnxmLAsA4zc1mKzMWTxvrh2rWmdDXetMcK1hlp2lql3Zv366R7/MxM3I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722198658; c=relaxed/simple; bh=5P/ds+u1Nc4DlKNiDUD6ZuYs75VWIvFx1DNGM0tCz1Q=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=RAGc8xm21UQ48U3ozVYSi9S9cQ+KqBdok9QRBSHI3+cRvYOxhuDy/1Rfdrd9eBTve9o8dBRYTKUFPcUdrxxq28miYOCJyERcW6fnrEyVBtF99dBbOn2EejYW6qr4j1RTex2u9mh+Fp+/kXVKCoF0/R1fL9/thFP+NBmMbCTDdA0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--xur.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=cBfLi/ND; arc=none smtp.client-ip=209.85.215.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--xur.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="cBfLi/ND" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-7a242496897so1808872a12.2 for ; Sun, 28 Jul 2024 13:30:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722198656; x=1722803456; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=o2mnjrwU8q3IWuUcbnv2YL1wGLUV3JerNGbL3ta/V8U=; b=cBfLi/NDtBWBjPzpPP+v5+G1124d8hHZzbXbgoiu4pqz+FAKvbw9E1ZLyEQgrBXN25 QbpBDIRhwXvjGIFkLpOyTIhPDblH6z/L1doVuTsiqPZBd3276WcIB7fjno5tWbyx2LVp o68jtHuRaLpUhnyQpxWw/xwyAg+WMpY61e+epj7knLvBbskeNjDP3nsirkhsx/Uhe9SK cmvyKn7Jm0OiGkRZf/q5fyR1FTwd5Hz+yuctGrsZsUQCxLf1Y1wEd50xCsjePOvSawfc btR56IofvZ/TgXqTUer2V6Vh4qKhnwGLvDoQerI4gDdZzE1I6CVclK+x3p6QTbCmJgC7 dH1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722198656; x=1722803456; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=o2mnjrwU8q3IWuUcbnv2YL1wGLUV3JerNGbL3ta/V8U=; b=wl/KL6VlTOWOaNqS98TjVZDFfrqSz1b9AuqaU/KVo6c7s0xxmotud4jL+mn+ZViXYS SAHNFvIlC3W+fhU7YjsyNn/gDCJ2PXzMwyuiQrHvdU7LcG85Q0gwtzc3sV/C/AfQDY3E d0RUj7AMPmSQxtlmOOsh3OYBBD4E9LgJ0laKzQeXY6g/NFkbHGBnp/q/j+xXx6U8PtSY XmCBx8sD3D1qquEq6RcexlKIEXvFB/57mD9AsWArr3lKvFoEzLr+MhgP73VJx479/woW PdMORMXalDZOVvRlt6t9zhMaglfbyjJlYEpOAoWAecvIzrAF7pKSoOZXUtY/iFs8FuB5 0c5g== X-Forwarded-Encrypted: i=1; AJvYcCWacsVT8m0kzFN84ITEKnj+MQ8+yTKl4Ox7VABxIYKQJGTbo2i658zTOZWdgShC2K7IhenzOjWcxsXAG5aqfO+5hhxOIamXR0YVMpCl X-Gm-Message-State: AOJu0YwziuapcoWrU12Ogxgthbc+drD5xZnI79OY1a0kS1bdd/oHL2F7 35vD86SJ0NUQk+3oIFs82KYbdD0AEuDJ3rG7+4bxIIysJjfnVd2u9HpAIcWg5ZUFOw== X-Google-Smtp-Source: AGHT+IF+cnWDEef0AOr5iV5UnZQ0Nmg6qihUgkJJVOtSeHchBxmd2+NRGmp/GGHZSyrSRRs3cz4mBGg= X-Received: from xur.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:2330]) (user=xur job=sendgmr) by 2002:a63:e903:0:b0:75c:49a4:2a2c with SMTP id 41be03b00d2f7-7ac8f942a86mr12318a12.7.1722198655784; Sun, 28 Jul 2024 13:30:55 -0700 (PDT) Date: Sun, 28 Jul 2024 13:29:56 -0700 In-Reply-To: <20240728203001.2551083-1-xur@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240728203001.2551083-1-xur@google.com> X-Mailer: git-send-email 2.46.0.rc1.232.g9752f9e123-goog Message-ID: <20240728203001.2551083-4-xur@google.com> Subject: [PATCH 3/6] Change the symbols order when --ffuntion-sections is enabled From: Rong Xu To: Rong Xu , Han Shen , Sriraman Tallam , David Li , Jonathan Corbet , Masahiro Yamada , Nathan Chancellor , Nicolas Schier , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H . Peter Anvin" , Ard Biesheuvel , Arnd Bergmann , Josh Poimboeuf , Peter Zijlstra , Nick Desaulniers , Bill Wendling , Justin Stitt , Vegard Nossum , John Moon , Andrew Morton , Heiko Carstens , Luis Chamberlain , Samuel Holland , Mike Rapoport , "Paul E . McKenney" , Rafael Aquini , Petr Pavlu , Eric DeVolder , Bjorn Helgaas , Randy Dunlap , Benjamin Segall , Breno Leitao , Wei Yang , Brian Gerst , Juergen Gross , Palmer Dabbelt , Alexandre Ghiti , Kees Cook , Sami Tolvanen , Xiao Wang , Jan Kiszka Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-efi@vger.kernel.org, linux-arch@vger.kernel.org, llvm@lists.linux.dev, Krzysztof Pszeniczny Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When the -ffunction-sections compiler option is enabled, each function is placed in a separate section named .text.function_name rather than putting all functions in a single .text section. However, using -function-sections can cause problems with the linker script. The comments included in include/asm-generic/vmlinux.lds.h note these issues.: =E2=80=9CTEXT_MAIN here will match .text.fixup and .text.unlikely if dead code elimination is enabled, so these sections should be converted to use ".." first.=E2=80=9D It is unclear whether there is a straightforward method for converting a suffix to "..". This patch modifies the order of subsections within the text output section when the -ffunction-sections flag is enabled. Specifically, it repositions sections with certain fixed patterns (for example .text.unlikely) before TEXT_MAIN, ensuring that they are grouped and matched together. Note that the limitation arises because the linker script employs glob patterns instead of regular expressions for string matching. While there is a method to maintain the current order using complex patterns, this significantly complicates the pattern and increases the likelihood of errors. Co-developed-by: Han Shen Signed-off-by: Han Shen Signed-off-by: Rong Xu Suggested-by: Sriraman Tallam Suggested-by: Krzysztof Pszeniczny --- include/asm-generic/vmlinux.lds.h | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinu= x.lds.h index 5703526d6ebf..f3de66bda293 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -582,9 +582,21 @@ * during second ld run in second ld pass when generating System.map * * TEXT_MAIN here will match .text.fixup and .text.unlikely if dead - * code elimination is enabled, so these sections should be converted - * to use ".." first. + * code elimination or function-section is enabled. Match these symbols + * first when in these builds. */ +#if defined(CONFIG_LD_DEAD_CODE_DATA_ELIMINATION) || defined(CONFIG_LTO_CL= ANG) +#define TEXT_TEXT \ + *(.text.asan.* .text.tsan.*) \ + *(.text.unknown .text.unknown.*) \ + *(.text.unlikely .text.unlikely.*) \ + ALIGN_FUNCTION(); \ + *(.text.hot .text.hot.*) \ + *(TEXT_MAIN .text.fixup) \ + NOINSTR_TEXT \ + *(.ref.text) \ + MEM_KEEP(init.text*) +#else #define TEXT_TEXT \ ALIGN_FUNCTION(); \ *(.text.hot .text.hot.*) \ @@ -594,7 +606,8 @@ NOINSTR_TEXT \ *(.ref.text) \ *(.text.asan.* .text.tsan.*) \ - MEM_KEEP(init.text*) \ + MEM_KEEP(init.text*) +#endif =20 =20 /* sched.text is aling to function alignment to secure we have same --=20 2.46.0.rc1.232.g9752f9e123-goog From nobody Sat Feb 7 18:20:44 2026 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 838757BB17 for ; Sun, 28 Jul 2024 20:31:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722198662; cv=none; b=cxfTTjqFOb1os9mN3ErpAa1uZGY0UtODNv9cMWh3g7IFX8D//k9kK8D6LLplz7dwuBLf5+QqDfZrUevnkQdZUtHDjKpLD1qiWEUNH6kne+qbhUekVTNxjgtwgyCGwXqYrNofNsYK/Gs9PF042DpVCs538vCs0YMvWpGfLaeSWCQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722198662; c=relaxed/simple; bh=beGZIYM3TPtatxrKmLYPAD0/CJjAgMIMbsJ074Ik9tg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=RKGmifxzgOcjGM4Y14LuYUdEC6kxH6V00zfTGD2PdhgmWvAzfbpekeD4Jr9Kn2NjPUdWDX4wsy2KWBU9W+5uBunzyMK/p1wQnZ+neNLmFBgoYKEUV8B/SXmOYc5F+FTEfONdzjr3TlgGmMSTyt/LWak9APxwr0/GtIWZVnMa6Bw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--xur.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Cbw9W6ak; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--xur.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Cbw9W6ak" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e0b2ac67a53so2573655276.0 for ; Sun, 28 Jul 2024 13:31:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722198659; x=1722803459; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Nypg1QHLbTqa/1p2hSGPQd9/Gf8EHrTdP6hUDec9EdE=; b=Cbw9W6akg0cNIlC5zMjJAlxlLpwYzGB4rcfnqydC9Jze3jMb2XKqKzGywKdmsn/ijN c6MhSTyYHyEAmibBRh9dGqbOGFNum3nck1HFGOVA7duZoxDFns+AxrCKucm4tkyTgn6m K5oHXQhhQKUpCdP93JbAk3kYLeo5iMoJBXN9Y3pakzBjoBT63FrRkzA2GaanOCaXXENX ykkQGAP9vfGLVmDJaQgxg7lJ/Z1gxWfVIwXRrq8pzDMJggfmixLuHZZNFaZLeASdGd9I oiWiiteyOxAjMHTIhX6t1izT/TlPofqhWVMWpGZyvre1tO/+TyFNyfOSed1VXklQ6SqX nsFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722198659; x=1722803459; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Nypg1QHLbTqa/1p2hSGPQd9/Gf8EHrTdP6hUDec9EdE=; b=nT6B1EkCVfcutitE3JgSkjmxprO9ktgV5ttqw8BpmLXi10hnqwvNQN3lK1FqU9xgQN ZgAkGnACvzR9ScwYNSI6sk6o/Tyb00zrs8XQJayo+OtMpx9vA7n/q6htdD5YVREhlSry kCR7otwd5/i9zhX7fgCQAsYcq3F+23wlRwnAFkOgHXXnG9paFkx5bqZD547Z3trty0xV AOeX6FA2PG+iBvs/TXe8BIJxYDCmIYZKyy2LDEnvorrXo64AQ5WYxQ+vkLY4izGRn+pS 55w4b5PC1VyYVM6cCHQAoMdUDEgw348gz8fAmNELc12VqCIbTKddpUi5cZPwNEPLwy+2 nq3w== X-Forwarded-Encrypted: i=1; AJvYcCXG3lFExhLXSbh0GPZey1X00jxTOw71zxq+Uh3RORha97U/PuLHssp3tGNQ+s3TtiNubDZwOkgvdWO/cCfgSDFRVZFokF0BAcEfJLXQ X-Gm-Message-State: AOJu0YxfXgzACnE26m4yWTxFWScItYi1bixlolSkloV9pPUAs9dB7ozn +X2hOY//1NE31etHbpObcUcRk2Y4AuvdzBrzZO8iMwyviMLmNdewTVRlcUbGY/RgSw== X-Google-Smtp-Source: AGHT+IGhcfBcAn7qASZpEvCq18PhN0EBXHuUDxWLgxYpaHcb/kQ/zFsB5MAYY4oJLzn0xh4JiWgv4U8= X-Received: from xur.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:2330]) (user=xur job=sendgmr) by 2002:a25:6844:0:b0:e0b:3432:73d4 with SMTP id 3f1490d57ef6-e0b5560e6b3mr58714276.1.1722198659209; Sun, 28 Jul 2024 13:30:59 -0700 (PDT) Date: Sun, 28 Jul 2024 13:29:57 -0700 In-Reply-To: <20240728203001.2551083-1-xur@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240728203001.2551083-1-xur@google.com> X-Mailer: git-send-email 2.46.0.rc1.232.g9752f9e123-goog Message-ID: <20240728203001.2551083-5-xur@google.com> Subject: [PATCH 4/6] AutoFDO: Enable -ffunction-sections for the AutoFDO build From: Rong Xu To: Rong Xu , Han Shen , Sriraman Tallam , David Li , Jonathan Corbet , Masahiro Yamada , Nathan Chancellor , Nicolas Schier , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H . Peter Anvin" , Ard Biesheuvel , Arnd Bergmann , Josh Poimboeuf , Peter Zijlstra , Nick Desaulniers , Bill Wendling , Justin Stitt , Vegard Nossum , John Moon , Andrew Morton , Heiko Carstens , Luis Chamberlain , Samuel Holland , Mike Rapoport , "Paul E . McKenney" , Rafael Aquini , Petr Pavlu , Eric DeVolder , Bjorn Helgaas , Randy Dunlap , Benjamin Segall , Breno Leitao , Wei Yang , Brian Gerst , Juergen Gross , Palmer Dabbelt , Alexandre Ghiti , Kees Cook , Sami Tolvanen , Xiao Wang , Jan Kiszka Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-efi@vger.kernel.org, linux-arch@vger.kernel.org, llvm@lists.linux.dev Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Enable -ffunction-sections by default for the AutoFDO build. With -ffunction-sections, the compiler places each function in its own section named .text.function_name instead of placing all functions in the .text section. In the AutoFDO build, this allows the linker to utilize profile information to reorganize functions for improved utilization of iCache and iTLB. Co-developed-by: Han Shen Signed-off-by: Han Shen Signed-off-by: Rong Xu Suggested-by: Sriraman Tallam --- include/asm-generic/vmlinux.lds.h | 37 ++++++++++++++++++++++++------- scripts/Makefile.autofdo | 2 +- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinu= x.lds.h index f3de66bda293..97c8399e5532 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -95,18 +95,25 @@ * With LTO_CLANG, the linker also splits sections by default, so we need * these macros to combine the sections during the final link. * + * With LTO_CLANG, the linker also splits sections by default, so we need + * these macros to combine the sections during the final link. + * * 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_CL= ANG) +#if defined(CONFIG_LD_DEAD_CODE_DATA_ELIMINATION) || defined(CONFIG_LTO_CL= ANG) || \ +defined(CONFIG_AUTOFDO_CLANG) #define TEXT_MAIN .text .text.[0-9a-zA-Z_]* +#else +#define TEXT_MAIN .text +#endif +#if defined(CONFIG_LD_DEAD_CODE_DATA_ELIMINATION) || defined(CONFIG_LTO_CL= ANG) #define DATA_MAIN .data .data.[0-9a-zA-Z_]* .data..L* .data..compoundliter= al* .data.$__unnamed_* .data.$L* #define SDATA_MAIN .sdata .sdata.[0-9a-zA-Z_]* #define RODATA_MAIN .rodata .rodata.[0-9a-zA-Z_]* .rodata..L* #define BSS_MAIN .bss .bss.[0-9a-zA-Z_]* .bss..compoundliteral* #define SBSS_MAIN .sbss .sbss.[0-9a-zA-Z_]* #else -#define TEXT_MAIN .text #define DATA_MAIN .data #define SDATA_MAIN .sdata #define RODATA_MAIN .rodata @@ -577,6 +584,20 @@ __cpuidle_text_end =3D .; \ __noinstr_text_end =3D .; =20 +#ifdef CONFIG_AUTOFDO_CLANG +#define TEXT_HOT \ + __hot_text_start =3D .; \ + *(.text.hot .text.hot.*) \ + __hot_text_end =3D .; +#define TEXT_UNLIKELY \ + __unlikely_text_start =3D .; \ + *(.text.unlikely .text.unlikely.*) \ + __unlikely_text_end =3D .; +#else +#define TEXT_HOT *(.text.hot .text.hot.*) +#define TEXT_UNLIKELY *(.text.unlikely .text.unlikely.*) +#endif + /* * .text section. Map to function alignment to avoid address changes * during second ld run in second ld pass when generating System.map @@ -585,13 +606,14 @@ * code elimination or function-section is enabled. Match these symbols * first when in these builds. */ -#if defined(CONFIG_LD_DEAD_CODE_DATA_ELIMINATION) || defined(CONFIG_LTO_CL= ANG) +#if defined(CONFIG_LD_DEAD_CODE_DATA_ELIMINATION) || defined(CONFIG_LTO_CL= ANG) || \ +defined(CONFIG_AUTOFDO_CLANG) #define TEXT_TEXT \ *(.text.asan.* .text.tsan.*) \ *(.text.unknown .text.unknown.*) \ - *(.text.unlikely .text.unlikely.*) \ + TEXT_UNLIKELY \ ALIGN_FUNCTION(); \ - *(.text.hot .text.hot.*) \ + TEXT_HOT \ *(TEXT_MAIN .text.fixup) \ NOINSTR_TEXT \ *(.ref.text) \ @@ -599,9 +621,9 @@ #else #define TEXT_TEXT \ ALIGN_FUNCTION(); \ - *(.text.hot .text.hot.*) \ + TEXT_HOT \ *(TEXT_MAIN .text.fixup) \ - *(.text.unlikely .text.unlikely.*) \ + TEXT_UNLIKELY \ *(.text.unknown .text.unknown.*) \ NOINSTR_TEXT \ *(.ref.text) \ @@ -609,7 +631,6 @@ MEM_KEEP(init.text*) #endif =20 - /* sched.text is aling to function alignment to secure we have same * address even at second ld pass when generating System.map */ #define SCHED_TEXT \ diff --git a/scripts/Makefile.autofdo b/scripts/Makefile.autofdo index 882fa7e801ba..f765bd9e81d7 100644 --- a/scripts/Makefile.autofdo +++ b/scripts/Makefile.autofdo @@ -5,7 +5,7 @@ CFLAGS_AUTOFDO_CLANG :=3D -fdebug-info-for-profiling -mllvm -enable-fs-dis= criminator=3Dtrue -mllvm -improved-fs-discriminator=3Dtrue =20 ifdef CLANG_AUTOFDO_PROFILE -CFLAGS_AUTOFDO_CLANG +=3D -fprofile-sample-use=3D$(CLANG_AUTOFDO_PROFILE) +CFLAGS_AUTOFDO_CLANG +=3D -fprofile-sample-use=3D$(CLANG_AUTOFDO_PROFILE) = -ffunction-sections endif =20 ifdef CONFIG_LTO_CLANG --=20 2.46.0.rc1.232.g9752f9e123-goog From nobody Sat Feb 7 18:20:44 2026 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 204387D3EF for ; Sun, 28 Jul 2024 20:31:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722198666; cv=none; b=tzv161CpbQ3c70proLbGGVXtAgP05tFQIe9oqyQvmSgnG/n5DYIDkikLHRWNELQkYBgs5ekjVuI/p2iGZwdH2X+xD3RCk2zn2IT2/gn2GidfT/jlMUqM4cAmwZB1zwiWw60f6+P4g3UMwzIuAqH7S84pvzbmqhjwHFNx6/8oBwo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722198666; c=relaxed/simple; bh=jgG0TSTo1c+hpUBT22yEfSilFpbm6otN2MQr5+RKpfs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=E4p2wyWI94ekucsNBr+RW+qBTGcOgUgQ3HIFaFJLSc33QzdCKw0iFHBDYuioQC3goGkhEpsaiDvJbr0JgAofR24zr+c7TllfxdqU+kLx/d4RMSJyDfD5D81AtN+CDfA0YG0LXaPdTd9cKzTFYHuX81bH23wTUXc042N+rNUYXnA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--xur.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=f6BjeUdH; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--xur.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="f6BjeUdH" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-64c3f08ca52so43794417b3.3 for ; Sun, 28 Jul 2024 13:31:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722198663; x=1722803463; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Tokg3sFCTTXy/Tg/kyuYTkBel/otDfHpuf9TI5sSKRc=; b=f6BjeUdHR36Kg9BILRErBF2TT4LyUUUeWe/2pIZ5RJ+8bUz3/NbWjd66ppYH8KLMcg wybYF/uZjne3GMXh1E+X1zAYra/WCpKEUBjZOVjjzz0/kOx4veBmncDp4c0wvtTsPXg5 Q7gXKDwUc91Ffz70gcy8siG+Z0Z8BHkr4mNeJMykTEEKau1hFbkhlp/9cmPjSSyWsQTe MpRwuxKr7a7JOtgdouDxBAK4YVsVaopo8toXBrxqtqBLzkmJ/gJ/volGOdGKRdngDgrw IAbShFBlEXNFgyUQgorAI/NfrnUVubUQo28Ed5qPYkmr/8FVyRU0slQDy9KU844a+4q/ YX4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722198663; x=1722803463; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Tokg3sFCTTXy/Tg/kyuYTkBel/otDfHpuf9TI5sSKRc=; b=h+/jHpg3pXF4bmiV06RO/ZwFCD8PITMDwSRTdj7xV73LQ3QMuTq0u2Bxm6RhyEQRJC ljhBTbz2K+SF/+SFn5dpG/ChzlJ9fMx5rmT5vD7fiTVH0Q7+VXSG7GwPsQnURgikdruZ HKnbvWnM811M4VQr994JZ+6ivG1S4UfhZWs9jBbIO2HiAUT9cSKIyHyEkhCZ4mKpCpeb xzaGuq17dutT3yU0AulRiZ/526f3ki08GaVml9knLv35euYQtOokbkWFaVFq1WJHKllW /0LG5+EpBt4SHz3cICycd415RDJAB6VUd2gmasY7v3d7lx3U7dOXU3v6hQcxd2rIz1/e Dmyg== X-Forwarded-Encrypted: i=1; AJvYcCWItpbVMKdZVAuM0NzpX5WmN+UtjAISqZuk9YKBwIbSmADEpEZzL0Y48wg5SinkaQokFyLSANU8faury9u+j7JaX3qTzJmcDBwSu8qM X-Gm-Message-State: AOJu0YwSuIBaBWLDl5GRAzHBUeZ3bu0IFei4JMwU5NEqqYwoVLc7s6gu SNmrpuOMwVdikK26hDlaUVB3B/TbWg3aJ7ae9KdrIpCR3b15IEdDw1anemyJST5Ikw== X-Google-Smtp-Source: AGHT+IGFJCBpCGKio3GvIQMtPQU0FwuQLnvFXOWRFKgHtvK/N12utXtZSpDgbRkZ6jpM9dmXhNWYM7k= X-Received: from xur.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:2330]) (user=xur job=sendgmr) by 2002:a05:690c:827:b0:667:8a45:d0f9 with SMTP id 00721157ae682-67a004a2775mr1250767b3.0.1722198663143; Sun, 28 Jul 2024 13:31:03 -0700 (PDT) Date: Sun, 28 Jul 2024 13:29:58 -0700 In-Reply-To: <20240728203001.2551083-1-xur@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240728203001.2551083-1-xur@google.com> X-Mailer: git-send-email 2.46.0.rc1.232.g9752f9e123-goog Message-ID: <20240728203001.2551083-6-xur@google.com> Subject: [PATCH 5/6] AutoFDO: Enable machine function split optimization for AutoFDO From: Rong Xu To: Rong Xu , Han Shen , Sriraman Tallam , David Li , Jonathan Corbet , Masahiro Yamada , Nathan Chancellor , Nicolas Schier , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H . Peter Anvin" , Ard Biesheuvel , Arnd Bergmann , Josh Poimboeuf , Peter Zijlstra , Nick Desaulniers , Bill Wendling , Justin Stitt , Vegard Nossum , John Moon , Andrew Morton , Heiko Carstens , Luis Chamberlain , Samuel Holland , Mike Rapoport , "Paul E . McKenney" , Rafael Aquini , Petr Pavlu , Eric DeVolder , Bjorn Helgaas , Randy Dunlap , Benjamin Segall , Breno Leitao , Wei Yang , Brian Gerst , Juergen Gross , Palmer Dabbelt , Alexandre Ghiti , Kees Cook , Sami Tolvanen , Xiao Wang , Jan Kiszka Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-efi@vger.kernel.org, linux-arch@vger.kernel.org, llvm@lists.linux.dev, Krzysztof Pszeniczny Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Enable the machine function split optimization for AutoFDO in Clang. Machine function split (MFS) is a pass in the Clang compiler that splits a function into hot and cold parts. The linker groups all cold blocks across functions together. This decreases hot code fragmentation and improves iCache and iTLB utilization. MFS requires a profile so this is enabled only for the AutoFDO builds. Co-developed-by: Han Shen Signed-off-by: Han Shen Signed-off-by: Rong Xu Suggested-by: Sriraman Tallam Suggested-by: Krzysztof Pszeniczny --- include/asm-generic/vmlinux.lds.h | 6 ++++++ scripts/Makefile.autofdo | 2 ++ 2 files changed, 8 insertions(+) diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinu= x.lds.h index 97c8399e5532..7d9dc8a3c046 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -593,9 +593,14 @@ defined(CONFIG_AUTOFDO_CLANG) __unlikely_text_start =3D .; \ *(.text.unlikely .text.unlikely.*) \ __unlikely_text_end =3D .; +#define TEXT_SPLIT \ + __split_text_start =3D .; \ + *(.text.split .text.split.[0-9a-zA-Z_]*) \ + __split_text_end =3D .; #else #define TEXT_HOT *(.text.hot .text.hot.*) #define TEXT_UNLIKELY *(.text.unlikely .text.unlikely.*) +#define TEXT_SPLIT #endif =20 /* @@ -611,6 +616,7 @@ defined(CONFIG_AUTOFDO_CLANG) #define TEXT_TEXT \ *(.text.asan.* .text.tsan.*) \ *(.text.unknown .text.unknown.*) \ + TEXT_SPLIT \ TEXT_UNLIKELY \ ALIGN_FUNCTION(); \ TEXT_HOT \ diff --git a/scripts/Makefile.autofdo b/scripts/Makefile.autofdo index f765bd9e81d7..80ad06689947 100644 --- a/scripts/Makefile.autofdo +++ b/scripts/Makefile.autofdo @@ -6,6 +6,7 @@ CFLAGS_AUTOFDO_CLANG :=3D -fdebug-info-for-profiling -mllvm= -enable-fs-discriminat =20 ifdef CLANG_AUTOFDO_PROFILE CFLAGS_AUTOFDO_CLANG +=3D -fprofile-sample-use=3D$(CLANG_AUTOFDO_PROFILE) = -ffunction-sections +CFLAGS_AUTOFDO_CLANG +=3D -fsplit-machine-functions endif =20 ifdef CONFIG_LTO_CLANG @@ -14,6 +15,7 @@ ifdef CLANG_AUTOFDO_PROFILE KBUILD_LDFLAGS +=3D --lto-sample-profile=3D$(CLANG_AUTOFDO_PROFILE) endif KBUILD_LDFLAGS +=3D --mllvm=3D-enable-fs-discriminator=3Dtrue --mllvm=3D-i= mproved-fs-discriminator=3Dtrue -plugin-opt=3Dthinlto +KBUILD_LDFLAGS +=3D -plugin-opt=3D-split-machine-functions endif endif =20 --=20 2.46.0.rc1.232.g9752f9e123-goog From nobody Sat Feb 7 18:20:44 2026 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9AC567E0EA for ; Sun, 28 Jul 2024 20:31:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722198671; cv=none; b=PZ9ziWASfuChxS1PADSv3A+06ePpVs0L8L94hvEdFK/EPvQT+ppiaWLNM7Fh1jXFNATKIpbv9OSy3TLIc1im0DFjn0Q9QYytSPXvkX1S0CUNMW+2FMnwQxlFKgClMBueFc5sUeCh9fAP1F5tIi0TmvGOBQwp//UNhXzw50hLEKQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722198671; c=relaxed/simple; bh=XwREC3Zn27Mwzwot+SrxEwvb50Hp1zKL3+sNJmz6Mf8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=f1QuL3J8egZ/Ls8/5PhGRDAa1KT94DK6U5V2YbmYVjT42zLNezXHHTfP0LKVfmql++DBTnTo25h3rz2qpFQqCMB6r5yynA3O7IiUyqJ3DjkkB24wHMJFKDEDGjLMujP2OLaVxtQHGnkfXnaeEHSjECvSPp7uvqPu10PMCKHaxlU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--xur.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=GB13msEA; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--xur.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="GB13msEA" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-66b3b4415c7so46182047b3.0 for ; Sun, 28 Jul 2024 13:31:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722198667; x=1722803467; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=c7mCEB24MiuOLEIX0+MZEpfyFZDjGobAIp2IOnV2iDg=; b=GB13msEAQC9SelAKNqj0jhCnF/f7CXgWeNjXaCTJdr0HVqMc4IRDdnx2UvEpdMJqzH QuQhdd00u26CCHwQQXO1koV65Ri4xMT69l+gVS6BAMBhMfNBvrlixM/xuF+0V3C68yQT /9wUCm7oIlNcx9ho4c9M5QUJHmO2j0ColfLeYEK+/kvqvCIWaLII0+c7MeAtMDpGOqEq bQ2+eigJZdM6nsHhnibaDH7KpjxF5L1KuJz9++mJAu5TB+TYu+Eb/xSGUu98KKNEz/9/ zn/zHq0xkLMcdjJ2bB/tHeyZzaDC1WQ0KX3zsF3Dxm4aJNo/PbQjsKHXZTdxtK7TX+V1 JePg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722198667; x=1722803467; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=c7mCEB24MiuOLEIX0+MZEpfyFZDjGobAIp2IOnV2iDg=; b=IzXrZHVYfM54AJCDesjazMDUyUb/CziBVb258As5wmxnx3uc2f+ZtY+BN29anXnLWQ VFhluo50W79ZxQIzSSJJtcQcIaGOALOM4xpPSrjX7Cnz4CqLKrLfx0ZmP7p5/l732Z/i yT4rPcJ5aeNg1gFgA+5lymzZ8xD3Q+d9nCctsc9C4atY49c9aA7wn77EPHQVJThHeOV5 P6kb55270yXagSsmGLj6416NNeX0te5QQkY7uqEuFU1geFnJ41ntNKNDICHjTYylsjdi DYREaKPG21MKV0mquNx3ZbR/7ydKpaL8UASOIzHnMXByCN4leRlYFaHadcnQVXT9/PvL AwUA== X-Forwarded-Encrypted: i=1; AJvYcCXG8aRyLTiV483wZgrOKho9gQxas47SCnKfxoxThkhdRJuxk9as1MwwCzmH48AKuokLg1eAkxITF7Yatx5iXpxdlwDO3LsE087/BeJ4 X-Gm-Message-State: AOJu0Ywbeb/j9SXaGxlHl4DvdEi/jp6z3S0dM40zNvuqOxk+TBuEuA4A lQ2t8qihHiDXuKKIM7as0SjrMJADH7iWNir15vJwh+0RUlEv9YdePcp6yLLkiD7seg== X-Google-Smtp-Source: AGHT+IGu4sbDUjEAKDB0hLyn3rxjDGmQnEZfdZL/ZgIho/aHfAuBV4gpPSxV5Bc3IDQzXkaJsNIU3DI= X-Received: from xur.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:2330]) (user=xur job=sendgmr) by 2002:a05:6902:1029:b0:e0b:9b5:8647 with SMTP id 3f1490d57ef6-e0b544ec4ddmr11322276.8.1722198666571; Sun, 28 Jul 2024 13:31:06 -0700 (PDT) Date: Sun, 28 Jul 2024 13:29:59 -0700 In-Reply-To: <20240728203001.2551083-1-xur@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240728203001.2551083-1-xur@google.com> X-Mailer: git-send-email 2.46.0.rc1.232.g9752f9e123-goog Message-ID: <20240728203001.2551083-7-xur@google.com> Subject: [PATCH 6/6] Add Propeller configuration for kernel build. From: Rong Xu To: Rong Xu , Han Shen , Sriraman Tallam , David Li , Jonathan Corbet , Masahiro Yamada , Nathan Chancellor , Nicolas Schier , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H . Peter Anvin" , Ard Biesheuvel , Arnd Bergmann , Josh Poimboeuf , Peter Zijlstra , Nick Desaulniers , Bill Wendling , Justin Stitt , Vegard Nossum , John Moon , Andrew Morton , Heiko Carstens , Luis Chamberlain , Samuel Holland , Mike Rapoport , "Paul E . McKenney" , Rafael Aquini , Petr Pavlu , Eric DeVolder , Bjorn Helgaas , Randy Dunlap , Benjamin Segall , Breno Leitao , Wei Yang , Brian Gerst , Juergen Gross , Palmer Dabbelt , Alexandre Ghiti , Kees Cook , Sami Tolvanen , Xiao Wang , Jan Kiszka Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-efi@vger.kernel.org, linux-arch@vger.kernel.org, llvm@lists.linux.dev, Krzysztof Pszeniczny , Stephane Eranian Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add the build support for using Clang's Propeller optimizer. Like AutoFDO, Propeller uses hardware sampling to gather information about the frequency of execution of different code paths within a binary. This information is then used to guide the compiler's optimization decisions, resulting in a more efficient binary. The support requires a Clang compiler LLVM 19 or later, and the create_llvm_prof tool (https://github.com/google/autofdo/releases/tag/v0.30.1). This submission is limited to x86 platforms that support PMU features like LBR on Intel machines and AMD Zen3 BRS. For Arm, we plan to send patches for SPE-based Propeller when AutoFDO for Arm is ready. Here is an example workflow for building an AutoFDO+Propeller optimized kernel: 1) Build the kernel on the HOST machine, with AutoFDO and Propeller build config CONFIG_AUTOFDO_CLANG=3Dy CONFIG_PROPELLER_CLANG=3Dy then $ make LLVM=3D1 CLANG_AUTOFDO_PROFILE=3D =E2=80=9C=E2=80=9D is the profile collected when doing a n= on-Propeller AutoFDO build. This step builds a kernel that has the same optimization level as AutoFDO, plus a metadata section that records basic block information. This kernel image runs as fast as an AutoFDO optimized kernel. 2) Install the kernel on test/production machines. 3) Run the load tests. The '-c' option in perf specifies the sample event period. We suggest using a suitable prime number, like 500009, for this purpose. For Intel platforms: $ perf record -e BR_INST_RETIRED.NEAR_TAKEN:k -a -N -b -c \ -o -- For AMD platforms: The supported system are: Zen3 with BRS, or Zen4 with amd_lbr_v2 # To see if Zen3 support LBR: $ cat proc/cpuinfo | grep " brs" # To see if Zen4 support LBR: $ cat proc/cpuinfo | grep amd_lbr_v2 # If the result is yes, then collect the profile using: $ perf record --pfm-events RETIRED_TAKEN_BRANCH_INSTRUCTIONS:k -a \ -N -b -c -o -- 4) (Optional) Download the raw perf file to the HOST machine. 5) Generate Propeller profile: $ create_llvm_prof --binary=3D --profile=3D \ --format=3Dpropeller --propeller_output_module_name \ --out=3D_cc_profile.txt \ --propeller_symorder=3D_ld_profile.txt =E2=80=9Ccreate_llvm_prof=E2=80=9D is the profile conversion tool, and a= prebuilt binary for linux can be found on https://github.com/google/autofdo/releases/tag/v0.30.1 (can also build from source). "" can be something like "/home/user/dir/any_string". This command generates a pair of Propeller profiles: "_cc_profile.txt" and "_ld_profile.txt". 6) Rebuild the kernel using the AutoFDO and Propeller profile files. CONFIG_AUTOFDO_CLANG=3Dy CONFIG_PROPELLER_CLANG=3Dy and $ make LLVM=3D1 CLANG_AUTOFDO_PROFILE=3D \ CLANG_PROPELLER_PROFILE_PREFIX=3D Co-developed-by: Han Shen Signed-off-by: Han Shen Signed-off-by: Rong Xu Suggested-by: Sriraman Tallam Suggested-by: Krzysztof Pszeniczny Suggested-by: Nick Desaulniers Suggested-by: Stephane Eranian --- Documentation/dev-tools/index.rst | 1 + Documentation/dev-tools/propeller.rst | 188 ++++++++++++++++++++++++++ MAINTAINERS | 7 + Makefile | 1 + arch/Kconfig | 22 +++ arch/x86/Kconfig | 1 + arch/x86/boot/compressed/Makefile | 3 + arch/x86/kernel/vmlinux.lds.S | 4 + arch/x86/platform/efi/Makefile | 1 + drivers/firmware/efi/libstub/Makefile | 2 + include/asm-generic/vmlinux.lds.h | 8 +- scripts/Makefile.lib | 10 ++ scripts/Makefile.propeller | 25 ++++ tools/objtool/check.c | 1 + 14 files changed, 270 insertions(+), 4 deletions(-) create mode 100644 Documentation/dev-tools/propeller.rst create mode 100644 scripts/Makefile.propeller diff --git a/Documentation/dev-tools/index.rst b/Documentation/dev-tools/in= dex.rst index 46636e4efe15..16e33eadb73b 100644 --- a/Documentation/dev-tools/index.rst +++ b/Documentation/dev-tools/index.rst @@ -33,6 +33,7 @@ Documentation/dev-tools/testing-overview.rst ktap checkuapi autofdo + propeller =20 =20 .. only:: subproject and html diff --git a/Documentation/dev-tools/propeller.rst b/Documentation/dev-tool= s/propeller.rst new file mode 100644 index 000000000000..15ef0e6d973e --- /dev/null +++ b/Documentation/dev-tools/propeller.rst @@ -0,0 +1,188 @@ +.. SPDX-License-Identifier: GPL-2.0 + +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +Using Propeller with the Linux kernel +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +This enables Propeller build support for the kernel when using Clang +compiler. Propeller is a profile-guided optimization (PGO) method used +to optimize binary executables. Like AutoFDO, it utilizes hardware +sampling to gather information about the frequency of execution of +different code paths within a binary. Unlike AutoFDO, this information +is then used right before linking phase to optimize (among others) +block layout within and across functions. + +A few important notes about adopting Propeller optimization: + +#. Although it can be used as a standalone optimization step, it is + strongly recommended to apply Propeller on top of AutoFDO, + AutoFDO+ThinLTO or Instrument FDO. The rest of this document + assumes this paradigm. + +#. Propeller uses another round of profiling on top of + AutoFDO/AutoFDO+ThinLTO/iFDO. The whole build process involves + "build-afdo - train-afdo - build-propeller - train-propeller - + build-optimized". + +#. Propeller requires LLVM 19 release or later for Clang/Clang++ + and the linker(ld.lld). + +#. In addition to LLVM toolchain, Propeller requires a profiling + conversion tool: https://github.com/google/autofdo with a release + after v0.30.1: https://github.com/google/autofdo/releases/tag/v0.30.1. + +The Propeller optimization process involves the following steps: + +#. Initial building: Build the AutoFDO or AutoFDO+ThinLTO binary as + you would normally do, but with a set of compile-time / link-time + flags, so that a special metadata section is created within the + kernel binary. The special section is only intend to be used by the + profiling tool, it is not part of the runtime image, nor does it + change kernel run time text sections. + +#. Profiling: The above kernel is then run with a representative + workload to gather execution frequency data. This data is collected + using hardware sampling, via perf. Propeller is most effective on + platforms supporting advanced PMU features like LBR on Intel + machines. This step is the same as profiling the kernel for AutoFDO + (the exact perf parameters can be different). + +#. Propeller profile generation: Perf output file is converted to a + pair of Propeller profiles via an offline tool. + +#. Optimized build: Build the AutoFDO or AutoFDO+ThinLTO optimized + binary as you would normally do, but with a compile-time / + link-time flag to pick up the Propeller compile time and link time + profiles. This build step uses 3 profiles - the AutoFDO profile, + the Propeller compile-time profile and the Propeller link-time + profile. + +#. Deployment: The optimized kernel binary is deployed and used + in production environments, providing improved performance + and reduced latency. + +Preparation +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +Configure the kernel with: + + .. code-block:: make + + CONFIG_AUTOFDO_CLANG=3Dy + CONFIG_PROPELLER_CLANG=3Dy + +Customization +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +You can enable or disable Propeller build for individual file and +directories by adding a line similar to the following to the +respective kernel Makefile: + +- For enabling a single file (e.g. foo.o) + + .. code-block:: make + + PROPELLER_PROFILE_foo.o :=3D y + +- For enabling all files in one directory + + .. code-block:: make + + PROPELLER_PROFILE :=3D y + +- For disabling one file + + .. code-block:: make + + PROPELLER_PROFILE_foo.o :=3D n + +- For disabling all files in one directory + + .. code-block:: make + + PROPELLER__PROFILE :=3D n + + +Workflow +=3D=3D=3D=3D=3D=3D=3D=3D + +Here is an example workflow for building an AutoFDO+Propeller kernel: + +1) Assuming an AutoFDO profile is already collected following + instructions in the AutoFDO document, build the kernel on the HOST + machine, with AutoFDO and Propeller build configs: + + .. code-block:: make + + CONFIG_AUTOFDO_CLANG=3Dy + CONFIG_PROPELLER_CLANG=3Dy + + and + + .. code-block:: sh + + $ make LLVM=3D1 CLANG_AUTOFDO_PROFILE=3D + +2) Install the kernel on the TEST machine. + +3) Run the load tests. The '-c' option in perf specifies the sample + event period. We suggest using a suitable prime number, like 500009, + for this purpose. + + - For Intel platforms: + + .. code-block:: sh + + $ perf record -e BR_INST_RETIRED.NEAR_TAKEN:k -a -N -b -c \ + -o -- + + - For AMD platforms: + + .. code-block:: sh + + $ perf record --pfm-event RETIRED_TAKEN_BRANCH_INSTRUCTIONS:k \ + -a -N -b -c -o -- + + Note you can repeat the above steps to collect multiple s. + +4) (Optional) Download the raw perf file(s) to the HOST machine. + +5) Use the create_llvm_prof tool (https://github.com/google/autofdo) to Ge= nerate Propeller profile. + + .. code-block:: sh + + $ create_llvm_prof --binary=3D --profile=3D \ + --format=3Dpropeller --propeller_output_module= _name \ + --out=3D_cc_profile.= txt \ + --propeller_symorder=3D_ld_profile.txt + + "" can be something like + "/home/user/dir/any_string". + + This command generates a pair of Propeller profiles: + "_cc_profile.txt" and + "_ld_profile.txt". + + If there are more than 1 perf_file collected in the previous step, + you can create a temp list file "" with each line + containing one perf file name and run: + + .. code-block:: sh + + $ create_llvm_prof --binary=3D --profile=3D@ \ + --format=3Dpropeller --propeller_output_module= _name \ + --out=3D_cc_profile.= txt \ + --propeller_symorder=3D_ld_profile.txt + +6) Rebuild the kernel using the AutoFDO and Propeller profiles. + + .. code-block:: make + + CONFIG_AUTOFDO_CLANG=3Dy + CONFIG_PROPELLER_CLANG=3Dy + + and + + .. code-block:: sh + + $ make LLVM=3D1 CLANG_AUTOFDO_PROFILE=3D CLANG_PROP= ELLER_PROFILE_PREFIX=3D diff --git a/MAINTAINERS b/MAINTAINERS index 8a89e7f0d9d5..0c7f3cebe4fe 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -17974,6 +17974,13 @@ S: Maintained F: include/linux/psi* F: kernel/sched/psi.c =20 +PROPELLER BUILD +M: Rong Xu +M: Han Shen +S: Supported +F: Documentation/dev-tools/propeller.rst +F: scripts/Makefile.propeller + PRINTK M: Petr Mladek R: Steven Rostedt diff --git a/Makefile b/Makefile index 5ae30cc94a26..85a96d973f20 100644 --- a/Makefile +++ b/Makefile @@ -1025,6 +1025,7 @@ include-$(CONFIG_KCOV) +=3D scripts/Makefile.kcov include-$(CONFIG_RANDSTRUCT) +=3D scripts/Makefile.randstruct include-$(CONFIG_GCC_PLUGINS) +=3D scripts/Makefile.gcc-plugins include-$(CONFIG_AUTOFDO_CLANG) +=3D scripts/Makefile.autofdo +include-$(CONFIG_PROPELLER_CLANG) +=3D scripts/Makefile.propeller =20 include $(addprefix $(srctree)/, $(include-y)) =20 diff --git a/arch/Kconfig b/arch/Kconfig index e12599c4ab63..5b136e904400 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -822,6 +822,28 @@ config AUTOFDO_CLANG =20 If unsure, say N. =20 +config ARCH_SUPPORTS_PROPELLER_CLANG + bool + +config PROPELLER_CLANG + bool "Enable Clang's Propeller build" + depends on ARCH_SUPPORTS_PROPELLER_CLANG + depends on AUTOFDO_CLANG + depends on CC_IS_CLANG && CLANG_VERSION >=3D 190000 + help + This option enables Clang=E2=80=99s Propeller build which + is on top of AutoFDO build. When the Propeller profiles + is specified in variable CLANG_PROPELLER_PROFILE_PREFIX + during the build process, Clang uses the profiles to + optimize the kernel. + + If no profile is specified, Proepller options are + still passed to Clang to facilitate the collection + of perf data for creating the Propeller profiles in + subsequent builds. + + If unsure, say N. + config ARCH_SUPPORTS_CFI_CLANG bool help diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index dca526b1364f..6fb5269d39b0 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -123,6 +123,7 @@ config X86 select ARCH_SUPPORTS_LTO_CLANG select ARCH_SUPPORTS_LTO_CLANG_THIN select ARCH_SUPPORTS_AUTOFDO_CLANG + select ARCH_SUPPORTS_PROPELLER_CLANG if X86_64 select ARCH_USE_BUILTIN_BSWAP select ARCH_USE_CMPXCHG_LOCKREF if X86_CMPXCHG64 select ARCH_USE_MEMTEST diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/M= akefile index f2051644de94..35d19b4e6361 100644 --- a/arch/x86/boot/compressed/Makefile +++ b/arch/x86/boot/compressed/Makefile @@ -17,6 +17,9 @@ # (see scripts/Makefile.lib size_append) # compressed vmlinux.bin.all + u32 size of vmlinux.bin.all =20 +# Do not run Propeller optimizer for early boot code. +PROPELLER_PROFILE :=3D n + targets :=3D vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 vmlinux.bi= n.lzma \ vmlinux.bin.xz vmlinux.bin.lzo vmlinux.bin.lz4 vmlinux.bin.zst =20 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S index 3509afc6a672..167dd05323cf 100644 --- a/arch/x86/kernel/vmlinux.lds.S +++ b/arch/x86/kernel/vmlinux.lds.S @@ -440,6 +440,10 @@ SECTIONS =20 STABS_DEBUG DWARF_DEBUG +#ifdef CONFIG_PROPELLER_CLANG + .llvm_bb_addr_map : { *(.llvm_bb_addr_map) } +#endif + ELF_DETAILS =20 DISCARDS diff --git a/arch/x86/platform/efi/Makefile b/arch/x86/platform/efi/Makefile index 543df9a1379d..e0c846b6d636 100644 --- a/arch/x86/platform/efi/Makefile +++ b/arch/x86/platform/efi/Makefile @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 KASAN_SANITIZE :=3D n GCOV_PROFILE :=3D n +PROPELLER_PROFILE :=3D n =20 obj-$(CONFIG_EFI) +=3D memmap.o quirks.o efi.o efi_$(BITS).o \ efi_stub_$(BITS).o diff --git a/drivers/firmware/efi/libstub/Makefile b/drivers/firmware/efi/l= ibstub/Makefile index 06f0428a723c..55ca5250df1a 100644 --- a/drivers/firmware/efi/libstub/Makefile +++ b/drivers/firmware/efi/libstub/Makefile @@ -56,6 +56,8 @@ KBUILD_CFLAGS :=3D $(filter-out $(CC_FLAGS_CFI), $(KBUILD= _CFLAGS)) # disable LTO KBUILD_CFLAGS :=3D $(filter-out $(CC_FLAGS_LTO), $(KBUILD_CFLAGS)) =20 +PROPELLER_PROFILE :=3D n + lib-y :=3D efi-stub-helper.o gop.o secureboot.o tpm.o \ file.o mem.o random.o randomalloc.o pci.o \ skip_spaces.o lib-cmdline.o lib-ctype.o \ diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinu= x.lds.h index 7d9dc8a3c046..ea3d8bf51edd 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -95,14 +95,14 @@ * With LTO_CLANG, the linker also splits sections by default, so we need * these macros to combine the sections during the final link. * - * With LTO_CLANG, the linker also splits sections by default, so we need - * these macros to combine the sections during the final link. + * CONFIG_AUTOFD_CLANG and CONFIG_PROPELLER_CLANG will also split text sec= tions + * and cluster them in the linking time. * * 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_CL= ANG) || \ -defined(CONFIG_AUTOFDO_CLANG) +defined(CONFIG_AUTOFDO_CLANG) || defined(CONFIG_PROPELLER_CLANG) #define TEXT_MAIN .text .text.[0-9a-zA-Z_]* #else #define TEXT_MAIN .text @@ -612,7 +612,7 @@ defined(CONFIG_AUTOFDO_CLANG) * first when in these builds. */ #if defined(CONFIG_LD_DEAD_CODE_DATA_ELIMINATION) || defined(CONFIG_LTO_CL= ANG) || \ -defined(CONFIG_AUTOFDO_CLANG) +defined(CONFIG_AUTOFDO_CLANG) || defined(CONFIG_PROPELLER_CLANG) #define TEXT_TEXT \ *(.text.asan.* .text.tsan.*) \ *(.text.unknown .text.unknown.*) \ diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index c2cab5adaf25..e239fa709c20 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -219,6 +219,16 @@ _c_flags +=3D $(if $(patsubst n%,, \ $(CFLAGS_AUTOFDO_CLANG)) endif =20 +# +# Enable Clang's Propeller build flags for a file or directory depending on +# variables AUTOFDO_PROPELLER_obj.o and PROPELLER_PROFILE. +# +ifeq ($(CONFIG_PROPELLER_CLANG),y) +_c_flags +=3D $(if $(patsubst n%,, \ + $(AUTOFDO_PROFILE_$(basetarget).o)$(AUTOFDO_PROFILE)$(PGO_PROFILE)$(PROPE= LLER_PROFILE)y), \ + $(CFLAGS_PROPELLER_CLANG)) +endif + # $(src) for including checkin headers from generated source files # $(obj) for including generated headers from checkin source files ifeq ($(KBUILD_EXTMOD),) diff --git a/scripts/Makefile.propeller b/scripts/Makefile.propeller new file mode 100644 index 000000000000..0c9318be5f64 --- /dev/null +++ b/scripts/Makefile.propeller @@ -0,0 +1,25 @@ +# SPDX-License-Identifier: GPL-2.0 + +# Enable available and selected Clang Propeller features. +# Propeller required debug information to embed module names in the profil= es. +CFLAGS_PROPELLER_CLANG :=3D -fdebug-info-for-profiling + +ifdef CLANG_PROPELLER_PROFILE_PREFIX +CFLAGS_PROPELLER_CLANG +=3D -fbasic-block-sections=3Dlist=3D$(CLANG_PROPEL= LER_PROFILE_PREFIX)_cc_profile.txt -ffunction-sections +KBUILD_LDFLAGS +=3D --symbol-ordering-file=3D$(CLANG_PROPELLER_PROFILE_PRE= FIX)_ld_profile.txt --no-warn-symbol-ordering +else +CFLAGS_PROPELLER_CLANG +=3D -fbasic-block-sections=3Dlabels +endif + +ifdef CONFIG_LTO_CLANG +ifdef CONFIG_LTO_CLANG_THIN +ifdef CLANG_PROPELLER_PROFILE_PREFIX +KBUILD_LDFLAGS +=3D --lto-basic-block-sections=3D$(CLANG_PROPELLER_PROFILE= _PREFIX)_cc_profile.txt +else +KBUILD_LDFLAGS +=3D --lto-basic-block-sections=3Dlabels +endif +endif +else +endif + +export CFLAGS_PROPELLER_CLANG diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 254913498c3c..7cea8ba53cf4 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -4489,6 +4489,7 @@ static int validate_ibt(struct objtool_file *file) !strcmp(sec->name, "__mcount_loc") || !strcmp(sec->name, ".kcfi_traps") || !strcmp(sec->name, ".llvm.call-graph-profile") || + !strcmp(sec->name, ".llvm_bb_addr_map") || strstr(sec->name, "__patchable_function_entries")) continue; =20 --=20 2.46.0.rc1.232.g9752f9e123-goog