From a0d7be4ab3ece46919418c57d0de4b6fd4ce7590 Mon Sep 17 00:00:00 2001 From: Piyush Patle Date: Sat, 11 Apr 2026 03:42:54 +0530 Subject: [PATCH 01/31] kbuild: document generation of offset header files Replace the placeholder reference with a description of how Kbuild generates offset header files such as include/generated/asm-offsets.h. Remove the corresponding TODO entry now that this is documented. Signed-off-by: Piyush Patle Reviewed-by: Nicolas Schier Link: https://patch.msgid.link/20260410221257.191517-1-piyushpatle228@gmail.com Signed-off-by: Nathan Chancellor --- Documentation/kbuild/makefiles.rst | 41 ++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/Documentation/kbuild/makefiles.rst b/Documentation/kbuild/makefiles.rst index 24a4708d26e8..7521cae7d56f 100644 --- a/Documentation/kbuild/makefiles.rst +++ b/Documentation/kbuild/makefiles.rst @@ -1285,8 +1285,39 @@ Example:: In this example, the file target maketools will be processed before descending down in the subdirectories. -See also chapter XXX-TODO that describes how kbuild supports -generating offset header files. +Generating offset header files +------------------------------ + +The ``include/generated/asm-offsets.h`` header exposes C structure +member offsets and other compile-time constants to assembly code. It +is generated from ``arch/$(SRCARCH)/kernel/asm-offsets.c``. + +The source file uses ``DEFINE()``, ``OFFSET()``, ``BLANK()`` and +``COMMENT()`` from ````. These emit marker strings +through inline asm that Kbuild extracts from the compiled assembly +output. + +Example:: + + #include + #include + + int main(void) + { + OFFSET(TSK_ACTIVE_MM, task_struct, active_mm); + DEFINE(THREAD_SIZE, THREAD_SIZE); + BLANK(); + return 0; + } + +The rules are defined in the top-level ``Kbuild`` and +``scripts/Makefile.lib``. The header is built during Kbuild's +``prepare`` phase, after ``archprepare`` and before descending into +subdirectories. + +The same mechanism generates ``include/generated/bounds.h`` from +``kernel/bounds.c`` and ``include/generated/rq-offsets.h`` from +``kernel/sched/rq-offsets.c``. List directories to visit when descending ----------------------------------------- @@ -1690,9 +1721,3 @@ Credits - Updates by Kai Germaschewski - Updates by Sam Ravnborg - Language QA by Jan Engelhardt - -TODO -==== - -- Generating offset header files. -- Add more variables to chapters 7 or 9? From 7abef41afad05be1a4b2a3303b9ecf62403463a1 Mon Sep 17 00:00:00 2001 From: Petr Pavlu Date: Fri, 10 Apr 2026 15:13:29 +0200 Subject: [PATCH 02/31] kbuild/btf: Remove broken module relinking exclusion Commit 5f9ae91f7c0d ("kbuild: Build kernel module BTFs if BTF is enabled and pahole supports it") in 2020 introduced CONFIG_DEBUG_INFO_BTF_MODULES to enable generation of split BTF for kernel modules. This change required the %.ko Makefile rule to additionally depend on vmlinux, which is used as a base for deduplication. The regular ld_ko_o command executed by the rule was then modified to be skipped if only vmlinux changes. This was done by introducing a new if_changed_except command and updating the original call to '+$(call if_changed_except,ld_ko_o,vmlinux)'. Later, commit 214c0eea43b2 ("kbuild: add $(objtree)/ prefix to some in-kernel build artifacts") in 2024 updated the rule's reference to vmlinux from 'vmlinux' to '$(objtree)/vmlinux'. This accidentally broke the previous logic to skip relinking modules if only vmlinux changes. The issue is that '$(objtree)' is typically '.' and GNU Make normalizes the resulting prerequisite './vmlinux' to just 'vmlinux', while the exclusion logic retains the raw './vmlinux'. As a result, if_changed_except doesn't correctly filter out vmlinux. Consequently, with CONFIG_DEBUG_INFO_BTF_MODULES=y, modules are relinked even if only vmlinux changes. It is possible to fix this Makefile issue. However, having the %.ko rule update the resulting file in place without starting from the original inputs is rather fragile. The logic is harder to debug if something breaks during a subsequent .ko update because the old input is lost due to the overwrite. Additionally, it requires that the BTF processing is idempotent. For example, sorting id+flags BTF_SET8 pairs in .BTF_ids by resolve_btfids currently doesn't have this property. One option is to split the %.ko target into two rules: the first for partial linking and the second one for generating the BTF data. However, this approach runs into an issue with requiring additional intermediate files, which increases the size of the build directory. On my system, when using a large distribution config with ~5500 modules, the size of the build directory with debuginfo enabled is already ~25 GB, with .ko files occupying ~8 GB. Duplicating these .ko files doesn't seem practical. Measuring the speed of the %.ko processing shows that the link step is actually relatively fast. It takes about 20% of the overall rule time, while the BTF processing accounts for 80%. Moreover, skipping the link part becomes relevant only during local development. In such cases, developers typically use configs that enable a limited number of modules, so having the %.ko rule slightly slower doesn't significantly impact the total rebuild time. This is supported by the fact that no one has complained about this optimization being broken for the past two years. Therefore, remove the logic that prevents module relinking when only vmlinux changes and simplify Makefile.modfinal. Signed-off-by: Petr Pavlu Reviewed-by: Alan Maguire Tested-by: Alan Maguire Acked-by: Ihor Solodrai Link: https://patch.msgid.link/20260410131343.2519532-1-petr.pavlu@suse.com Signed-off-by: Nathan Chancellor --- scripts/Makefile.modfinal | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/scripts/Makefile.modfinal b/scripts/Makefile.modfinal index adcbcde16a07..01a37ec872b9 100644 --- a/scripts/Makefile.modfinal +++ b/scripts/Makefile.modfinal @@ -46,17 +46,9 @@ quiet_cmd_btf_ko = BTF [M] $@ $(CONFIG_SHELL) $(srctree)/scripts/gen-btf.sh --btf_base $(objtree)/vmlinux $@; \ fi; -# Same as newer-prereqs, but allows to exclude specified extra dependencies -newer_prereqs_except = $(filter-out $(PHONY) $(1),$?) - -# Same as if_changed, but allows to exclude specified extra dependencies -if_changed_except = $(if $(call newer_prereqs_except,$(2))$(cmd-check), \ - $(cmd); \ - printf '%s\n' 'savedcmd_$@ := $(make-cmd)' > $(dot-target).cmd, @:) - # Re-generate module BTFs if either module's .ko or vmlinux changed %.ko: %.o %.mod.o .module-common.o $(objtree)/scripts/module.lds $(and $(CONFIG_DEBUG_INFO_BTF_MODULES),$(KBUILD_BUILTIN),$(objtree)/vmlinux) FORCE - +$(call if_changed_except,ld_ko_o,$(objtree)/vmlinux) + +$(call if_changed,ld_ko_o) ifdef CONFIG_DEBUG_INFO_BTF_MODULES +$(if $(newer-prereqs),$(call cmd,btf_ko)) endif From b9d21c32dca2167a614e66c9e27999b9e1c33d55 Mon Sep 17 00:00:00 2001 From: Xingjing Deng Date: Fri, 6 Mar 2026 02:17:09 +0000 Subject: [PATCH 03/31] kconfig: fix potential NULL pointer dereference in conf_askvalue In conf_askvalue(), the 'def' argument (retrieved via sym_get_string_value) can be NULL. While current call sites ensure that 'def' is valid, calling printf("%s\n", def) is technically undefined behavior and could lead to a segmentation fault on certain libc implementations if the function were called with a NULL pointer in the future. Improve the robustness of conf_askvalue() by providing an empty string as a fallback. Additionally, remove the redundant re-initialization of the 'line' buffer inside the !sym_is_changeable(sym) block, as it is already properly initialized at the function entry. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Xingjing Deng Reviewed-by: Nathan Chancellor Link: https://patch.msgid.link/20260306021709.27068-1-micro6947@gmail.com Signed-off-by: Nathan Chancellor --- scripts/kconfig/conf.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c index a7b44cd8ae14..c368bec5ab60 100644 --- a/scripts/kconfig/conf.c +++ b/scripts/kconfig/conf.c @@ -297,9 +297,7 @@ static int conf_askvalue(struct symbol *sym, const char *def) line[1] = 0; if (!sym_is_changeable(sym)) { - printf("%s\n", def); - line[0] = '\n'; - line[1] = 0; + printf("%s\n", def ?: ""); return 0; } @@ -307,7 +305,7 @@ static int conf_askvalue(struct symbol *sym, const char *def) case oldconfig: case syncconfig: if (sym_has_value(sym)) { - printf("%s\n", def); + printf("%s\n", def ?: ""); return 0; } /* fall through */ From 2c31897a17e55a6da529b4e797e98c6febc60fd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= Date: Wed, 18 Mar 2026 21:37:20 +0100 Subject: [PATCH 04/31] kbuild: pacman-pkg: package unstripped vDSO libraries MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The unstripped vDSO files are useful for debugging. They are provided in the upstream 'linux-headers' package. Also package them as part of 'make pacman-pkg'. Make them part of the '-debug' package, as they fit there best. This differs from the upstream package as that has no '-debug' variant. Signed-off-by: Thomas Weißschuh Reviewed-by: Nathan Chancellor Tested-by: Nathan Chancellor Link: https://patch.msgid.link/20260318-kbuild-pacman-vdso-install-v1-1-48ceb31c0e80@weissschuh.net Signed-off-by: Nathan Chancellor --- scripts/package/PKGBUILD | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/package/PKGBUILD b/scripts/package/PKGBUILD index 452374d63c24..b1d0c8a9f030 100644 --- a/scripts/package/PKGBUILD +++ b/scripts/package/PKGBUILD @@ -121,6 +121,9 @@ _package-debug(){ install -Dt "${debugdir}" -m644 vmlinux mkdir -p "${builddir}" ln -sr "${debugdir}/vmlinux" "${builddir}/vmlinux" + + echo "Installing unstripped vDSO(s)..." + ${MAKE} INSTALL_MOD_PATH="${pkgdir}/usr" vdso_install } for _p in "${pkgname[@]}"; do From ce3267a39a92be732429fa1a1f6d95a807a31fa7 Mon Sep 17 00:00:00 2001 From: Nathan Chancellor Date: Sun, 17 May 2026 13:05:04 -1000 Subject: [PATCH 05/31] kbuild: Bump minimum version of LLVM for building the kernel to 17.0.1 The current minimum version of LLVM for building the kernel is 15.0.0. However, there are two deficiencies compared to GCC that were fixed in LLVM 17 that are starting to become more noticeable. The first was a bug in LLVM's scope checker [1], where all labels in a function were validated as potential targets of an asm goto statement, even if they were not listed in the asm goto statement as targets. This becomes particularly problematic when the cleanup attribute is used, as asm goto(... : label_a); ... label_a: ... int var __free(foo); asm goto(... : label_b); ... label_b: ... will trigger an error since the scope checker will complain that the cleanup variable would be skipped when jumping from the first asm goto to label_b (which obviously cannot happen). This issue was the catalyst for commit e2ffa15b9baa ("kbuild: Disable CC_HAS_ASM_GOTO_OUTPUT on clang < 17"). Unfortunately, this issue is reproducible with regular asm goto in addition to asm goto with outputs, so that change was not entirely sufficient to avoid the issue altogether. As asm goto has effectively been required since commit a0a12c3ed057 ("asm goto: eradicate CC_HAS_ASM_GOTO") and the usage of the cleanup attribute continues to grow across the tree, raising the minimum to a version that avoids this issue altogether is a better long term solution than attempting to workaround it at every spot where it happens. The second issue is an incompatibility with GCC 8.1+ around variables marked with const being valid constant expressions for _Static_assert and other macros [2]. With GCC 8.1 being the minimum supported version since commit 118c40b7b503 ("kbuild: require gcc-8 and binutils-2.30"), this incompatibility becomes more of a maintenance burden since only clang-15 and clang-16 are affected by it. Looking at the clang version of various major distributions through Docker images, no one should be left behind as a result of this bump, as the old ones cannot clear the current minimum of 15.0.0. archlinux:latest clang version 22.1.3 debian:oldoldstable-slim Debian clang version 11.0.1-2 debian:oldstable-slim Debian clang version 14.0.6 debian:stable-slim Debian clang version 19.1.7 (3+b1) debian:testing-slim Debian clang version 21.1.8 (3+b1) debian:unstable-slim Debian clang version 21.1.8 (7+b1) fedora:42 clang version 20.1.8 (Fedora 20.1.8-4.fc42) fedora:latest clang version 21.1.8 (Fedora 21.1.8-4.fc43) fedora:44 clang version 22.1.1 (Fedora 22.1.1-2.fc44) fedora:rawhide clang version 22.1.3 (Fedora 22.1.3-1.fc45) opensuse/leap:latest clang version 17.0.6 opensuse/tumbleweed:latest clang version 21.1.8 ubuntu:jammy Ubuntu clang version 14.0.0-1ubuntu1.1 ubuntu:noble Ubuntu clang version 18.1.3 (1ubuntu1) ubuntu:questing Ubuntu clang version 20.1.8 (0ubuntu4) ubuntu:resolute Ubuntu clang version 21.1.8 (6ubuntu1) 17.0.1 is chosen as the minimum instead of 17.0.0 to ensure that the particular version of LLVM 17 has the two aforementioned bugs fixed, as the second was fixed during the 17.0.0 release candidate phase and it was not until LLVM 18 that LLVM adopted the scheme of x.0.0 being a prerelease version and x.1.0 is a release version [3] to help with scenarios such as this. Link: https://github.com/llvm/llvm-project/commit/f023f5cdb2e6c19026f04a15b5a935c041835d14 [1] Link: https://github.com/llvm/llvm-project/commit/0b2d5b967d98375793897295d651f58f6fbd3034 [2] Link: https://github.com/llvm/llvm-project/commit/4532617ae420056bf32f6403dde07fb99d276a49 [3] Acked-by: Nicolas Schier Link: https://patch.msgid.link/20260517-bump-minimum-supported-llvm-version-to-17-v2-1-b3b8cda46bdd@kernel.org Signed-off-by: Nathan Chancellor --- Documentation/process/changes.rst | 2 +- Documentation/translations/it_IT/process/changes.rst | 2 +- Documentation/translations/pt_BR/process/changes.rst | 2 +- scripts/min-tool-version.sh | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Documentation/process/changes.rst b/Documentation/process/changes.rst index 9a99037270ff..b9afce768446 100644 --- a/Documentation/process/changes.rst +++ b/Documentation/process/changes.rst @@ -36,7 +36,7 @@ bindgen (optional) 0.71.1 bindgen --version binutils 2.30 ld -v bison 2.0 bison --version btrfs-progs 0.18 btrfs --version -Clang/LLVM (optional) 15.0.0 clang --version +Clang/LLVM (optional) 17.0.1 clang --version e2fsprogs 1.41.4 e2fsck -V flex 2.5.35 flex --version gdb 7.2 gdb --version diff --git a/Documentation/translations/it_IT/process/changes.rst b/Documentation/translations/it_IT/process/changes.rst index 7e93833b4511..7ee54c972418 100644 --- a/Documentation/translations/it_IT/process/changes.rst +++ b/Documentation/translations/it_IT/process/changes.rst @@ -33,7 +33,7 @@ PC Card, per esempio, probabilmente non dovreste preoccuparvi di pcmciautils. Programma Versione minima Comando per verificare la versione ====================== ================= ======================================== GNU C 8.1 gcc --version -Clang/LLVM (optional) 13.0.0 clang --version +Clang/LLVM (optional) 17.0.1 clang --version Rust (opzionale) 1.78.0 rustc --version bindgen (opzionale) 0.65.1 bindgen --version GNU make 4.0 make --version diff --git a/Documentation/translations/pt_BR/process/changes.rst b/Documentation/translations/pt_BR/process/changes.rst index 1964c1c93b34..6bbfe60fd973 100644 --- a/Documentation/translations/pt_BR/process/changes.rst +++ b/Documentation/translations/pt_BR/process/changes.rst @@ -31,7 +31,7 @@ PC Card por exemplo, provavelmente não precisará se preocupar com o pcmciautil Programa Versão mínima Comando para verificar a versão ====================== =============== ======================================== GNU C 8.1 gcc --version -Clang/LLVM (optional) 15.0.0 clang --version +Clang/LLVM (optional) 17.0.1 clang --version Rust (optional) 1.78.0 rustc --version bindgen (optional) 0.65.1 bindgen --version GNU make 4.0 make --version diff --git a/scripts/min-tool-version.sh b/scripts/min-tool-version.sh index b96ec2d379b6..ea2689bc9641 100755 --- a/scripts/min-tool-version.sh +++ b/scripts/min-tool-version.sh @@ -27,7 +27,7 @@ llvm) if [ "$SRCARCH" = loongarch ]; then echo 18.0.0 else - echo 15.0.0 + echo 17.0.1 fi ;; rustc) From 813fe686e90b433b6d13cfd157b8008825193872 Mon Sep 17 00:00:00 2001 From: Nathan Chancellor Date: Sun, 17 May 2026 13:05:05 -1000 Subject: [PATCH 06/31] security/Kconfig.hardening: Remove tautological condition from CC_HAS_ZERO_CALL_USED_REGS Now that the minimum supported version of LLVM for building the kernel has been raised to 17.0.1, the '!Clang || Clang > 15.0.6' dependency for CONFIG_CC_HAS_ZERO_CALL_USED_REGS is always true, so it can be removed. Reviewed-by: Nicolas Schier Acked-by: Arnd Bergmann Link: https://patch.msgid.link/20260517-bump-minimum-supported-llvm-version-to-17-v2-2-b3b8cda46bdd@kernel.org Signed-off-by: Nathan Chancellor --- security/Kconfig.hardening | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/security/Kconfig.hardening b/security/Kconfig.hardening index 86f8768c63d4..4ab19f658bde 100644 --- a/security/Kconfig.hardening +++ b/security/Kconfig.hardening @@ -188,10 +188,8 @@ config INIT_ON_FREE_DEFAULT_ON synthetic workloads have measured as high as 8%. config CC_HAS_ZERO_CALL_USED_REGS + # supported by gcc-11 or newer and all supported versions of clang def_bool $(cc-option,-fzero-call-used-regs=used-gpr) - # https://github.com/ClangBuiltLinux/linux/issues/1766 - # https://github.com/llvm/llvm-project/issues/59242 - depends on !CC_IS_CLANG || CLANG_VERSION > 150006 config ZERO_CALL_USED_REGS bool "Enable register zeroing on function exit" From 8ad2017578c99ba7851bca5df52f82a3ade2e603 Mon Sep 17 00:00:00 2001 From: Nathan Chancellor Date: Sun, 17 May 2026 13:05:06 -1000 Subject: [PATCH 07/31] security/Kconfig.hardening: Remove tautological condition from FORTIFY_SOURCE Now that the minimum supported version of LLVM for building the kernel has been raised to 17.0.1, the '!X86_32 || !Clang || Clang > 16' dependency of CONFIG_FORTIFY_SOURCE is always true, so it can be removed. Reviewed-by: Nicolas Schier Link: https://patch.msgid.link/20260517-bump-minimum-supported-llvm-version-to-17-v2-3-b3b8cda46bdd@kernel.org Signed-off-by: Nathan Chancellor --- security/Kconfig.hardening | 2 -- 1 file changed, 2 deletions(-) diff --git a/security/Kconfig.hardening b/security/Kconfig.hardening index 4ab19f658bde..364c2ff553f6 100644 --- a/security/Kconfig.hardening +++ b/security/Kconfig.hardening @@ -214,8 +214,6 @@ menu "Bounds checking" config FORTIFY_SOURCE bool "Harden common str/mem functions against buffer overflows" depends on ARCH_HAS_FORTIFY_SOURCE - # https://github.com/llvm/llvm-project/issues/53645 - depends on !X86_32 || !CC_IS_CLANG || CLANG_VERSION >= 160000 help Detect overflows of buffers in common string and memory functions where the compiler can determine and validate the buffer sizes. From 9331258bc129a007a5f10e2a2b45d1e71624d115 Mon Sep 17 00:00:00 2001 From: Nathan Chancellor Date: Sun, 17 May 2026 13:05:07 -1000 Subject: [PATCH 08/31] security/Kconfig.hardening: Remove tautological condition from CC_HAS_RANDSTRUCT Now that the minimum supported version of LLVM for building the kernel has been raised to 17.0.1, the '!Clang || Clang >= 16' dependency for CONFIG_CC_HAS_RANDSTRUCT is always true, so it can be removed. Reviewed-by: Nicolas Schier Link: https://patch.msgid.link/20260517-bump-minimum-supported-llvm-version-to-17-v2-4-b3b8cda46bdd@kernel.org Signed-off-by: Nathan Chancellor --- security/Kconfig.hardening | 3 --- 1 file changed, 3 deletions(-) diff --git a/security/Kconfig.hardening b/security/Kconfig.hardening index 364c2ff553f6..6923036e1a2f 100644 --- a/security/Kconfig.hardening +++ b/security/Kconfig.hardening @@ -275,9 +275,6 @@ endmenu config CC_HAS_RANDSTRUCT def_bool $(cc-option,-frandomize-layout-seed-file=/dev/null) - # Randstruct was first added in Clang 15, but it isn't safe to use until - # Clang 16 due to https://github.com/llvm/llvm-project/issues/60349 - depends on !CC_IS_CLANG || CLANG_VERSION >= 160000 choice prompt "Randomize layout of sensitive kernel structures" From 2189cb1a80f06f9673874163a5720ae804f83f87 Mon Sep 17 00:00:00 2001 From: Nathan Chancellor Date: Sun, 17 May 2026 13:05:08 -1000 Subject: [PATCH 09/31] arch/Kconfig: Remove tautological conditions from HAS_LTO_CLANG Now that the minimum supported version of LLVM for building the kernel has been raised to 17.0.1, two dependency lines in CONFIG_HAS_LTO_CLANG are always true because Clang will always be newer than 17.0.0, so they can be removed. Reviewed-by: Nicolas Schier Acked-by: Arnd Bergmann Link: https://patch.msgid.link/20260517-bump-minimum-supported-llvm-version-to-17-v2-5-b3b8cda46bdd@kernel.org Signed-off-by: Nathan Chancellor --- arch/Kconfig | 3 --- 1 file changed, 3 deletions(-) diff --git a/arch/Kconfig b/arch/Kconfig index e86880045158..0d34bcafecaa 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -806,9 +806,6 @@ config HAS_LTO_CLANG depends on $(success,$(AR) --help | head -n 1 | grep -qi llvm) depends on ARCH_SUPPORTS_LTO_CLANG depends on !FTRACE_MCOUNT_USE_RECORDMCOUNT - # https://github.com/ClangBuiltLinux/linux/issues/1721 - depends on (!KASAN || KASAN_HW_TAGS || CLANG_VERSION >= 170000) || !DEBUG_INFO - depends on (!KCOV || CLANG_VERSION >= 170000) || !DEBUG_INFO depends on !GCOV_KERNEL help The compiler and Kconfig options support building with Clang's From de0bf1e138fcd6efdb4ddac764eb9f3487122535 Mon Sep 17 00:00:00 2001 From: Nathan Chancellor Date: Sun, 17 May 2026 13:05:09 -1000 Subject: [PATCH 10/31] arch/Kconfig: Remove tautological condition from AUTOFDO_CLANG Now that the minimum supported version of LLVM for building the kernel has been raised to 17.0.1, the clang version check in CONFIG_AUTOFDO_CLANG can be removed because it is always true. Reviewed-by: Rong Xu Link: https://patch.msgid.link/20260517-bump-minimum-supported-llvm-version-to-17-v2-6-b3b8cda46bdd@kernel.org Signed-off-by: Nathan Chancellor --- arch/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/Kconfig b/arch/Kconfig index 0d34bcafecaa..5d6e9f56210b 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -866,7 +866,7 @@ config ARCH_SUPPORTS_AUTOFDO_CLANG config AUTOFDO_CLANG bool "Enable Clang's AutoFDO build (EXPERIMENTAL)" depends on ARCH_SUPPORTS_AUTOFDO_CLANG - depends on CC_IS_CLANG && CLANG_VERSION >= 170000 + depends on CC_IS_CLANG help This option enables Clang’s AutoFDO build. When an AutoFDO profile is specified in variable From 48d229b6a48aeefeb0d7b4c5c860723ff5d7bd2d Mon Sep 17 00:00:00 2001 From: Nathan Chancellor Date: Sun, 17 May 2026 13:05:10 -1000 Subject: [PATCH 11/31] ARM: Drop tautological ld.lld conditions from ARCH_MULTI_V4{,T} Now that the minimum supported version of LLVM for building the kernel has been raised to 17.0.1, the '!ld.lld || ld.lld >= 16' dependency of CONFIG_ARCH_MULTI_V4{,T} is always true, so it can be removed from both symbols. Acked-by: Arnd Bergmann Link: https://patch.msgid.link/20260517-bump-minimum-supported-llvm-version-to-17-v2-7-b3b8cda46bdd@kernel.org Signed-off-by: Nathan Chancellor --- arch/arm/Kconfig.platforms | 4 ---- 1 file changed, 4 deletions(-) diff --git a/arch/arm/Kconfig.platforms b/arch/arm/Kconfig.platforms index 5c19c1f2cff6..386eccc81868 100644 --- a/arch/arm/Kconfig.platforms +++ b/arch/arm/Kconfig.platforms @@ -8,16 +8,12 @@ comment "CPU Core family selection" config ARCH_MULTI_V4 bool "ARMv4 based platforms (FA526, StrongARM)" depends on !ARCH_MULTI_V6_V7 - # https://github.com/llvm/llvm-project/issues/50764 - depends on !LD_IS_LLD || LLD_VERSION >= 160000 select ARCH_MULTI_V4_V5 select CPU_FA526 if !(CPU_SA110 || CPU_SA1100) config ARCH_MULTI_V4T bool "ARMv4T based platforms (ARM720T, ARM920T, ...)" depends on !ARCH_MULTI_V6_V7 - # https://github.com/llvm/llvm-project/issues/50764 - depends on !LD_IS_LLD || LLD_VERSION >= 160000 select ARCH_MULTI_V4_V5 select CPU_ARM920T if !(CPU_ARM7TDMI || CPU_ARM720T || \ CPU_ARM740T || CPU_ARM9TDMI || CPU_ARM922T || \ From 62c4af86895111feb61ebcf8dd5e0a5b86e5b97e Mon Sep 17 00:00:00 2001 From: Nathan Chancellor Date: Sun, 17 May 2026 13:05:11 -1000 Subject: [PATCH 12/31] riscv: Remove tautological condition from selection of ARCH_SUPPORTS_CFI Now that the minimum supported version of LLVM for building the kernel has been raised to 17.0.1, the condition of the selection of CONFIG_ARCH_SUPPORTS_CFI is always true, so it can be removed. Acked-by: Paul Walmsley # arch/riscv Link: https://patch.msgid.link/20260517-bump-minimum-supported-llvm-version-to-17-v2-8-b3b8cda46bdd@kernel.org Signed-off-by: Nathan Chancellor --- arch/riscv/Kconfig | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index d235396c4514..7ffbf6032b61 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -61,8 +61,7 @@ config RISCV select ARCH_OPTIONAL_KERNEL_RWX_DEFAULT select ARCH_STACKWALK select ARCH_SUPPORTS_ATOMIC_RMW - # clang >= 17: https://github.com/llvm/llvm-project/commit/62fa708ceb027713b386c7e0efda994f8bdc27e2 - select ARCH_SUPPORTS_CFI if (!CC_IS_CLANG || CLANG_VERSION >= 170000) + select ARCH_SUPPORTS_CFI select ARCH_SUPPORTS_DEBUG_PAGEALLOC if MMU select ARCH_SUPPORTS_HUGE_PFNMAP if TRANSPARENT_HUGEPAGE select ARCH_SUPPORTS_HUGETLBFS if MMU From 7e279976cf2a233b875cc22108b26476bdf70b51 Mon Sep 17 00:00:00 2001 From: Nathan Chancellor Date: Sun, 17 May 2026 13:05:12 -1000 Subject: [PATCH 13/31] riscv: Drop tautological condition from TOOLCHAIN_NEEDS_OLD_ISA_SPEC Now that the minimum supported version of LLVM for building the kernel has been raised to 17.0.1, the Clang dependency part of CONFIG_TOOLCHAIN_NEEDS_OLD_ISA_SPEC is always false, so it can be removed. Adjust the help text to remove mention of Clang < 17, as it is irrelevant for the kernel after the minimum supported bump. Acked-by: Paul Walmsley # arch/riscv Link: https://patch.msgid.link/20260517-bump-minimum-supported-llvm-version-to-17-v2-9-b3b8cda46bdd@kernel.org Signed-off-by: Nathan Chancellor --- arch/riscv/Kconfig | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 7ffbf6032b61..c742c42fd39b 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -873,19 +873,18 @@ config TOOLCHAIN_NEEDS_EXPLICIT_ZICSR_ZIFENCEI and Zifencei are supported in binutils from version 2.36 onwards. To make life easier, and avoid forcing toolchains that default to a newer ISA spec to version 2.2, relax the check to binutils >= 2.36. - For clang < 17 or GCC < 11.3.0, for which this is not possible or need - special treatment, this is dealt with in TOOLCHAIN_NEEDS_OLD_ISA_SPEC. + For GCC < 11.3.0, for which this is not possible or need special + treatment, this is dealt with in TOOLCHAIN_NEEDS_OLD_ISA_SPEC. config TOOLCHAIN_NEEDS_OLD_ISA_SPEC def_bool y depends on TOOLCHAIN_NEEDS_EXPLICIT_ZICSR_ZIFENCEI - # https://github.com/llvm/llvm-project/commit/22e199e6afb1263c943c0c0d4498694e15bf8a16 # https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=d29f5d6ab513c52fd872f532c492e35ae9fd6671 - depends on (CC_IS_CLANG && CLANG_VERSION < 170000) || (CC_IS_GCC && GCC_VERSION < 110300) + depends on CC_IS_GCC && GCC_VERSION < 110300 help - Certain versions of clang and GCC do not support zicsr and zifencei via - -march. This option causes an older ISA spec compatible with these older - versions of clang and GCC to be passed to GAS, which has the same result + Certain versions of GCC do not support zicsr and zifencei via -march. + This option causes an older ISA spec compatible with these older + versions of GCC to be passed to GAS, which has the same result as passing zicsr and zifencei to -march. config FPU From 2a35c63c6bc420df8d9b3daa5e2339233787f67c Mon Sep 17 00:00:00 2001 From: Nathan Chancellor Date: Sun, 17 May 2026 13:05:13 -1000 Subject: [PATCH 14/31] scripts/Makefile.warn: Drop -Wformat handling for clang < 16 Now that the minimum supported version of LLVM for building the kernel has been raised to 17.0.1, the block dealing with -Wformat with clang prior to 16 can be removed since the condition for its inclusion is always false. Reviewed-by: Nicolas Schier Link: https://patch.msgid.link/20260517-bump-minimum-supported-llvm-version-to-17-v2-10-b3b8cda46bdd@kernel.org Signed-off-by: Nathan Chancellor --- scripts/Makefile.warn | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/scripts/Makefile.warn b/scripts/Makefile.warn index e77ca875aea4..35af7d6c6d18 100644 --- a/scripts/Makefile.warn +++ b/scripts/Makefile.warn @@ -135,16 +135,6 @@ KBUILD_CFLAGS += $(call cc-option, -Wno-stringop-truncation) KBUILD_CFLAGS += -Wno-override-init # alias for -Wno-initializer-overrides in clang ifdef CONFIG_CC_IS_CLANG -# Clang before clang-16 would warn on default argument promotions. -ifneq ($(call clang-min-version, 160000),y) -# Disable -Wformat -KBUILD_CFLAGS += -Wno-format -# Then re-enable flags that were part of the -Wformat group that aren't -# problematic. -KBUILD_CFLAGS += -Wformat-extra-args -Wformat-invalid-specifier -KBUILD_CFLAGS += -Wformat-zero-length -Wnonnull -KBUILD_CFLAGS += -Wformat-insufficient-args -endif KBUILD_CFLAGS += -Wno-pointer-to-enum-cast KBUILD_CFLAGS += -Wno-tautological-constant-out-of-range-compare KBUILD_CFLAGS += -Wno-unaligned-access From 7b3281fcb43c5fce8d4d2b0996d3ac719cb5068b Mon Sep 17 00:00:00 2001 From: Nathan Chancellor Date: Sun, 17 May 2026 13:05:14 -1000 Subject: [PATCH 15/31] x86/build: Drop unnecessary '-ffreestanding' addition to KBUILD_CFLAGS Now that the minimum supported version of LLVM for building the kernel has been raised to 17.0.1, the addition of '-ffreestanding' to KBUILD_CFLAGS for 32-bit x86 is unnecessary, as the linked LLVM bug is resolved in all supported LLVM versions. 16cb16e0d285 ("x86/build: Remove -ffreestanding on i386 with GCC") intended to make the addition of '-ffreestanding' clang only but due to a bug in the adjusted check from d70da12453ac ("hardening: Enable i386 FORTIFY_SOURCE on Clang 16+") it has been applied for all versions of GCC and clang < 16.0.0. There are no known problems with removing this for GCC but if one surfaces, it can be restored under a CONFIG_CC_IS_GCC block. Link: https://patch.msgid.link/20260517-bump-minimum-supported-llvm-version-to-17-v2-11-b3b8cda46bdd@kernel.org Signed-off-by: Nathan Chancellor --- arch/x86/Makefile | 5 ----- 1 file changed, 5 deletions(-) diff --git a/arch/x86/Makefile b/arch/x86/Makefile index 46fec0b08487..5720f2470cfc 100644 --- a/arch/x86/Makefile +++ b/arch/x86/Makefile @@ -124,11 +124,6 @@ ifeq ($(CONFIG_X86_32),y) include $(srctree)/arch/x86/Makefile_32.cpu KBUILD_CFLAGS += $(cflags-y) - ifneq ($(call clang-min-version, 160000),y) - # https://github.com/llvm/llvm-project/issues/53645 - KBUILD_CFLAGS += -ffreestanding - endif - percpu_seg := fs else BITS := 64 From 12b7bf92bddd449e4e72e23d5b4e2ed730e4d3e8 Mon Sep 17 00:00:00 2001 From: Nathan Chancellor Date: Sun, 17 May 2026 13:05:15 -1000 Subject: [PATCH 16/31] x86/module: Revert "Deal with GOT based stack cookie load on Clang < 17" Now that the minimum supported version of LLVM for building the kernel has been raised to 17.0.1, the workaround added by 78c4374ef8b8 ("x86/module: Deal with GOT based stack cookie load on Clang < 17") will never be included, as the final clause in the preprocessor conditional is always false. Revert the change to clean up the dead code. Acked-by: Ard Biesheuvel Link: https://patch.msgid.link/20260517-bump-minimum-supported-llvm-version-to-17-v2-12-b3b8cda46bdd@kernel.org Signed-off-by: Nathan Chancellor --- arch/x86/include/asm/elf.h | 5 ++--- arch/x86/kernel/module.c | 15 --------------- 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h index c7f98977663c..0de9df759c99 100644 --- a/arch/x86/include/asm/elf.h +++ b/arch/x86/include/asm/elf.h @@ -54,9 +54,8 @@ typedef struct user_i387_struct elf_fpregset_t; #define R_X86_64_GLOB_DAT 6 /* Create GOT entry */ #define R_X86_64_JUMP_SLOT 7 /* Create PLT entry */ #define R_X86_64_RELATIVE 8 /* Adjust by program base */ -#define R_X86_64_GOTPCREL 9 /* 32 bit signed pc relative offset to GOT */ -#define R_X86_64_GOTPCRELX 41 -#define R_X86_64_REX_GOTPCRELX 42 +#define R_X86_64_GOTPCREL 9 /* 32 bit signed pc relative + offset to GOT */ #define R_X86_64_32 10 /* Direct 32 bit zero extended */ #define R_X86_64_32S 11 /* Direct 32 bit sign extended */ #define R_X86_64_16 12 /* Direct 16 bit zero extended */ diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c index 11c45ce42694..b5b4de4f08e6 100644 --- a/arch/x86/kernel/module.c +++ b/arch/x86/kernel/module.c @@ -19,7 +19,6 @@ #include #include #include -#include #include #include @@ -132,20 +131,6 @@ static int __write_relocate_add(Elf64_Shdr *sechdrs, goto overflow; size = 4; break; -#if defined(CONFIG_STACKPROTECTOR) && \ - defined(CONFIG_CC_IS_CLANG) && CONFIG_CLANG_VERSION < 170000 - case R_X86_64_REX_GOTPCRELX: { - static unsigned long __percpu *const addr = &__stack_chk_guard; - - if (sym->st_value != (u64)addr) { - pr_err("%s: Unsupported GOTPCREL relocation\n", me->name); - return -ENOEXEC; - } - - val = (u64)&addr + rel[i].r_addend; - fallthrough; - } -#endif case R_X86_64_PC32: case R_X86_64_PLT32: val -= (u64)loc; From 4e7af20d0d1043d9eb10a422c64d91de973384c1 Mon Sep 17 00:00:00 2001 From: Nathan Chancellor Date: Sun, 17 May 2026 13:05:16 -1000 Subject: [PATCH 17/31] x86/entry/vdso32: Remove conditional omission of '.cfi_offset eflags' Now that the minimum supported version of LLVM for building the kernel has been raised to 17.0.1, the inclusion condition added by 3e30278e0c71 ("x86/entry/vdso32: Omit '.cfi_offset eflags' for LLVM < 16") will always be true. Revert the change to clean up the source code. Acked-by: H. Peter Anvin (Intel) Link: https://patch.msgid.link/20260517-bump-minimum-supported-llvm-version-to-17-v2-13-b3b8cda46bdd@kernel.org Signed-off-by: Nathan Chancellor --- arch/x86/entry/vdso/vdso32/sigreturn.S | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/arch/x86/entry/vdso/vdso32/sigreturn.S b/arch/x86/entry/vdso/vdso32/sigreturn.S index b33fcc501ba3..328bd3a4ef51 100644 --- a/arch/x86/entry/vdso/vdso32/sigreturn.S +++ b/arch/x86/entry/vdso/vdso32/sigreturn.S @@ -22,17 +22,7 @@ CFI_OFFSET cs, IA32_SIGCONTEXT_cs CFI_OFFSET ss, IA32_SIGCONTEXT_ss CFI_OFFSET ds, IA32_SIGCONTEXT_ds -/* - * .cfi_offset eflags requires LLVM 16 or newer: - * - * https://github.com/llvm/llvm-project/commit/67bd3c58c0c7389e39c5a2f4d3b1a30459ccf5b7 - * - * Check for 16.0.1 to ensure the support is present, as 16.0.0 may be a - * prerelease version. - */ -#if defined(CONFIG_AS_IS_GNU) || (defined(CONFIG_AS_IS_LLVM) && CONFIG_AS_VERSION >= 160001) CFI_OFFSET eflags, IA32_SIGCONTEXT_flags -#endif .endm /* From f3de78cb19d1236169c3f24a5caaf7739c0886a1 Mon Sep 17 00:00:00 2001 From: Nathan Chancellor Date: Sun, 17 May 2026 13:05:17 -1000 Subject: [PATCH 18/31] kbuild: Remove check for broken scoping with clang < 17 in CC_HAS_ASM_GOTO_OUTPUT Now that the minimum supported version of LLVM for building the kernel has been raised to 17.0.1, the check added to CC_HAS_ASM_GOTO_OUTPUT by commit e2ffa15b9baa ("kbuild: Disable CC_HAS_ASM_GOTO_OUTPUT on clang < 17") can be removed, as the issue it detects is guaranteed to be fixed. Acked-by: Nicolas Schier Link: https://patch.msgid.link/20260517-bump-minimum-supported-llvm-version-to-17-v2-14-b3b8cda46bdd@kernel.org Signed-off-by: Nathan Chancellor --- init/Kconfig | 3 --- 1 file changed, 3 deletions(-) diff --git a/init/Kconfig b/init/Kconfig index 2937c4d308ae..6da6cf019d1a 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -118,10 +118,7 @@ config GCC_ASM_GOTO_OUTPUT_BROKEN config CC_HAS_ASM_GOTO_OUTPUT def_bool y depends on !GCC_ASM_GOTO_OUTPUT_BROKEN - # Detect basic support depends on $(success,echo 'int foo(int x) { asm goto ("": "=r"(x) ::: bar); return x; bar: return 0; }' | $(CC) -x c - -c -o /dev/null) - # Detect clang (< v17) scoped label issues - depends on $(success,echo 'void b(void **);void* c(void);int f(void){{asm goto(""::::l0);return 0;l0:return 1;}void *x __attribute__((cleanup(b)))=c();{asm goto(""::::l1);return 2;l1:return 3;}}' | $(CC) -x c - -c -o /dev/null) config CC_HAS_ASM_GOTO_TIED_OUTPUT depends on CC_HAS_ASM_GOTO_OUTPUT From c69eaa687667e529fcc0cce02394cca5a4db2249 Mon Sep 17 00:00:00 2001 From: Nathan Chancellor Date: Sun, 17 May 2026 13:05:18 -1000 Subject: [PATCH 19/31] compiler-clang.h: Remove __cleanup -Wunused-variable workaround Now that the minimum supported version of LLVM for building the kernel has been raised to 17.0.1, the redefinition of __cleanup with __maybe_unused added to it is unnecessary because the referenced LLVM change is present in all supported LLVM versions. Drop it. Link: https://patch.msgid.link/20260517-bump-minimum-supported-llvm-version-to-17-v2-15-b3b8cda46bdd@kernel.org Signed-off-by: Nathan Chancellor --- include/linux/compiler-clang.h | 9 --------- 1 file changed, 9 deletions(-) diff --git a/include/linux/compiler-clang.h b/include/linux/compiler-clang.h index e1123dd28486..eadf48b7b5b1 100644 --- a/include/linux/compiler-clang.h +++ b/include/linux/compiler-clang.h @@ -5,15 +5,6 @@ /* Compiler specific definitions for Clang compiler */ -/* - * Clang prior to 17 is being silly and considers many __cleanup() variables - * as unused (because they are, their sole purpose is to go out of scope). - * - * https://github.com/llvm/llvm-project/commit/877210faa447f4cc7db87812f8ed80e398fedd61 - */ -#undef __cleanup -#define __cleanup(func) __maybe_unused __attribute__((__cleanup__(func))) - /* all clang versions usable with the kernel support KASAN ABI version 5 */ #define KASAN_ABI_VERSION 5 From c919893eabb437d18dee3dddba6bc508bf1b1edd Mon Sep 17 00:00:00 2001 From: Nathan Chancellor Date: Sun, 17 May 2026 13:05:19 -1000 Subject: [PATCH 20/31] compiler-clang.h: Drop explicit version number from "all" diagnostic macro This is more consistent with what commit 7efa84b5cdd6 ("compiler-gcc.h: Introduce __diag_GCC_all") did for GCC. Link: https://patch.msgid.link/20260517-bump-minimum-supported-llvm-version-to-17-v2-16-b3b8cda46bdd@kernel.org Signed-off-by: Nathan Chancellor --- include/linux/compiler-clang.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/linux/compiler-clang.h b/include/linux/compiler-clang.h index eadf48b7b5b1..a105e2e8016c 100644 --- a/include/linux/compiler-clang.h +++ b/include/linux/compiler-clang.h @@ -122,10 +122,10 @@ #define __diag_str(s) __diag_str1(s) #define __diag(s) _Pragma(__diag_str(clang diagnostic s)) -#define __diag_clang_13(s) __diag(s) +#define __diag_clang_all(s) __diag(s) #define __diag_ignore_all(option, comment) \ - __diag_clang(13, ignore, option) + __diag_clang(all, ignore, option) /* * clang has horrible behavior with "g" or "rm" constraints for asm From c10ba5c9c62e2158cfa8a8be1f4c6fab67c799ec Mon Sep 17 00:00:00 2001 From: Philipp Hahn Date: Fri, 15 May 2026 14:47:50 +0200 Subject: [PATCH 21/31] run-clang-tools: run multiprocessing.Pool as context manager `multiprocessing.pool.Pool()` should be used as a context manager so Python can free its internal resources and do a proper cleanup.[1] While at it move the code to read the `compiler_commands.json` so the opened file can be closed before the sub-processes are fork()ed. Link: https://docs.python.org/3/library/multiprocessing.html#multiprocessing.pool.Pool [1] Signed-off-by: Philipp Hahn Link: https://patch.msgid.link/40180613bef84946c45d6fbeb4bb274573cd0beb.1778849135.git.phahn-oss@avm.de Signed-off-by: Nathan Chancellor --- scripts/clang-tools/run-clang-tools.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/scripts/clang-tools/run-clang-tools.py b/scripts/clang-tools/run-clang-tools.py index f31ffd09e1ea..e78be82aa693 100755 --- a/scripts/clang-tools/run-clang-tools.py +++ b/scripts/clang-tools/run-clang-tools.py @@ -79,14 +79,15 @@ def run_analysis(entry): def main(): - try: - args = parse_arguments() + args = parse_arguments() - lock = multiprocessing.Lock() - pool = multiprocessing.Pool(initializer=init, initargs=(lock, args)) - # Read JSON data into the datastore variable - with open(args.path, "r") as f: - datastore = json.load(f) + # Read JSON data into the datastore variable + with open(args.path) as f: + datastore = json.load(f) + + lock = multiprocessing.Lock() + try: + with multiprocessing.Pool(initializer=init, initargs=(lock, args)) as pool: pool.map(run_analysis, datastore) except BrokenPipeError: # Python flushes standard streams on exit; redirect remaining output From 159921d63da16ff1d4764e73ddf9e1556b54dfc8 Mon Sep 17 00:00:00 2001 From: Yafang Shao Date: Tue, 26 May 2026 14:27:32 +0800 Subject: [PATCH 22/31] kbuild: rpm-pkg: append %{?dist} macro to Release tag Add support for the %{?dist} macro in the kernel.spec file. This enables building and releasing kernel RPMs with a custom distribution suffix (e.g., via rpmbuild's --define option) to better match production environment tracking. Signed-off-by: Yafang Shao Link: https://patch.msgid.link/20260526062732.84006-1-laoar.shao@gmail.com Signed-off-by: Nathan Chancellor --- scripts/package/kernel.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/package/kernel.spec b/scripts/package/kernel.spec index b3c956205af0..c732415662ef 100644 --- a/scripts/package/kernel.spec +++ b/scripts/package/kernel.spec @@ -6,7 +6,7 @@ Name: kernel Summary: The Linux Kernel Version: %(echo %{KERNELRELEASE} | sed -e 's/-/_/g') -Release: %{pkg_release} +Release: %{pkg_release}%{?dist} License: GPL Group: System Environment/Kernel Vendor: The Linux Community From d7231d8cb262b1e350c00271bf53d54414b4f3b1 Mon Sep 17 00:00:00 2001 From: Alexandre Courbot Date: Wed, 27 May 2026 20:52:17 +0900 Subject: [PATCH 23/31] scripts: modpost: detect and report truncated buf_printf() output buf_printf() uses a fixed-size stack buffer. vsnprintf() returns the number of bytes that *would* have been written to that buffer, which can be larger than the size of said buffer if the formatted string is too long. The problem is that whenever this happens buf_printf() currently passes this length, unchecked, to buf_write(), which silently reads past the stack buffer and copies invalid data into the output buffer. Fix this by detecting vsnprintf() failures and truncations before appending to the output buffer, and report a fatal error instead of producing corrupt symbol names. Signed-off-by: Alexandre Courbot Link: https://patch.msgid.link/20260527-nova-exports-v2-1-06de4c556d55@nvidia.com Signed-off-by: Nathan Chancellor --- scripts/mod/modpost.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index abbcd3fc1394..0d2f1f09019b 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -1689,8 +1689,17 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf, va_start(ap, fmt); len = vsnprintf(tmp, SZ, fmt, ap); - buf_write(buf, tmp, len); va_end(ap); + + if (len < 0) { + perror("vsnprintf failed"); + exit(1); + } + if (len >= SZ) + fatal("buf_printf output truncated for string %s: %d bytes needed, %d available\n", + tmp, len + 1, SZ); + + buf_write(buf, tmp, len); } void buf_write(struct buffer *buf, const char *s, int len) From 9c72d26e9fe3be79dd1d8a2ba00a033503ffd27d Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 29 May 2026 11:53:44 -0700 Subject: [PATCH 24/31] kbuild: move vmlinux.a build rule to scripts/Makefile.vmlinux_a Move the build rule for vmlinux.a to a separate file in preparation for supporting distributed builds with Clang ThinLTO. Signed-off-by: Masahiro Yamada Tested-by: Rong Xu Tested-by: Piotr Gorski Tested-by: Nathan Chancellor Signed-off-by: Rong Xu Link: https://patch.msgid.link/20260529185347.2418373-2-xur@google.com [nathan: Squash in forward fix from Rong around '--thin' to $(AR) https://patch.msgid.link/20260529185347.2418373-3-xur@google.com] Signed-off-by: Nathan Chancellor --- Makefile | 16 +++++-------- scripts/Makefile.vmlinux_a | 46 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 10 deletions(-) create mode 100644 scripts/Makefile.vmlinux_a diff --git a/Makefile b/Makefile index e27c91ea56fc..0fce9557a115 100644 --- a/Makefile +++ b/Makefile @@ -1291,7 +1291,7 @@ export ARCH_DRIVERS := $(drivers-y) $(drivers-m) KBUILD_VMLINUX_OBJS := built-in.a $(patsubst %/, %/lib.a, $(filter %/, $(libs-y))) KBUILD_VMLINUX_LIBS := $(filter-out %/, $(libs-y)) -export KBUILD_VMLINUX_LIBS +export KBUILD_VMLINUX_OBJS KBUILD_VMLINUX_LIBS export KBUILD_LDS := arch/$(SRCARCH)/kernel/vmlinux.lds ifdef CONFIG_TRIM_UNUSED_KSYMS @@ -1300,16 +1300,12 @@ ifdef CONFIG_TRIM_UNUSED_KSYMS KBUILD_MODULES := y endif -# '$(AR) mPi' needs 'T' to workaround the bug of llvm-ar <= 14 -quiet_cmd_ar_vmlinux.a = AR $@ - cmd_ar_vmlinux.a = \ - rm -f $@; \ - $(AR) cDPrST $@ $(KBUILD_VMLINUX_OBJS); \ - $(AR) mPiT $$($(AR) t $@ | sed -n 1p) $@ $$($(AR) t $@ | grep -F -f $(srctree)/scripts/head-object-list.txt) +PHONY += vmlinux_a +vmlinux_a: $(KBUILD_VMLINUX_OBJS) scripts/head-object-list.txt FORCE + $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.vmlinux_a -targets += vmlinux.a -vmlinux.a: $(KBUILD_VMLINUX_OBJS) scripts/head-object-list.txt FORCE - $(call if_changed,ar_vmlinux.a) +vmlinux.a: vmlinux_a + @: PHONY += vmlinux_o vmlinux_o: vmlinux.a $(KBUILD_VMLINUX_LIBS) diff --git a/scripts/Makefile.vmlinux_a b/scripts/Makefile.vmlinux_a new file mode 100644 index 000000000000..650d44330d1f --- /dev/null +++ b/scripts/Makefile.vmlinux_a @@ -0,0 +1,46 @@ +# SPDX-License-Identifier: GPL-2.0-only + +PHONY := __default +__default: vmlinux.a + +include include/config/auto.conf +include $(srctree)/scripts/Kbuild.include +include $(srctree)/scripts/Makefile.lib + +# Link of built-in-fixup.a +# --------------------------------------------------------------------------- + +# '$(AR) mPi' needs 'T' to workaround the bug of llvm-ar <= 14 +quiet_cmd_ar_builtin_fixup = AR $@ + cmd_ar_builtin_fixup = \ + rm -f $@; \ + $(AR) cDPrST $@ $(KBUILD_VMLINUX_OBJS); \ + $(AR) mPiT $$($(AR) t $@ | sed -n 1p) $@ $$($(AR) t $@ | grep -F -f $(srctree)/scripts/head-object-list.txt) + +targets += built-in-fixup.a +built-in-fixup.a: $(KBUILD_VMLINUX_OBJS) scripts/head-object-list.txt FORCE + $(call if_changed,ar_builtin_fixup) + +# vmlinux.a +# --------------------------------------------------------------------------- + +targets += vmlinux.a +vmlinux.a: built-in-fixup.a FORCE + $(call if_changed,copy) + +# Add FORCE to the prerequisites of a target to force it to be always rebuilt. +# --------------------------------------------------------------------------- + +PHONY += FORCE +FORCE: + +# Read all saved command lines and dependencies for the $(targets) we +# may be building above, using $(if_changed{,_dep}). As an +# optimization, we don't need to read them if the target does not +# exist, we will rebuild anyway in that case. + +existing-targets := $(wildcard $(sort $(targets))) + +-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd) + +.PHONY: $(PHONY) From 9f2aee8f7d1842be08da860e45265d30dba0d1f7 Mon Sep 17 00:00:00 2001 From: Rong Xu Date: Fri, 29 May 2026 11:53:46 -0700 Subject: [PATCH 25/31] kbuild: distributed build support for Clang ThinLTO Add distributed ThinLTO build support for the Linux kernel. This new mode offers several advantages: (1) Increased flexibility in handling user-specified build options. (2) Improved user-friendliness for developers. (3) Greater convenience for integrating with objtool and livepatch. Note that "distributed" in this context refers to a term that differentiates in-process ThinLTO builds by invoking backend compilation through the linker, not necessarily building in distributed environments. Distributed ThinLTO is enabled via the `CONFIG_LTO_CLANG_THIN_DIST` Kconfig option. For example: > make LLVM=1 defconfig > scripts/config -e LTO_CLANG_THIN_DIST > make LLVM=1 oldconfig > make LLVM=1 vmlinux -j <..> The build flow proceeds in four stages: 1. Perform FE compilation, mirroring the in-process ThinLTO mode. 2. Thin-link the generated IR files and object files. 3. Find all IR files and perform BE compilation, using the flags stored in the .*.o.cmd files. 4. Link the BE results to generate the final vmlinux.o. NOTE: This patch currently implements the build for the main kernel image (vmlinux) only. Kernel module support is planned for a subsequent patch. Tested on the following arch: x86, arm64, loongarch, and riscv. The earlier implementation details can be found here: https://discourse.llvm.org/t/rfc-distributed-thinlto-build-for-kernel/85934 Signed-off-by: Rong Xu Co-developed-by: Masahiro Yamada Signed-off-by: Masahiro Yamada Tested-by: Piotr Gorski Tested-by: Nathan Chancellor Link: https://patch.msgid.link/20260529185347.2418373-4-xur@google.com Signed-off-by: Nathan Chancellor --- .gitignore | 2 ++ Makefile | 16 ++++++++++----- arch/Kconfig | 19 ++++++++++++++++++ scripts/Makefile.lib | 8 ++++++++ scripts/Makefile.thinlto | 40 ++++++++++++++++++++++++++++++++++++++ scripts/Makefile.vmlinux_a | 37 +++++++++++++++++++++++++++++++++++ scripts/mod/modpost.c | 15 +++++++++++--- 7 files changed, 129 insertions(+), 8 deletions(-) create mode 100644 scripts/Makefile.thinlto diff --git a/.gitignore b/.gitignore index 3044b9590f05..1cc34c9a5523 100644 --- a/.gitignore +++ b/.gitignore @@ -57,6 +57,7 @@ *.zst Module.symvers dtbs-list +builtin.order modules.order # @@ -68,6 +69,7 @@ modules.order /vmlinux.32 /vmlinux.map /vmlinux.symvers +/vmlinux.thinlto-index /vmlinux.unstripped /vmlinux-gdb.py /vmlinuz diff --git a/Makefile b/Makefile index 0fce9557a115..857f08dcc952 100644 --- a/Makefile +++ b/Makefile @@ -1071,11 +1071,16 @@ export CC_FLAGS_SCS endif ifdef CONFIG_LTO_CLANG -ifdef CONFIG_LTO_CLANG_THIN -CC_FLAGS_LTO := -flto=thin -fsplit-lto-unit -KBUILD_LDFLAGS += $(call ld-option,--lto-whole-program-visibility -mllvm -always-rename-promoted-locals=false) -else +ifdef CONFIG_LTO_CLANG_FULL CC_FLAGS_LTO := -flto +else +CC_FLAGS_LTO := -flto=thin -fsplit-lto-unit + +# These LLVM options were initially added with only in-process ThinLTO +# support, so avoid distributed ThinLTO support for now. +ifdef CONFIG_LTO_CLANG_THIN +KBUILD_LDFLAGS += $(call ld-option,--lto-whole-program-visibility -mllvm -always-rename-promoted-locals=false) +endif endif CC_FLAGS_LTO += -fvisibility=hidden @@ -1684,6 +1689,7 @@ endif # CONFIG_MODULES CLEAN_FILES += vmlinux.symvers modules-only.symvers \ modules.builtin modules.builtin.modinfo modules.nsdeps \ modules.builtin.ranges vmlinux.o.map vmlinux.unstripped \ + vmlinux.thinlto-index builtin.order \ compile_commands.json rust/test \ rust-project.json .vmlinux.objs .vmlinux.export.c \ .builtin-dtbs-list .builtin-dtbs.S @@ -2145,7 +2151,7 @@ clean: $(clean-dirs) $(call cmd,rmfiles) @find . $(RCS_FIND_IGNORE) \ \( -name '*.[aios]' -o -name '*.rsi' -o -name '*.ko' -o -name '.*.cmd' \ - -o -name '*.ko.*' \ + -o -name '*.ko.*' -o -name '*.o.thinlto.bc' \ -o -name '*.dtb' -o -name '*.dtbo' \ -o -name '*.dtb.S' -o -name '*.dtbo.S' \ -o -name '*.dt.yaml' -o -name 'dtbs-list' \ diff --git a/arch/Kconfig b/arch/Kconfig index 5d6e9f56210b..0848932d1c8e 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -858,6 +858,25 @@ config LTO_CLANG_THIN https://clang.llvm.org/docs/ThinLTO.html If unsure, say Y. + +config LTO_CLANG_THIN_DIST + bool "Clang ThinLTO in distributed mode (EXPERIMENTAL)" + depends on HAS_LTO_CLANG && ARCH_SUPPORTS_LTO_CLANG_THIN + select LTO_CLANG + help + This option enables Clang's ThinLTO in distributed build mode. + In this mode, the linker performs the thin-link, generating + ThinLTO index files. Subsequently, the build system explicitly + invokes ThinLTO backend compilation using these index files + and pre-linked IR objects. The resulting native object files + are with the .thinlto-native.o suffix. + + This build mode offers improved visibility into the ThinLTO + process through explicit subcommand exposure. It also makes + final native object files directly available, benefiting + tools like objtool and kpatch. Additionally, it provides + crucial granular control over back-end options, enabling + module-specific compiler options, and simplifies debugging. endchoice config ARCH_SUPPORTS_AUTOFDO_CLANG diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index 0718e39cedda..86e1428cc55d 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -249,6 +249,13 @@ ifdef CONFIG_LTO_CLANG cmd_ld_single = $(if $(objtool-enabled)$(is-single-obj-m), ; $(LD) $(ld_flags) -r -o $(tmp-target) $@; mv $(tmp-target) $@) endif +ifdef CONFIG_LTO_CLANG_THIN_DIST +# Save the _c_flags, sliently. +quiet_cmd_save_c_flags = + saved_c_flags = $(_c_flags) $(modkern_cflags) + cmd_save_c_flags = printf '\n%s\n' 'saved_c_flags_$@ := $(call escsq,$(saved_c_flags))' >> $(dot-target).cmd +endif + quiet_cmd_cc_o_c = CC $(quiet_modtag) $@ cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $< \ $(cmd_ld_single) \ @@ -256,6 +263,7 @@ quiet_cmd_cc_o_c = CC $(quiet_modtag) $@ define rule_cc_o_c $(call cmd_and_fixdep,cc_o_c) + $(call cmd,save_c_flags) $(call cmd,checksrc) $(call cmd,checkdoc) $(call cmd,gen_objtooldep) diff --git a/scripts/Makefile.thinlto b/scripts/Makefile.thinlto new file mode 100644 index 000000000000..bb83f13f3cd6 --- /dev/null +++ b/scripts/Makefile.thinlto @@ -0,0 +1,40 @@ +PHONY := __default +__default: + +include include/config/auto.conf +include $(srctree)/scripts/Kbuild.include +include $(srctree)/scripts/Makefile.lib + +native-objs := $(patsubst %.o,%.thinlto-native.o,$(call read-file, vmlinux.thinlto-index)) + +__default: $(native-objs) + +# Generate .thinlto-native.o (obj) from .o (bitcode) and .thinlto.bc (summary) files +# --------------------------------------------------------------------------- +quiet_cmd_cc_o_bc = CC $(quiet_modtag) $@ + be_flags = $(shell sed -n '/saved_c_flags_/s/.*:= //p' \ + $(dir $(<)).$(notdir $(<)).cmd) + cmd_cc_o_bc = \ + $(CC) $(be_flags) -x ir -fno-lto -Wno-unused-command-line-argument \ + -fthinlto-index=$(word 2, $^) -c -o $@ $< + +targets += $(native-objs) +$(native-objs): %.thinlto-native.o: %.o %.o.thinlto.bc FORCE + $(call if_changed,cc_o_bc) + +# Add FORCE to the prerequisites of a target to force it to be always rebuilt. +# --------------------------------------------------------------------------- + +PHONY += FORCE +FORCE: + +# Read all saved command lines and dependencies for the $(targets) we +# may be building above, using $(if_changed{,_dep}). As an +# optimization, we don't need to read them if the target does not +# exist, we will rebuild anyway in that case. + +existing-targets := $(wildcard $(sort $(targets))) + +-include $(foreach f, $(existing-targets),$(dir $(f)).$(notdir $(f)).cmd) + +.PHONY: $(PHONY) diff --git a/scripts/Makefile.vmlinux_a b/scripts/Makefile.vmlinux_a index 650d44330d1f..bd141b893748 100644 --- a/scripts/Makefile.vmlinux_a +++ b/scripts/Makefile.vmlinux_a @@ -21,6 +21,41 @@ targets += built-in-fixup.a built-in-fixup.a: $(KBUILD_VMLINUX_OBJS) scripts/head-object-list.txt FORCE $(call if_changed,ar_builtin_fixup) +ifdef CONFIG_LTO_CLANG_THIN_DIST + +quiet_cmd_builtin.order = GEN $@ + cmd_builtin.order = $(AR) t $< > $@ + +targets += builtin.order +builtin.order: built-in-fixup.a FORCE + $(call if_changed,builtin.order) + +quiet_cmd_ld_thinlto_index = LD $@ + cmd_ld_thinlto_index = \ + $(LD) $(KBUILD_LDFLAGS) -r --thinlto-index-only=$@ @$< + +targets += vmlinux.thinlto-index +vmlinux.thinlto-index: builtin.order FORCE + $(call if_changed,ld_thinlto_index) + +quiet_cmd_ar_vmlinux.a = GEN $@ + cmd_ar_vmlinux.a = \ + rm -f $@; \ + while read -r obj; do \ + if grep -Fqx $${obj} $(word 2, $^); then \ + echo $${obj%.o}.thinlto-native.o; \ + else \ + echo $${obj}; \ + fi; \ + done < $< | xargs $(AR) cDPrS --thin $@ + +targets += vmlinux.a +vmlinux.a: builtin.order vmlinux.thinlto-index FORCE + $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.thinlto + $(call if_changed,ar_vmlinux.a) + +else + # vmlinux.a # --------------------------------------------------------------------------- @@ -28,6 +63,8 @@ targets += vmlinux.a vmlinux.a: built-in-fixup.a FORCE $(call if_changed,copy) +endif + # Add FORCE to the prerequisites of a target to force it to be always rebuilt. # --------------------------------------------------------------------------- diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 0d2f1f09019b..da0f4bc75509 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -1487,13 +1487,22 @@ static void extract_crcs_for_object(const char *object, struct module *mod) char cmd_file[PATH_MAX]; char *buf, *p; const char *base; - int dirlen, ret; + int dirlen, baselen_without_suffix, ret; base = get_basename(object); dirlen = base - object; - ret = snprintf(cmd_file, sizeof(cmd_file), "%.*s.%s.cmd", - dirlen, object, base); + baselen_without_suffix = strlen(object) - dirlen - strlen(".o"); + + /* + * When CONFIG_LTO_CLANG_THIN_DIST=y, the ELF is *.thinlto-native.o + * but the symbol CRCs are recorded in *.o.cmd file. + */ + if (strends(object, ".thinlto-native.o")) + baselen_without_suffix -= strlen(".thinlto-native"); + + ret = snprintf(cmd_file, sizeof(cmd_file), "%.*s.%.*s.o.cmd", + dirlen, object, baselen_without_suffix, base); if (ret >= sizeof(cmd_file)) { error("%s: too long path was truncated\n", cmd_file); return; From a48bd961fb203a7ce68f8110fc53a85f90e24b33 Mon Sep 17 00:00:00 2001 From: Nathan Chancellor Date: Tue, 2 Jun 2026 18:41:50 -0700 Subject: [PATCH 26/31] kbuild: Remove unnecessary 'T' modifier in cmd_ar_builtin_fixup In cmd_ar_builtin_fixup, the 'T' modifier was added to '$(AR) mPi' to work around a bug in llvm-ar that caused thin archives to be silently converted to full archives [1]. Since commit 20c098928356 ("kbuild: Bump minimum version of LLVM for building the kernel to 15.0.0"), all supported versions of llvm-ar have this issue fixed, so the 'T' modifier and comment can be removed. Link: https://github.com/llvm/llvm-project/commit/d17c54d17de22d2961a04163f3dbc8e973de89b8 [1] Signed-off-by: Nathan Chancellor --- scripts/Makefile.vmlinux_a | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/Makefile.vmlinux_a b/scripts/Makefile.vmlinux_a index bd141b893748..395e29998d7d 100644 --- a/scripts/Makefile.vmlinux_a +++ b/scripts/Makefile.vmlinux_a @@ -10,12 +10,11 @@ include $(srctree)/scripts/Makefile.lib # Link of built-in-fixup.a # --------------------------------------------------------------------------- -# '$(AR) mPi' needs 'T' to workaround the bug of llvm-ar <= 14 quiet_cmd_ar_builtin_fixup = AR $@ cmd_ar_builtin_fixup = \ rm -f $@; \ $(AR) cDPrST $@ $(KBUILD_VMLINUX_OBJS); \ - $(AR) mPiT $$($(AR) t $@ | sed -n 1p) $@ $$($(AR) t $@ | grep -F -f $(srctree)/scripts/head-object-list.txt) + $(AR) mPi $$($(AR) t $@ | sed -n 1p) $@ $$($(AR) t $@ | grep -F -f $(srctree)/scripts/head-object-list.txt) targets += built-in-fixup.a built-in-fixup.a: $(KBUILD_VMLINUX_OBJS) scripts/head-object-list.txt FORCE From f58316a441b4626324993db585fa4b7b7c780fac Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Wed, 27 May 2026 09:27:03 -0500 Subject: [PATCH 27/31] kconfig: add kconfig-sym-check static checker Add 'make kconfig-sym-check', a static checker that finds Kconfig symbols referenced in expressions (select, depends on, default, etc.) but never defined via config/menuconfig anywhere in the tree. New dangling symbols are reported as errors (exit 1) unless they are listed in an exclusion file, e.g. KCONFIG_SYM_CHECK_EXCLUDES=sym-check-excludes make kconfig-sym-check The exclusion file lists one symbol per line; blank lines and lines starting with '#' are ignored. The checker also warns about uppercase N/Y/M used as tristate literal values following the same logic as checkpatch. This new static checker is the script used for [1] with a few improvements to avoid some false positives. Link: https://bugzilla.kernel.org/show_bug.cgi?id=216748 [1] Assisted-by: Claude:claude-sonnet-4-6 Signed-off-by: Andrew Jones Acked-by: Andy Shevchenko Acked-by: Randy Dunlap Tested-by: Randy Dunlap Tested-by: Julian Braha Tested-by: Nicolas Schier Acked-by: Nicolas Schier Link: https://patch.msgid.link/20260527142703.107110-1-andrew.jones@linux.dev Signed-off-by: Nathan Chancellor --- Makefile | 23 +++-- scripts/kconfig/kconfig-sym-check.pl | 132 +++++++++++++++++++++++++++ 2 files changed, 146 insertions(+), 9 deletions(-) create mode 100755 scripts/kconfig/kconfig-sym-check.pl diff --git a/Makefile b/Makefile index 857f08dcc952..37fdb454b637 100644 --- a/Makefile +++ b/Makefile @@ -293,6 +293,7 @@ version_h := include/generated/uapi/linux/version.h clean-targets := %clean mrproper cleandocs no-dot-config-targets := $(clean-targets) \ cscope gtags TAGS tags help% %docs check% coccicheck \ + kconfig-sym-check \ $(version_h) headers headers_% archheaders archscripts \ %asm-generic kernelversion %src-pkg dt_binding_check \ outputmakefile rustavailable rustfmt rustfmtcheck \ @@ -1800,14 +1801,15 @@ help: echo ' (default: $(INSTALL_HDR_PATH))'; \ echo '' @echo 'Static analysers:' - @echo ' checkstack - Generate a list of stack hogs and consider all functions' - @echo ' with a stack size larger than MINSTACKSIZE (default: 100)' - @echo ' versioncheck - Sanity check on version.h usage' - @echo ' includecheck - Check for duplicate included header files' - @echo ' headerdep - Detect inclusion cycles in headers' - @echo ' coccicheck - Check with Coccinelle' - @echo ' clang-analyzer - Check with clang static analyzer' - @echo ' clang-tidy - Check with clang-tidy' + @echo ' checkstack - Generate a list of stack hogs and consider all functions' + @echo ' with a stack size larger than MINSTACKSIZE (default: 100)' + @echo ' versioncheck - Sanity check on version.h usage' + @echo ' includecheck - Check for duplicate included header files' + @echo ' headerdep - Detect inclusion cycles in headers' + @echo ' coccicheck - Check with Coccinelle' + @echo ' kconfig-sym-check - Check for dangling Kconfig symbol references' + @echo ' clang-analyzer - Check with clang static analyzer' + @echo ' clang-tidy - Check with clang-tidy' @echo '' @echo 'Tools:' @echo ' nsdeps - Generate missing symbol namespace dependencies' @@ -2227,7 +2229,7 @@ endif # Scripts to check various things for consistency # --------------------------------------------------------------------------- -PHONY += includecheck versioncheck coccicheck +PHONY += includecheck versioncheck coccicheck kconfig-sym-check includecheck: find $(srctree)/* $(RCS_FIND_IGNORE) \ @@ -2242,6 +2244,9 @@ versioncheck: coccicheck: $(Q)$(BASH) $(srctree)/scripts/$@ +kconfig-sym-check: + $(Q)$(PERL) $(srctree)/scripts/kconfig/kconfig-sym-check.pl $(srctree) $(KCONFIG_SYM_CHECK_EXCLUDES) + PHONY += checkstack kernelrelease kernelversion image_name # UML needs a little special treatment here. It wants to use the host diff --git a/scripts/kconfig/kconfig-sym-check.pl b/scripts/kconfig/kconfig-sym-check.pl new file mode 100755 index 000000000000..daa5285fdefc --- /dev/null +++ b/scripts/kconfig/kconfig-sym-check.pl @@ -0,0 +1,132 @@ +#!/usr/bin/env perl +# SPDX-License-Identifier: GPL-2.0 + +use warnings; +use strict; + +my $srctree = shift @ARGV; +unless (defined $srctree) { + $srctree = `git rev-parse --show-toplevel 2>/dev/null`; + chomp $srctree; + my $msg = "Usage: $0 [excludes file]\n"; + $msg .= "Please provide ."; + $msg .= " Is it '$srctree'?" if $srctree; + $msg .= "\n"; + die $msg; +} +my $kconfig_sym_check_excludes = defined $ARGV[0] ? $ARGV[0] : undef; + +sub indent_depth { + my ($ws) = @_; + my $col = 0; + for my $c (split //, $ws) { + $col = $c eq "\t" ? int($col / 8) * 8 + 8 : $col + 1; + } + return $col; +} + +my @files = `git -C \Q$srctree\E ls-files '*Kconfig*' 2>/dev/null`; +if (@files) { + chomp @files; + @files = map { "$srctree/$_" } @files; +} else { + @files = `find \Q$srctree\E -name '*Kconfig*'`; + chomp @files; +} + +@files = grep { !m{/scripts/kconfig/tests/} } @files; + +my %configs = (); +my %refs = (); + +foreach my $file (@files) { + open F, $file or die "Cannot open $file: $!"; + + my $help = 0; + my $help_level; + my $level; + + while () { + chomp; + + while (/\\\s*$/) { + s/\\\s*$/ /; + my $cont = // last; + chomp $cont; + $_ .= $cont; + } + + next if /^\s*$/; + next if /^\s*#/; + + /^(\s*)/; + $level = indent_depth($1); + + if ($help && $level < $help_level) { + $help = 0; + } + + next if ($help); + + if (/^\s*(help|\-\-\-help\-\-\-)$/) { + $help = 1; + my $next; + while (defined($next = )) { + last unless $next =~ /^\s*(?:#.*)?$/; + } + last unless defined $next; + $next =~ /^(\s*)/; + if (indent_depth($1) >= $level) { + $help_level = indent_depth($1); + } else { + $help = 0; + } + $_ = $next; + redo; + } + + if (/^\s*(config|menuconfig)\s+([a-zA-Z0-9_]+)\s*(#.*)?$/) { + $configs{$2}++; + next; + } + + if (/^\s*(default|def_bool|def_tristate|select|depends\s+on|imply|visible\s+if|range|if|bool|tristate|int|hex|string|prompt)\s+(.+)\s*$/) { + my $s = $2; + $s =~ s/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'//g; + $s =~ s/#.*//; + $s =~ s/\$\((?:[^()]*|\((?:[^()]*|\([^()]*\))*\))*\)//g; + $s =~ s/%%[^%]*%%//g; + my @syms = split /[^a-zA-Z0-9_]+/, $s; + map { + $refs{$_}++ if (/[a-zA-Z]/ && $_ ne "if" && $_ ne "y" && $_ ne "n" && $_ ne "m" && !/^0[xX][0-9a-fA-F]+$/); + } @syms + } + } + + close F; +} + +my %known_syms = (); +if (defined $kconfig_sym_check_excludes) { + my $file = $kconfig_sym_check_excludes; + open(F, "<", $file) or die "Cannot open $file: $!"; + while () { + chomp; + next if /^\s*$/; + next if /^\s*#/; + $known_syms{$1}++ if (/^\s*([a-zA-Z0-9_]+)\s*(#.*)?$/); + } +} + +my $ret = 0; +foreach my $k (sort keys %refs) { + next if (exists $configs{$k} || exists $known_syms{$k}); + + print "$k"; + print " - warning: '$k' is probably not what you want; Kconfig tristate literals are always lowercase ('n', 'y', 'm')" if ($k eq "N" || $k eq "Y" || $k eq "M"); + print "\n"; + + $ret = 1; +} + +exit $ret; From 29c52907334a8e50ba1ee5fbaa53407dec28d876 Mon Sep 17 00:00:00 2001 From: James Lee Date: Thu, 4 Jun 2026 14:03:00 +0800 Subject: [PATCH 28/31] modpost: Add __llvm_covfun and __llvm_covmap to section_white_list Modpost emits hundreds of warnings when using Clang to build for ARCH=um and CONFIG_GCOV=y. e.g.: vmlinux (__llvm_covfun): unexpected non-allocatable section. Did you forget to use "ax"/"aw" in a .S file? Note that for example contains section definitions for use in .S files. For example, when we use LLVM for a kunit user mode build with coverage: python3 tools/testing/kunit/kunit.py build --make_options LLVM=1 \ --kunitconfig=tools/testing/kunit/configs/default.config \ --kunitconfig=tools/testing/kunit/configs/coverage_uml.config The behaviour occurs when building the kernel for ARCH=um with code coverage enabled. The warnings come from modpost's check_sec_ref function, which ensures no sections reference others that will be discarded. covfun and covmap sections must reference __init and __exit sections to collect coverage data, triggering the modpost warning. To suppress these warnings, these section names have been added to modpost's whitelist. This is unlikely to suppress legitimate warnings as Clang will only insert these sections when building with coverage, and can be assumed to manage these references safely. Signed-off-by: James Lee Link: https://patch.msgid.link/20260604-dev-coverage-patch-v1-1-9f9368253cb4@codeconstruct.com.au Signed-off-by: Nathan Chancellor --- scripts/mod/modpost.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index da0f4bc75509..d592548cbd60 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -765,6 +765,8 @@ static const char *const section_white_list[] = ".gnu.lto*", ".discard.*", ".llvm.call-graph-profile", /* call graph */ + "__llvm_covfun", + "__llvm_covmap", NULL }; From e88b2fe8b9993c9cae856019b1c31c14b63cad7a Mon Sep 17 00:00:00 2001 From: Rong Xu Date: Thu, 4 Jun 2026 12:56:07 -0700 Subject: [PATCH 29/31] kconfig: Remove the architecture specific config for AutoFDO The CONFIG_AUTOFDO_CLANG option currently depends on ARCH_SUPPORTS_AUTOFDO_CLANG, but this dependency seems unnecessary. Remove ARCH_SUPPORTS_AUTOFDO_CLANG and allow users to control AutoFDO builds solely through CONFIG_AUTOFDO_CLANG. This simplifies the kconfig and avoids potential confusion. Expand the AutoFDO documentation to include instructions for arm64. Contributor acknowledgments: * SPE instructions: Daniel Hoekwater * ETM instructions: Yabin Cui Signed-off-by: Rong Xu Suggested-by: Will Deacon Tested-by: Yabin Cui Reviewed-by: Kees Cook Link: https://patch.msgid.link/20260604195612.3757860-2-xur@google.com Signed-off-by: Nathan Chancellor --- Documentation/dev-tools/autofdo.rst | 41 +++++++++++++++++++++++++++++ arch/Kconfig | 4 --- arch/x86/Kconfig | 1 - 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/Documentation/dev-tools/autofdo.rst b/Documentation/dev-tools/autofdo.rst index bcf06e7d6ffa..ae03c4dfedc1 100644 --- a/Documentation/dev-tools/autofdo.rst +++ b/Documentation/dev-tools/autofdo.rst @@ -61,6 +61,9 @@ process consists of the following steps: the AutoFDO profile via offline tools. The support requires a Clang compiler LLVM 17 or later. +Current supported architectures include x86/x86_64 (via LBR) and +arm64 (via SPE or ETM). + Preparation =========== @@ -141,6 +144,35 @@ Here is an example workflow for AutoFDO kernel: $ perf record --pfm-events RETIRED_TAKEN_BRANCH_INSTRUCTIONS:k -a -N -b -c -o -- + - For arm64 with SPE: + + There are a few kernel features that must be enabled to collect SPE profiles on Arm. + Below is a list of the required features: + + - CONFIG_ARM_SPE_PMU=y + - CONFIG_PID_IN_CONTEXTIDR=y + - kpti=off + + Use the following command to generate SPE perf data file:: + + $ perf record -e ' arm_spe_0/branch_filter=1,load_filter=0,store_filter=0/' -a -c -N --no-switch-events -o -- + + - For arm64 with ETM trace: + + Follow the instructions in `Linaro OpenCSD document + `_ + to record ETM traces for AutoFDO:: + + $ perf record -e cs_etm/@tmc_etr0/k -a -o -- + $ perf inject -i -o --itrace=i500009il + + For ARM platforms running Android, follow the instructions in `Android simpleperf + document `_ + to record ETM traces for AutoFDO:: + + $ simpleperf record -e cs-etm:k -a -o -- + $ simpleperf inject -i -o --symdir + 4) (Optional) Download the raw perf file to the host machine. 5) To generate an AutoFDO profile, two offline tools are available: @@ -162,6 +194,15 @@ Here is an example workflow for AutoFDO kernel: $ llvm-profdata merge -o ... + For arm64 SPE, use the following command:: + + $ create_llvm_prof --binary= --profile= --profiler=perf_spe --format=extbinary --out= + + For arm64 ETM, use the following command:: + + $ create_llvm_prof --binary= --profile= --profiler=text -format=extbinary -out= + + 6) Rebuild the kernel using the AutoFDO profile file with the same config as step 1, (Note CONFIG_AUTOFDO_CLANG needs to be enabled):: diff --git a/arch/Kconfig b/arch/Kconfig index 0848932d1c8e..5e878924939a 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -879,12 +879,8 @@ config LTO_CLANG_THIN_DIST module-specific compiler options, and simplifies debugging. endchoice -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 help This option enables Clang’s AutoFDO build. When diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index f3f7cb01d69d..10bf3984102e 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -130,7 +130,6 @@ config X86 select ARCH_SUPPORTS_LTO_CLANG select ARCH_SUPPORTS_LTO_CLANG_THIN select ARCH_SUPPORTS_RT - 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_CX8 From 2566fa7b2f2402a77dae6a5e9b28a1bae1c20793 Mon Sep 17 00:00:00 2001 From: Rong Xu Date: Thu, 4 Jun 2026 12:56:08 -0700 Subject: [PATCH 30/31] kconfig: Remove the architecture specific config for Propeller The CONFIG_PROPELLER_CLANG option currently depends on ARCH_SUPPORTS_PROPELLER_CLANG, but this dependency seems unnecessary. Remove ARCH_SUPPORTS_PROPELLER_CLANG and allow users to control Propeller builds solely through CONFIG_PROPELLER_CLANG. This simplifies the kconfig and avoids potential confusion. Move the .llvm_bb_addr_map sections grouping to include/asm-generic/vmlinux.lds.h. The Propeller documentation has been updated to reflect the most recent tool location and now includes instructions for arm64. Contributor Acknowledgments: * SPE instructions: Daniel Hoekwater Signed-off-by: Rong Xu Suggested-by: Will Deacon Suggested-by: Nathan Chancellor Tested-by: Yabin Cui Reviewed-by: Kees Cook Link: https://patch.msgid.link/20260604195612.3757860-3-xur@google.com Signed-off-by: Nathan Chancellor --- Documentation/dev-tools/propeller.rst | 49 ++++++++++++++++++++------- arch/Kconfig | 5 +-- arch/arm64/kernel/vmlinux.lds.S | 1 + arch/x86/Kconfig | 1 - arch/x86/kernel/vmlinux.lds.S | 5 +-- include/asm-generic/vmlinux.lds.h | 6 ++++ 6 files changed, 46 insertions(+), 21 deletions(-) diff --git a/Documentation/dev-tools/propeller.rst b/Documentation/dev-tools/propeller.rst index 92195958e3db..e927319941c9 100644 --- a/Documentation/dev-tools/propeller.rst +++ b/Documentation/dev-tools/propeller.rst @@ -28,8 +28,10 @@ A few important notes about adopting Propeller optimization: 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. + conversion tool: https://github.com/google/llvm-propeller. + +Current supported architectures include x86/X86_64 (via LBR), +and arm64 (via SPE). The Propeller optimization process involves the following steps: @@ -124,17 +126,30 @@ Here is an example workflow for building an AutoFDO+Propeller kernel: $ 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. + - For arm64 with SPE:: + There are a few kernel features that must be enabled to collect SPE profiles on Arm. + Below is a list of the required features: + + - CONFIG_ARM_SPE_PMU=y + - CONFIG_PID_IN_CONTEXTIDR=y + - kpti=off + + Use the following command to generate SPE perf data file:: + + $ perf record -e 'arm_spe_0/branch_filter=1,load_filter=0,store_filter=0/' -a -N -c --no-switch-events -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 +5) Use the generate_propeller_profiles tool (https://github.com/google/llvm-propeller) to generate Propeller profile. :: - $ create_llvm_prof --binary= --profile= - --format=propeller --propeller_output_module_name - --out=_cc_profile.txt - --propeller_symorder=_ld_profile.txt + $ generate_propeller_profiles \ + --binary= --profile= \ + --format=propeller --propeller_output_module_name \ + --out=_cc_profile.txt \ + --propeller_symorder=_ld_profile.txt "" can be something like "/home/user/dir/any_string". @@ -146,10 +161,20 @@ Here is an example workflow for building an AutoFDO+Propeller kernel: you can create a temp list file "" with each line containing one perf file name and run:: - $ create_llvm_prof --binary= --profile=@ - --format=propeller --propeller_output_module_name - --out=_cc_profile.txt - --propeller_symorder=_ld_profile.txt + $ generate_propeller_profiles \ + --binary= --profile=@ \ + --format=propeller --propeller_output_module_name \ + --out=_cc_profile.txt \ + --propeller_symorder=_ld_profile.txt + + For arm64 SPE, add the option '--profiler=perf_spe', like:: + + $ generate_propeller_profiles \ + --binary= --profile= \ + --profiler=perf_spe \ + --format=propeller --propeller_output_module_name \ + --out=_cc_profile.txt \ + --propeller_symorder=_ld_profile.txt 6) Rebuild the kernel using the AutoFDO and Propeller profiles. :: diff --git a/arch/Kconfig b/arch/Kconfig index 5e878924939a..99c2017eb515 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -895,13 +895,10 @@ config AUTOFDO_CLANG If unsure, say N. -config ARCH_SUPPORTS_PROPELLER_CLANG - bool - config PROPELLER_CLANG bool "Enable Clang's Propeller build" - depends on ARCH_SUPPORTS_PROPELLER_CLANG depends on CC_IS_CLANG && CLANG_VERSION >= 190000 + depends on $(cc-option,-fbasic-block-sections=list=/dev/null) help This option enables Clang’s Propeller build. When the Propeller profiles is specified in variable CLANG_PROPELLER_PROFILE_PREFIX diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S index e1ac876200a3..8aaf404980a7 100644 --- a/arch/arm64/kernel/vmlinux.lds.S +++ b/arch/arm64/kernel/vmlinux.lds.S @@ -368,6 +368,7 @@ SECTIONS STABS_DEBUG DWARF_DEBUG + PROPELLER_DATA MODINFO ELF_DETAILS diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 10bf3984102e..b875d2f27e48 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -130,7 +130,6 @@ config X86 select ARCH_SUPPORTS_LTO_CLANG select ARCH_SUPPORTS_LTO_CLANG_THIN select ARCH_SUPPORTS_RT - select ARCH_SUPPORTS_PROPELLER_CLANG if X86_64 select ARCH_USE_BUILTIN_BSWAP select ARCH_USE_CMPXCHG_LOCKREF if X86_CX8 select ARCH_USE_MEMTEST diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S index 4711a35e706c..74e336d7f9dd 100644 --- a/arch/x86/kernel/vmlinux.lds.S +++ b/arch/x86/kernel/vmlinux.lds.S @@ -423,10 +423,7 @@ SECTIONS STABS_DEBUG DWARF_DEBUG -#ifdef CONFIG_PROPELLER_CLANG - .llvm_bb_addr_map : { *(.llvm_bb_addr_map) } -#endif - + PROPELLER_DATA MODINFO ELF_DETAILS diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h index 60c8c22fd3e4..5659f4b5a125 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -1011,6 +1011,12 @@ #define PERCPU_DECRYPTED_SECTION #endif +#ifdef CONFIG_PROPELLER_CLANG +#define PROPELLER_DATA \ + .llvm_bb_addr_map : { *(.llvm_bb_addr_map) } +#else +#define PROPELLER_DATA +#endif /* * Default discarded sections. From 1a1e62a5a48494cdf33e3bfb82fb8f408da7c4cc Mon Sep 17 00:00:00 2001 From: Ethan Nelson-Moore Date: Mon, 8 Jun 2026 19:17:10 -0700 Subject: [PATCH 31/31] kconfig: tests: fix typo in comment scripts/kconfig/tests/no_write_if_dep_unmet/__init__.py contains a typo "COFIG_" for "CONFIG_". Fix it. Discovered while searching for typos in CONFIG_* variable references. Signed-off-by: Ethan Nelson-Moore Link: https://patch.msgid.link/20260609021712.7965-1-enelsonmoore@gmail.com Signed-off-by: Nathan Chancellor --- scripts/kconfig/tests/no_write_if_dep_unmet/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/kconfig/tests/no_write_if_dep_unmet/__init__.py b/scripts/kconfig/tests/no_write_if_dep_unmet/__init__.py index ffd469d1f226..791ed659c76b 100644 --- a/scripts/kconfig/tests/no_write_if_dep_unmet/__init__.py +++ b/scripts/kconfig/tests/no_write_if_dep_unmet/__init__.py @@ -8,7 +8,7 @@ for symbols with unmet dependency. This was not working correctly for choice values because choice needs a bit different symbol computation. -This checks that no unneeded "# COFIG_... is not set" is contained in +This checks that no unneeded "# CONFIG_... is not set" is contained in the .config file. Related Linux commit: cb67ab2cd2b8abd9650292c986c79901e3073a59