tools build: Append -fzero-init-padding-bits=all option
Subsystems (19)
v7 cover tools build: Append -fzero-init-padding-bits=all option
GCC-15 doesn't guarantee that a {0} initializer clears the whole union [1]. This may cause bugs if data is not intialized properly.
The kernel enabld the -fzero-init-padding-bits=all option to tackle the issue, which was merged in commit dce4aab8441d ("kbuild: Use -fzero-init-padding-bits=all").
This series propagates the same flag to the tools build. It uses tools/scripts/Makefile.include as the central place to add the option to EXTRA_CFLAGS and HOST_EXTRACFLAGS for the CC and HOSTCC compilers. Each project under tools/ appends the variables as needed.
BPF/bpftool related patches will be sent separately, as maintainers prefer them to go via the BPF tree.
The changes are organized into three parts:
Patches 01 – 04: Fixes for thermal build.
Patch 05: Rename to cross-cc-option so the function name
cc-option can be reserved for using globally.
Patch 06: Propagate -fzero-init-padding-bits=all to
EXTRA_CFLAGS and HOST_EXTRACFLAGS for the CC and HOSTCC compilers, respectively.
Patches 07 – 23: Apply EXTRA_CFLAGS and HOST_EXTRACFLAGS in
project Makefiles.
The change has been verified:
Test 1: Cross compiling perf (rebased on perf-tools-next)
host: gcc 15.2.0 (x86_64), target: aarch64-linux-gnu-gcc
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- LDFLAGS="-static" \
-C tools/perf VF=1 CORESIGHT=1 NO_JEVENTS=1 DEBUG=1
Test 2: Cross compiling selftest bpf and sched_ext
host: gcc 15.2.0 (x86_64), target: aarch64-linux-gnu-gcc
export ARCH=arm64
export CROSS_COMPILE=aarch64-linux-gnu-
make -C tools/testing/selftests/ TARGETS="bpf sched_ext" SKIP_TARGETS=""
Test 3: BPF CI test (BPF patches will be sent separately)
https://github.com/kernel-patches/bpf/actions/runs/26815163486
[1] https://gcc.gnu.org/gcc-15/changes.html
---
Changes in v7:
- Appended $(EXTRA_CFLAGS) in tracing/rtla/Makefile.
- Refactored testing/selftests/lib.mk to include Makefile.include, as
the $(EXTRA_CFLAGS) can be applied globally for selftest, dropped the
patches for selftests/hid, selftests/nolibc and selftests/sched_ext.
- Link to v6: https://lore.kernel.org/r/[email protected]
Changes in v6:
- Gathered Acked tags (thanks Jonathan!)
- Left out bpftool patches and will send together with other BPF patches (Quentin)
- Added back complete info in cover (Peter.Z)
- Link to v5: https://lore.kernel.org/r/[email protected]
Changes in v5:
- Gathered Acked tags (thanks Daniel, Namhyung, Benjamin!)
- Appended HOST_EXTRACFLAGS after KBUILD_HOSTCFLAGS (Ian)
- Appended CFLAGS for libc-test (Thomas)
- Left out BPF patches and will send out separately (Alexei)
- Rebase on v7.0.0-rc4
- Link to v4: https://lore.kernel.org/r/[email protected]
---
Leo Yan (23):
tools: lib: thermal: Fix typo
tools/thermal: Fix typo
tools: lib: thermal: Initialize CFLAGS before including Makefile.include tools/thermal: Initialize CFLAGS before including Makefile.include selftests/nolibc: Use a dedicated cross cc-option helper tools build: Append -fzero-init-padding-bits=all to extra cflags perf build: Append extra host flags
tools build: Append extra host CFLAGS for fixdep
tools: bootconfig: Append extra cflags
tools: counter: Append extra cflags
tools: dma: Append extra cflags
tools: gpio: Append extra cflags
tools: hv: Append extra cflags
tools: iio: Append extra cflags
tools: mm: Append extra cflags
tools: objtool: Append extra host cflags
tools: power: acpi: Append extra cflags
tools: power: x86/intel-speed-select: Append extra cflags
tools: sched_ext: Append extra cflags
tools: spi: Append extra cflags
tools: tracing: Append extra cflags
tools: usb: Append extra cflags
selftests: Include tools Makefile.include
tools/bootconfig/Makefile | 1 + tools/build/Makefile | 8 ++++--- tools/counter/Makefile | 1 + tools/dma/Makefile | 1 + tools/gpio/Makefile | 1 + tools/hv/Makefile | 1 + tools/iio/Makefile | 1 + tools/lib/thermal/Makefile | 20 +++++++++-------- tools/mm/Makefile | 1 + tools/objtool/Makefile | 2 ++ tools/perf/Makefile.config | 2 +- tools/power/acpi/Makefile.config | 1 + tools/power/x86/intel-speed-select/Makefile | 1 + tools/sched_ext/Makefile | 1 + tools/scripts/Makefile.include | 30 ++++++++++++++++++++++++++ tools/spi/Makefile | 1 + tools/testing/selftests/lib.mk | 30 +++++++++++++------------- tools/testing/selftests/nolibc/Makefile.nolibc | 12 +++++------ tools/thermal/lib/Makefile | 20 +++++++++-------- tools/tracing/latency/Makefile | 1 + tools/tracing/rtla/Makefile | 1 + tools/usb/Makefile | 1 + 22 files changed, 95 insertions(+), 43 deletions(-)
---
base-commit: 6f3ed7fec72fc8979b2a8c7219c0a9fcfc8d07b5
change-id: 20260224-tools_build_fix_zero_init-dc5261bd8b8b
Best regards,
Signature · 1 line
Leo Yan <[email protected]>
PATCH v7 1/23 tools: lib: thermal: Fix typo
s/CFGLAS/CFLAGS
--- tools/lib/thermal/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/lib/thermal/Makefile +2 -2
@@ -66,8 +66,8 @@ override CFLAGS += -fPIC override CFLAGS += $(NL3_CFLAGS) override CFLAGS += $(INCLUDES) override CFLAGS += -fvisibility=hidden -override CFGLAS += -Wl,-L. -override CFGLAS += -Wl,-lthermal +override CFLAGS += -Wl,-L. +override CFLAGS += -Wl,-lthermal all:
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH v7 01/23] tools: lib: thermal: Fix typo
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] Fixing the 'CFGLAS' typo activates logically incorrect linker flags inside the compiler flags…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Fixing the 'CFGLAS' typo activates logically incorrect linker flags inside the compiler flags (CFLAGS), injecting them into the object compilation step. --
commit 783a6df50ce2cf932c85a46af96705ee016835e4
Author: Leo Yan <[email protected]>
tools: lib: thermal: Fix typo
This commit fixes a typo in tools/lib/thermal/Makefile by replacing CFGLAS with CFLAGS for the linker flags.
tools/lib/thermal/Makefile override CFLAGS += -fPIC · line 70
Quoted 11 lines
tools/lib/thermal/Makefile +2
-2@@ -66,8 +66,8 @@ override CFLAGS += -fPIC override CFLAGS += $(NL3_CFLAGS) override CFLAGS += $(INCLUDES) override CFLAGS += -fvisibility=hidden -override CFGLAS += -Wl,-L. -override CFGLAS += -Wl,-lthermal +override CFLAGS += -Wl,-L. +override CFLAGS += -Wl,-lthermal
[Severity: Low]
Does this activate logically incorrect linker flags?
By fixing the typo, the linker flags -Wl,-L. and -Wl,-lthermal are now injected into CFLAGS. Linker flags do not belong in CFLAGS, which is used for compiling object files. Furthermore, instructing libthermal to link against itself while it is being built is conceptually a circular dependency.
While GCC silently ignores these flags during object compilation, their presence in CFLAGS causes Clang to emit -Wunused-command-line-argument warnings. Because the Makefile enforces -Werror, this newly introduced logical error breaks the build for Clang users.
Should these two lines be deleted entirely instead of renaming the variable?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
PATCH v7 2/23 tools/thermal: Fix typo
In reply to Leo Yans/CFGLAS/CFLAGS
--- tools/thermal/lib/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/thermal/lib/Makefile +2 -2
@@ -60,8 +60,8 @@ override CFLAGS += $(EXTRA_WARNINGS) override CFLAGS += -Werror -Wall override CFLAGS += -fPIC override CFLAGS += $(INCLUDES) -override CFGLAS += -Wl,-L. -override CFGLAS += -Wl,-lthermal +override CFLAGS += -Wl,-L. +override CFLAGS += -Wl,-lthermal all:
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH v7 02/23] tools/thermal: Fix typo
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] Fixing the `CFGLAS` typo to `CFLAGS` introduces linker flags (`-Wl,-lthermal` and `-Wl,-L.`) into…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Fixing the CFGLAS typo to CFLAGS introduces linker flags (-Wl,-lthermal and -Wl,-L.) into the C compilation phase (CFLAGS). This breaks the build under Clang because the unused linker arguments during the -c compilation step trigger a warning that is turned into a fatal error by -Werror. Furthermore, these flags are useless because CFLAGS is not even passed to the $(CC) --shared link step in these Makefiles. --
commit 93498abb92499dd9b72fc403e55f192942d97b46
Author: Leo Yan <[email protected]>
tools/thermal: Fix typo
This commit fixes a typo in the tools/thermal/lib/Makefile, changing CFGLAS to CFLAGS for the thermal library linker flags.
tools/thermal/lib/Makefile override CFLAGS += $(EXTRA_WARNINGS) · line 64
Quoted 11 lines
tools/thermal/lib/Makefile +2
-2@@ -60,8 +60,8 @@ override CFLAGS += $(EXTRA_WARNINGS) override CFLAGS += -Werror -Wall override CFLAGS += -fPIC override CFLAGS += $(INCLUDES) -override CFGLAS += -Wl,-L. -override CFGLAS += -Wl,-lthermal +override CFLAGS += -Wl,-L. +override CFLAGS += -Wl,-lthermal
[Severity: Low]
Does adding these linker flags into the C compilation phase break the build when compiling with Clang?
Since the Makefile also specifies -Werror, passing -Wl,-lthermal and -Wl,-L. during the C compilation step might trigger a fatal unused argument warning under Clang.
Are these linker flags actually needed in CFLAGS, or should they be added to LDFLAGS instead, considering CFLAGS doesn't appear to be passed to the shared link step?
Also, does the prior commit in this series introduce this same behavior in tools/lib/thermal/Makefile by fixing an identical typo?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
PATCH v7 3/23 tools: lib: thermal: Initialize CFLAGS before including Makefile.include
In reply to Leo Yantools/scripts/Makefile.include may expand EXTRA_CFLAGS in a future change. This could alter the initialization of CFLAGS in the thermal Makefile, as the default options "-g -Wall" would never be set once EXTRA_CFLAGS is expanded.
Prepare for this by moving the CFLAGS initialization before including tools/scripts/Makefile.include, so it is not affected by the extended EXTRA_CFLAGS.
Append EXTRA_CFLAGS to CFLAGS only after including Makefile.include and place it last so that the extra flags propagate properly and can override the default options.
--- tools/lib/thermal/Makefile | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
tools/lib/thermal/Makefile +9 -7
@@ -23,6 +23,14 @@ INSTALL = install DESTDIR ?= DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))' +# Defer assigning EXTRA_CFLAGS to CFLAGS until after including +# tools/scripts/Makefile.include, as it may add flags to EXTRA_CFLAGS. +ifdef EXTRA_CFLAGS + CFLAGS := +else + CFLAGS := -g -Wall +endif + include $(srctree)/tools/scripts/Makefile.include include $(srctree)/tools/scripts/Makefile.arch
@@ -39,13 +47,6 @@ libdir = $(prefix)/$(libdir_relative) libdir_SQ = $(subst ','\'',$(libdir)) libdir_relative_SQ = $(subst ','\'',$(libdir_relative)) -# Set compile option CFLAGS -ifdef EXTRA_CFLAGS - CFLAGS := $(EXTRA_CFLAGS) -else - CFLAGS := -g -Wall -endif - NL3_CFLAGS = $(shell pkg-config --cflags libnl-3.0 2>/dev/null) ifeq ($(NL3_CFLAGS),) NL3_CFLAGS = -I/usr/include/libnl3
@@ -68,6 +69,7 @@ override CFLAGS += $(INCLUDES) override CFLAGS += -fvisibility=hidden override CFLAGS += -Wl,-L. override CFLAGS += -Wl,-lthermal +override CFLAGS += $(EXTRA_CFLAGS) all:
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH v7 03/23] tools: lib: thermal: Initialize CFLAGS before including Makefile.include
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but the fix for the CFLAGS initialization order completely missed tools/lib/bpf/Makefile. This leaves it vulnerable to the EXTRA_CFLAGS expansion introduced later in the series. --
commit d569bb22d825610f92ca0c5003854cd0736f3058
Author: Leo Yan <[email protected]>
tools: lib: thermal: Initialize CFLAGS before including Makefile.include
This commit prepares the thermal lib Makefile for future changes to tools/scripts/Makefile.include that may expand EXTRA_CFLAGS. It moves the CFLAGS initialization before the include to ensure default compiler options like -g and -Wall are not silently dropped.
Quoted 5 lines
tools/lib/thermal/Makefile +0
-0
tools/lib/thermal/Makefile INSTALL = install · line 32
Quoted 10 lines
tools/lib/thermal/Makefile +7
-0@@ -23,6 +23,14 @@ INSTALL = install DESTDIR ?= DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))' +# Defer assigning EXTRA_CFLAGS to CFLAGS until after including +# tools/scripts/Makefile.include, as it may add flags to EXTRA_CFLAGS. +ifdef EXTRA_CFLAGS + CFLAGS := +else + CFLAGS := -g -Wall +endif
[Severity: High]
This is a pre-existing issue, but it looks like this same vulnerable CFLAGS initialization order exists in tools/lib/bpf/Makefile.
Since a later patch in this series unconditionally populates EXTRA_CFLAGS via Makefile.include, does this mean libbpf will skip its default initialization and build without optimizations?
tools/lib/bpf/Makefile:
...
include $(srctree)/tools/scripts/Makefile.include
...
ifdef EXTRA_CFLAGS
CFLAGS := $(EXTRA_CFLAGS)
else
CFLAGS := -g -O2
endifShould tools/lib/bpf/Makefile also be updated in this series to prevent a performance regression in libbpf?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
PATCH v7 4/23 tools/thermal: Initialize CFLAGS before including Makefile.include
In reply to Leo Yantools/scripts/Makefile.include may expand EXTRA_CFLAGS in a future change. This could alter the initialization of CFLAGS in the thermal Makefile, as the default options "-g -Wall" would never be set once EXTRA_CFLAGS is expanded.
Prepare for this by moving the CFLAGS initialization before including tools/scripts/Makefile.include, so it is not affected by the extended EXTRA_CFLAGS.
Append EXTRA_CFLAGS to CFLAGS only after including Makefile.include and place it last so that the extra flags propagate properly and can override the default options.
--- tools/thermal/lib/Makefile | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
tools/thermal/lib/Makefile +9 -7
@@ -23,6 +23,14 @@ INSTALL = install DESTDIR ?= DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))' +# Defer assigning EXTRA_CFLAGS to CFLAGS until after including +# tools/scripts/Makefile.include, as it may add flags to EXTRA_CFLAGS. +ifdef EXTRA_CFLAGS + CFLAGS := +else + CFLAGS := -g -Wall +endif + include $(srctree)/tools/scripts/Makefile.include include $(srctree)/tools/scripts/Makefile.arch
@@ -39,13 +47,6 @@ libdir = $(prefix)/$(libdir_relative) libdir_SQ = $(subst ','\'',$(libdir)) libdir_relative_SQ = $(subst ','\'',$(libdir_relative)) -# Set compile option CFLAGS -ifdef EXTRA_CFLAGS - CFLAGS := $(EXTRA_CFLAGS) -else - CFLAGS := -g -Wall -endif - INCLUDES = \ -I/usr/include/libnl3 \ -I$(srctree)/tools/lib/thermal/include \
@@ -62,6 +63,7 @@ override CFLAGS += -fPIC override CFLAGS += $(INCLUDES) override CFLAGS += -Wl,-L. override CFLAGS += -Wl,-lthermal +override CFLAGS += $(EXTRA_CFLAGS) all:
Signature · 1 line
2.34.1
PATCH v7 5/23 selftests/nolibc: Use a dedicated cross cc-option helper
In reply to Leo YanMakefile.nolibc uses cc-option for architecture-specific flag probes such as -m32, -mmultiple and -mabi=elfv2. These probes need to include CLANG_CROSS_FLAGS so that Clang tests the option for the selected target instead of the host.
The file also includes tools/scripts/Makefile.include. In a sequential change, Makefile.include will define its own cc-option helper.
Rename the nolibc helper to cross-cc-option and use it for the architecture-specific probes that require CLANG_CROSS_FLAGS. This keeps the cross-build checks explicit and avoids clashing with the common tools cc-option helper.
--- tools/testing/selftests/nolibc/Makefile.nolibc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
tools/testing/selftests/nolibc/Makefile.nolibc +6 -6
@@ -23,7 +23,7 @@ include $(srctree)/scripts/subarch.include ARCH = $(SUBARCH) endif -cc-option = $(call __cc-option, $(CC),$(CLANG_CROSS_FLAGS),$(1),$(2)) +cross-cc-option = $(call __cc-option, $(CC),$(CLANG_CROSS_FLAGS),$(1),$(2)) # XARCH extends the kernel's ARCH with a few variants of the same # architecture that only differ by the configuration, the toolchain
@@ -211,13 +211,13 @@ else Q=@ endif -CFLAGS_i386 = $(call cc-option,-m32) +CFLAGS_i386 = $(call cross-cc-option,-m32) CFLAGS_x32 = -mx32 CFLAGS_arm = -marm CFLAGS_armthumb = -mthumb -march=armv6t2 -CFLAGS_ppc = -m32 -mbig-endian -mno-vsx $(call cc-option,-mmultiple) -CFLAGS_ppc64 = -m64 -mbig-endian -mno-vsx $(call cc-option,-mmultiple) -CFLAGS_ppc64le = -m64 -mlittle-endian -mno-vsx $(call cc-option,-mabi=elfv2) +CFLAGS_ppc = -m32 -mbig-endian -mno-vsx $(call cross-cc-option,-mmultiple) +CFLAGS_ppc64 = -m64 -mbig-endian -mno-vsx $(call cross-cc-option,-mmultiple) +CFLAGS_ppc64le = -m64 -mlittle-endian -mno-vsx $(call cross-cc-option,-mabi=elfv2) CFLAGS_s390x = -m64 CFLAGS_mips32le = -EL -mabi=32 -fPIC CFLAGS_mips32be = -EB -mabi=32
@@ -226,7 +226,7 @@ CFLAGS_mipsn32be = -EB -mabi=n32 -march=mips64r6 CFLAGS_mips64le = -EL -mabi=64 -march=mips64r6 CFLAGS_mips64be = -EB -mabi=64 -march=mips64r2 CFLAGS_loongarch = $(if $(LLVM),-fuse-ld=lld) -CFLAGS_sparc32 = $(call cc-option,-m32) -mcpu=v8 +CFLAGS_sparc32 = $(call cross-cc-option,-m32) -mcpu=v8 CFLAGS_sh4 = -ml -m4 ifeq ($(origin XARCH),command line) CFLAGS_XARCH = $(CFLAGS_$(XARCH))
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH v7 05/23] selftests/nolibc: Use a dedicated cross cc-option helper
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] Renaming `cc-option` to `cross-cc-option` in `Makefile.nolibc` breaks compiler flag probing in…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Renaming cc-option to cross-cc-option in Makefile.nolibc breaks compiler flag probing in Makefile.include during cross-builds with Clang. --
commit 2287b14b38d381104f1caab4547ea009ec49cae7
Author: Leo Yan <[email protected]>
selftests/nolibc: Use a dedicated cross cc-option helper
This commit renames the nolibc cc-option helper to cross-cc-option to ensure CLANG_CROSS_FLAGS is used for architecture-specific flag probes. This keeps cross-build checks explicit and avoids clashing with the common tools helper.
tools/testing/selftests/nolibc/Makefile.nolibc include $(srctree)/scripts/subarch.include · line 26
Quoted 9 lines
tools/testing/selftests/nolibc/Makefile.nolibc +1
-1@@ -23,7 +23,7 @@ include $(srctree)/scripts/subarch.include ARCH = $(SUBARCH) endif -cc-option = $(call __cc-option, $(CC),$(CLANG_CROSS_FLAGS),$(1),$(2)) +cross-cc-option = $(call __cc-option, $(CC),$(CLANG_CROSS_FLAGS),$(1),$(2))
[Severity: Medium]
Does this change break compiler flag probing in Makefile.include during cross-builds with Clang?
Since cc-option is no longer overridden to include $(CLANG_CROSS_FLAGS) here, uses of cc-option in Makefile.include will fall back to the generic cc-option defined in scripts/Makefile.compiler.
For example, Makefile.include evaluates:
__CFLAGS_STACKPROTECTOR = $(call cc-option,-fstack-protector-all) \
$(call cc-option,-mstack-protector-guard=global)Because CC is left as just clang without any target flags in this context, the generic cc-option will probe the host compiler instead of the target compiler. Could this discard valid target flags if the host doesn't support them, altering test coverage and breaking feature enablement for the nolibc test suite?
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
PATCH v7 6/23 tools build: Append -fzero-init-padding-bits=all to extra cflags
In reply to Leo YanGCC-15 release claims [1]:
{0} initializer in C or C++ for unions no longer guarantees clearing of the whole union (except for static storage duration initialization), it just initializes the first union member to zero. If initialization of the whole union including padding bits is desirable, use {} (valid in C23 or C++) or use -fzero-init-padding-bits=unions option to restore old GCC behavior.
As a result, this new behaviour might cause unexpected data when we initialize a union with using the '{ 0 }' initializer.
Since commit dce4aab8441d ("kbuild: Use -fzero-init-padding-bits=all"), the kernel has enabled -fzero-init-padding-bits=all to zero padding bits in unions and structures. This commit applies the same option for tools building.
The option is not supported by any version older than GCC 15, nor is it supported by LLVM. This patch adds the cc-option and host-cc-option functions to dynamically detect compiler option and append it to the EXTRA_CFLAGS and HOST_EXTRACFLAGS respectively.
[1] https://gcc.gnu.org/gcc-15/changes.html
--- tools/scripts/Makefile.include | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
tools/scripts/Makefile.include +30 -0
@@ -139,6 +139,36 @@ else EXTRA_WARNINGS += -Wshadow endif +# output directory for tests below +TMPOUT = .tmp_$$$$ + +# try-run +# Usage: option = $(call try-run, $(CC)...-o "$$TMP",option-ok,otherwise) +# Exit code chooses option. "$$TMP" serves as a temporary file and is +# automatically cleaned up. +try-run = $(shell set -e; \ + TMP=$(TMPOUT)/tmp; \ + trap "rm -rf $(TMPOUT)" EXIT; \ + mkdir -p $(TMPOUT); \ + if ($(1)) >/dev/null 2>&1; \ + then echo "$(2)"; \ + else echo "$(3)"; \ + fi) + +# cc-option +# Usage: CFLAGS += $(call cc-option,-march=winchip-c6,-march=i586) +cc-option = $(call try-run, \ + $(CC) -Werror $(1) -c -x c /dev/null -o "$$TMP",$(1),$(2)) + +host-cc-option = $(call try-run, \ + $(HOSTCC) -Werror $(1) -c -x c /dev/null -o "$$TMP",$(1),$(2)) + +# Explicitly clear padding bits with the initializer '{ 0 }' +FLAG_ZERO_INIT := $(call cc-option,-fzero-init-padding-bits=all) +override EXTRA_CFLAGS += $(FLAG_ZERO_INIT) +HOST_FLAG_ZERO_INIT := $(call host-cc-option,-fzero-init-padding-bits=all) +override HOST_EXTRACFLAGS += $(HOST_FLAG_ZERO_INIT) + ifneq ($(findstring $(MAKEFLAGS), w),w) PRINT_DIR = --no-print-directory else
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH v7 06/23] tools build: Append -fzero-init-padding-bits=all to extra cflags
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] The `try-run` macro attempts to create a temporary directory in the source tree, breaking…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] The try-run macro attempts to create a temporary directory in the source tree, breaking out-of-tree builds on read-only filesystems.
- [High] Unconditionally appending to EXTRA_CFLAGS in Makefile.include breaks libbpf's default compilation flags, causing it to be built without debug info and optimizations. --
commit e8ede2fdc1b643da62469cb30003522715558696
Author: Leo Yan <[email protected]>
Subject: tools build: Append -fzero-init-padding-bits=all to extra cflags
The kernel has enabled -fzero-init-padding-bits=all to zero padding bits in unions and structures. This commit applies the same option for tools building by adding cc-option and host-cc-option to dynamically detect and append it to EXTRA_CFLAGS and HOST_EXTRACFLAGS.
Quoted 4 lines
tools/scripts/Makefile.include +0
-0
[ ... ]
Quoted 5 lines
tools/scripts/Makefile.include +1
-0@@ -139,6 +139,36 @@ else EXTRA_WARNINGS += -Wshadow endif +# output directory for tests below
tools/scripts/Makefile.include else · line 152
Quoted 10 lines
tools/scripts/Makefile.include +10
-0+TMPOUT = .tmp_$$$$ + +# try-run +# Usage: option = $(call try-run, $(CC)...-o "$$TMP",option-ok,otherwise) +# Exit code chooses option. "$$TMP" serves as a temporary file and is +# automatically cleaned up. +try-run = $(shell set -e; \ + TMP=$(TMPOUT)/tmp; \ + trap "rm -rf $(TMPOUT)" EXIT; \ + mkdir -p $(TMPOUT); \
[Severity: High]
Does this break out-of-tree builds on read-only filesystems?
Because TMPOUT is hardcoded as .tmp_$$$$ without an $(OUTPUT) prefix, the mkdir -p command will attempt to write directly to the source directory.
When performing out-of-tree builds (like make O=/path/to/build) on read-only source trees, this fails with a read-only file system error. Since the compiler flag uses immediate assignment (:=), this failure might spam the console and silently drop the option during parsing.
Quoted 5 lines
tools/scripts/Makefile.include +5
-0+ if ($(1)) >/dev/null 2>&1; \ + then echo "$(2)"; \ + else echo "$(3)"; \ + fi) +
[ ... ]
tools/scripts/Makefile.include else · line 168
Quoted 6 lines
tools/scripts/Makefile.include +6
-0+host-cc-option = $(call try-run, \ + $(HOSTCC) -Werror $(1) -c -x c /dev/null -o "$$TMP",$(1),$(2)) + +# Explicitly clear padding bits with the initializer '{ 0 }' +FLAG_ZERO_INIT := $(call cc-option,-fzero-init-padding-bits=all) +override EXTRA_CFLAGS += $(FLAG_ZERO_INIT)
[Severity: High]
Will this cause libbpf to lose its default debug and optimization flags?
In tools/lib/bpf/Makefile, there is a conditional block:
ifdef EXTRA_CFLAGS
CFLAGS := $(EXTRA_CFLAGS)
else
CFLAGS := -g -O2
endif
Because tools/scripts/Makefile.include is included prior to this check, EXTRA_CFLAGS will unconditionally contain -fzero-init-padding-bits=all if supported by the compiler.
This means EXTRA_CFLAGS is always defined, causing libbpf to completely drop its default -g -O2 flags and compile with only the padding bits flag.
It appears libthermal was fixed to avoid this issue, but is a corresponding fix needed for libbpf in this patch series?
Quoted 3 lines
tools/scripts/Makefile.include +3
-0+HOST_FLAG_ZERO_INIT := $(call host-cc-option,-fzero-init-padding-bits=all) +override HOST_EXTRACFLAGS += $(HOST_FLAG_ZERO_INIT) +
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
PATCH v7 7/23 perf build: Append extra host flags
In reply to Leo YanAppend HOST_EXTRACFLAGS to HOST_CFLAGS so that additional flags can be applied to the host compiler.
--- tools/perf/Makefile.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/Makefile.config +1 -1
@@ -17,7 +17,7 @@ detected = $(shell echo "$(1)=y" >> $(OUTPUT).config-detected) detected_var = $(shell echo "$(1)=$($(1))" >> $(OUTPUT).config-detected) CFLAGS := $(EXTRA_CFLAGS) $(filter-out -Wnested-externs,$(EXTRA_WARNINGS)) -HOSTCFLAGS := $(filter-out -Wnested-externs,$(EXTRA_WARNINGS)) +HOSTCFLAGS := $(HOST_EXTRACFLAGS) $(filter-out -Wnested-externs,$(EXTRA_WARNINGS)) # This is required because the kernel is built with this and some of the code # borrowed from kernel headers depends on it, e.g. put_unaligned_*().
Signature · 1 line
2.34.1
PATCH v7 8/23 tools build: Append extra host CFLAGS for fixdep
In reply to Leo Yantools/scripts/Makefile.include can add host compiler options through HOST_EXTRACFLAGS. Make sure the tools build uses those flags when building fixdep.
Create a local HOST_CFLAGS variable from KBUILD_HOSTCFLAGS and HOST_EXTRACFLAGS, and pass it to the fixdep build.
--- tools/build/Makefile | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
tools/build/Makefile +5 -3
@@ -40,18 +40,20 @@ endif FIXDEP := $(OUTPUT)fixdep FIXDEP_IN := $(OUTPUT)fixdep-in.o +HOST_CFLAGS := $(KBUILD_HOSTCFLAGS) $(HOST_EXTRACFLAGS) + # To track fixdep's dependencies properly, fixdep needs to run on itself. # Build it twice the first time. $(FIXDEP_IN): FORCE $(Q)if [ ! -f $(FIXDEP) ]; then \ - $(MAKE) $(build)=fixdep HOSTCFLAGS="$(KBUILD_HOSTCFLAGS)"; \ + $(MAKE) $(build)=fixdep HOSTCFLAGS="$(HOST_CFLAGS)"; \ rm -f $(FIXDEP).o; \ fi - $(Q)$(MAKE) $(build)=fixdep HOSTCFLAGS="$(KBUILD_HOSTCFLAGS)" + $(Q)$(MAKE) $(build)=fixdep HOSTCFLAGS="$(HOST_CFLAGS)" $(FIXDEP): $(FIXDEP_IN) - $(QUIET_LINK)$(HOSTCC) $(FIXDEP_IN) $(KBUILD_HOSTLDFLAGS) -o $@ + $(QUIET_LINK)$(HOSTCC) $(FIXDEP_IN) $(HOST_CFLAGS) -o $@ FORCE:
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH v7 08/23] tools build: Append extra host CFLAGS for fixdep
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] The link step for `fixdep` replaces `KBUILD_HOSTLDFLAGS` with `HOST_CFLAGS`, unintentionally…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] The link step for fixdep replaces KBUILD_HOSTLDFLAGS with HOST_CFLAGS, unintentionally dropping all host linker flags. --
commit fdc8f23a99f210f1577aab161879510c7af15c47
Author: Leo Yan <[email protected]>
tools build: Append extra host CFLAGS for fixdep
This commit introduces a local HOST_CFLAGS variable that combines KBUILD_HOSTCFLAGS and HOST_EXTRACFLAGS, and passes it to the fixdep build process to ensure host compiler options are included.
Quoted 4 lines
tools/build/Makefile +0
-0
[ ... ]
tools/build/Makefile endif · line 56
Quoted 3 lines
$(FIXDEP): $(FIXDEP_IN)
tools/build/Makefile +1
-1- $(QUIET_LINK)$(HOSTCC) $(FIXDEP_IN) $(KBUILD_HOSTLDFLAGS) -o $@ + $(QUIET_LINK)$(HOSTCC) $(FIXDEP_IN) $(HOST_CFLAGS) -o $@
[Severity: Low]
Does this unintentionally drop the host linker flags?
By replacing KBUILD_HOSTLDFLAGS with HOST_CFLAGS during the link step for the fixdep executable, we might be missing required linker flags like LFS options or custom library paths.
Should this step retain KBUILD_HOSTLDFLAGS instead of or in addition to HOST_CFLAGS when generating the binary?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
PATCH v7 9/23 tools: bootconfig: Append extra cflags
In reply to Leo YanAppend EXTRA_CFLAGS to CFLAGS so that additional flags can be applied to the compiler.
--- tools/bootconfig/Makefile | 1 + 1 file changed, 1 insertion(+)
tools/bootconfig/Makefile +1 -0
@@ -11,6 +11,7 @@ endif LIBSRC = $(srctree)/lib/bootconfig.c $(srctree)/include/linux/bootconfig.h override CFLAGS += -Wall -g -I$(CURDIR)/include +override CFLAGS += $(EXTRA_CFLAGS) ALL_TARGETS := bootconfig ALL_PROGRAMS := $(patsubst %,$(OUTPUT)%,$(ALL_TARGETS))
Signature · 1 line
2.34.1
PATCH v7 10/23 tools: counter: Append extra cflags
In reply to Leo YanAppend EXTRA_CFLAGS to CFLAGS so that additional flags can be applied to the compiler.
--- tools/counter/Makefile | 1 + 1 file changed, 1 insertion(+)
tools/counter/Makefile +1 -0
@@ -14,6 +14,7 @@ MAKEFLAGS += -r override CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include \ -I$(srctree)/tools/include +override CFLAGS += $(EXTRA_CFLAGS) ALL_TARGETS := counter_example counter_watch_events ALL_PROGRAMS := $(patsubst %,$(OUTPUT)%,$(ALL_TARGETS))
Signature · 1 line
2.34.1
Re: [PATCH v7 10/23] tools: counter: Append extra cflags
Quoted 4 lines · Leo Yan
Append
EXTRA_CFLAGSto CFLAGS so that additional flags can be applied to the compiler.Signed-off-by Leo Yan <[email protected]>
PATCH v7 11/23 tools: dma: Append extra cflags
In reply to Leo YanAppend EXTRA_CFLAGS to CFLAGS so that additional flags can be applied to the compiler.
--- tools/dma/Makefile | 1 + 1 file changed, 1 insertion(+)
tools/dma/Makefile +1 -0
@@ -17,6 +17,7 @@ endif MAKEFLAGS += -r override CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include +override CFLAGS += $(EXTRA_CFLAGS) ALL_TARGETS := dma_map_benchmark ALL_PROGRAMS := $(patsubst %,$(OUTPUT)%,$(ALL_TARGETS))
Signature · 1 line
2.34.1
PATCH v7 12/23 tools: gpio: Append extra cflags
In reply to Leo YanAppend EXTRA_CFLAGS to CFLAGS so that additional flags can be applied to the compiler.
--- tools/gpio/Makefile | 1 + 1 file changed, 1 insertion(+)
tools/gpio/Makefile +1 -0
@@ -17,6 +17,7 @@ endif MAKEFLAGS += -r override CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include +override CFLAGS += $(EXTRA_CFLAGS) ALL_TARGETS := lsgpio gpio-hammer gpio-event-mon gpio-watch ALL_PROGRAMS := $(patsubst %,$(OUTPUT)%,$(ALL_TARGETS))
Signature · 1 line
2.34.1
PATCH v7 13/23 tools: hv: Append extra cflags
In reply to Leo YanAppend EXTRA_CFLAGS to CFLAGS so that additional flags can be applied to the compiler.
--- tools/hv/Makefile | 1 + 1 file changed, 1 insertion(+)
tools/hv/Makefile +1 -0
@@ -18,6 +18,7 @@ MAKEFLAGS += -r override CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include override CFLAGS += -Wno-address-of-packed-member +override CFLAGS += $(EXTRA_CFLAGS) ALL_TARGETS := hv_kvp_daemon hv_vss_daemon ifneq ($(filter x86_64 x86,$(ARCH)),)
Signature · 1 line
2.34.1
PATCH v7 14/23 tools: iio: Append extra cflags
In reply to Leo YanAppend EXTRA_CFLAGS to CFLAGS so that additional flags can be applied to the compiler.
--- tools/iio/Makefile | 1 + 1 file changed, 1 insertion(+)
tools/iio/Makefile +1 -0
@@ -13,6 +13,7 @@ endif MAKEFLAGS += -r override CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include +override CFLAGS += $(EXTRA_CFLAGS) ALL_TARGETS := iio_event_monitor lsiio iio_generic_buffer ALL_PROGRAMS := $(patsubst %,$(OUTPUT)%,$(ALL_TARGETS))
Signature · 1 line
2.34.1
PATCH v7 15/23 tools: mm: Append extra cflags
In reply to Leo YanAppend EXTRA_CFLAGS to CFLAGS so that additional flags can be applied to the compiler.
--- tools/mm/Makefile | 1 + 1 file changed, 1 insertion(+)
tools/mm/Makefile +1 -0
@@ -10,6 +10,7 @@ LIB_DIR = ../lib/api LIBS = $(LIB_DIR)/libapi.a CFLAGS += -Wall -Wextra -I../lib/ -pthread +CFLAGS += $(EXTRA_CFLAGS) LDFLAGS += $(LIBS) -pthread all: $(BUILD_TARGETS)
Signature · 1 line
2.34.1
PATCH v7 16/23 tools: objtool: Append extra host cflags
In reply to Leo YanAppend HOST_EXTRACFLAGS to HOSTCFLAGS so that additional flags can be applied to the host compiler.
--- tools/objtool/Makefile | 2 ++ 1 file changed, 2 insertions(+)
tools/objtool/Makefile +2 -0
@@ -11,6 +11,8 @@ ifeq ($(SRCARCH),loongarch) BUILD_ORC := y endif +HOSTCFLAGS += $(HOST_EXTRACFLAGS) + ifeq ($(ARCH_HAS_KLP),y) HAVE_XXHASH = $(shell printf "$(pound)include <xxhash.h>\nXXH3_state_t *state;int main() {}" | \ $(HOSTCC) $(HOSTCFLAGS) -xc - -o /dev/null -lxxhash 2> /dev/null && echo y || echo n)
Signature · 1 line
2.34.1
PATCH v7 17/23 tools: power: acpi: Append extra cflags
In reply to Leo YanAppend EXTRA_CFLAGS to CFLAGS so that additional flags can be applied to the compiler.
--- tools/power/acpi/Makefile.config | 1 + 1 file changed, 1 insertion(+)
tools/power/acpi/Makefile.config +1 -0
@@ -69,6 +69,7 @@ KERNEL_INCLUDE := $(OUTPUT)include ACPICA_INCLUDE := $(srctree)/../../../drivers/acpi/acpica CFLAGS += -D_LINUX -I$(KERNEL_INCLUDE) -I$(ACPICA_INCLUDE) CFLAGS += $(WARNINGS) +CFLAGS += $(EXTRA_CFLAGS) MKDIR = mkdir ifeq ($(strip $(V)),false)
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH v7 17/23] tools: power: acpi: Append extra cflags
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] EXTRA_CFLAGS cannot override optimization and debug flags. --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] EXTRA_CFLAGS cannot override optimization and debug flags.
--
commit bdc57550350069918185456205e82edb378bafaf
Author: Leo Yan <[email protected]>
tools: power: acpi: Append extra cflags
Append EXTRA_CFLAGS to CFLAGS so that additional flags can be applied to the compiler.
tools/power/acpi/Makefile.config KERNEL_INCLUDE := $(OUTPUT)include · line 72
Quoted 8 lines
tools/power/acpi/Makefile.config +1
-0@@ -69,6 +69,7 @@ KERNEL_INCLUDE := $(OUTPUT)include ACPICA_INCLUDE := $(srctree)/../../../drivers/acpi/acpica CFLAGS += -D_LINUX -I$(KERNEL_INCLUDE) -I$(ACPICA_INCLUDE) CFLAGS += $(WARNINGS) +CFLAGS += $(EXTRA_CFLAGS)
[Severity: Low]
Will appending EXTRA_CFLAGS here prevent it from overriding the default optimization and debug flags?
Because CFLAGS are evaluated sequentially by the compiler, any flags added later in the file will override earlier ones. Further down in tools/power/acpi/Makefile.config, the optimization flags are appended:
# if DEBUG is enabled, then we do not strip or optimize ifeq ($(strip $(DEBUG)),true) CFLAGS += -O1 -g -DDEBUG STRIPCMD = /bin/true -Since_we_are_debugging else CFLAGS += $(OPTIMIZATION) -fomit-frame-pointer STRIPCMD = $(STRIP) -s --remove-section=.note --remove-section=.comment endif
It appears that user-provided optimization overrides (such as passing -O0 in EXTRA_CFLAGS) will be silently overridden by these defaults. Should EXTRA_CFLAGS be appended after the debug and optimization flags instead?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=17
PATCH v7 18/23 tools: power: x86/intel-speed-select: Append extra cflags
In reply to Leo YanAppend EXTRA_CFLAGS to CFLAGS so that additional flags can be applied to the compiler.
--- tools/power/x86/intel-speed-select/Makefile | 1 + 1 file changed, 1 insertion(+)
tools/power/x86/intel-speed-select/Makefile +1 -0
@@ -20,6 +20,7 @@ NL3_CFLAGS = -I/usr/include/libnl3 endif override CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include $(NL3_CFLAGS) +override CFLAGS += $(EXTRA_CFLAGS) override LDFLAGS += -lnl-genl-3 -lnl-3 ALL_TARGETS := intel-speed-select
Signature · 1 line
2.34.1
PATCH v7 19/23 tools: sched_ext: Append extra cflags
In reply to Leo YanAppend EXTRA_CFLAGS to CFLAGS so that additional flags can be applied to the compiler.
--- tools/sched_ext/Makefile | 1 + 1 file changed, 1 insertion(+)
tools/sched_ext/Makefile +1 -0
@@ -92,6 +92,7 @@ endif CFLAGS += -g -O2 -rdynamic -pthread -Wall -Werror $(GENFLAGS) \ -I$(INCLUDE_DIR) -I$(GENDIR) -I$(LIBDIR) \ -I$(TOOLSINCDIR) -I$(APIDIR) -I$(CURDIR)/include +CFLAGS += $(EXTRA_CFLAGS) # Silence some warnings when compiled with clang ifneq ($(LLVM),)
Signature · 1 line
2.34.1
Re: [PATCH v7 19/23] tools: sched_ext: Append extra cflags
Quoted 4 lines · Leo Yan
Append
EXTRA_CFLAGSto CFLAGS so that additional flags can be applied to the compiler.Signed-off-by Leo Yan <[email protected]>
Thanks.
Signature · 1 line
tejun
PATCH v7 20/23 tools: spi: Append extra cflags
In reply to Leo YanAppend EXTRA_CFLAGS to CFLAGS so that additional flags can be applied to the compiler.
--- tools/spi/Makefile | 1 + 1 file changed, 1 insertion(+)
tools/spi/Makefile +1 -0
@@ -13,6 +13,7 @@ endif MAKEFLAGS += -r CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include +CFLAGS += $(EXTRA_CFLAGS) ALL_TARGETS := spidev_test spidev_fdx ALL_PROGRAMS := $(patsubst %,$(OUTPUT)%,$(ALL_TARGETS))
Signature · 1 line
2.34.1
PATCH v7 21/23 tools: tracing: Append extra cflags
In reply to Leo YanAppend EXTRA_CFLAGS to CFLAGS so that additional flags can be applied to the compiler.
--- tools/tracing/latency/Makefile | 1 + tools/tracing/rtla/Makefile | 1 + 2 files changed, 2 insertions(+)
tools/tracing/latency/Makefile +1 -0
@@ -57,6 +57,7 @@ ifeq ($(config),1) endif CFLAGS += $(INCLUDES) $(LIB_INCLUDES) +CFLAGS += $(EXTRA_CFLAGS) export CFLAGS OUTPUT srctree
tools/tracing/rtla/Makefile +1 -0
@@ -67,6 +67,7 @@ ifeq ($(config),1) endif CFLAGS += $(INCLUDES) $(LIB_INCLUDES) +CFLAGS += $(EXTRA_CFLAGS) export CFLAGS OUTPUT srctree
Signature · 1 line
2.34.1
PATCH v7 22/23 tools: usb: Append extra cflags
In reply to Leo YanAppend EXTRA_CFLAGS to CFLAGS so that additional flags can be applied to the compiler.
--- tools/usb/Makefile | 1 + 1 file changed, 1 insertion(+)
tools/usb/Makefile +1 -0
@@ -14,6 +14,7 @@ endif MAKEFLAGS += -r override CFLAGS += -O2 -Wall -Wextra -g -D_GNU_SOURCE -I$(OUTPUT)include -I$(srctree)/tools/include +override CFLAGS += $(EXTRA_CFLAGS) override LDFLAGS += -lpthread ALL_TARGETS := testusb ffs-test
Signature · 1 line
2.34.1
PATCH v7 23/23 selftests: Include tools Makefile.include
In reply to Leo Yanselftests/lib.mk has its own compiler setup instead of using the common tools build helpers. This duplicates part of the LLVM handling prepared by tools/scripts/Makefile.include.
Include tools/scripts/Makefile.include from selftests/lib.mk so selftests reuse the LLVM prefix/suffix validation and the provided CLANG_CROSS_FLAGS. This improves Clang cross builds, especially when CROSS_COMPILE is set it can derive --prefix, --sysroot and --gcc-toolchain flags from the GCC cross toolchain.
Keep the $(CLANG_TARGET_FLAGS_$(ARCH)) target flag as a fallback when CLANG_CROSS_FLAGS is empty, and append EXTRA_CFLAGS to the selftest.
--- tools/testing/selftests/lib.mk | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-)
tools/testing/selftests/lib.mk +15 -15
@@ -1,11 +1,17 @@ # This mimics the top-level Makefile. We do it explicitly here so that this # Makefile can operate with or without the kbuild infrastructure. -ifneq ($(LLVM),) -ifneq ($(filter %/,$(LLVM)),) -LLVM_PREFIX := $(LLVM) -else ifneq ($(filter -%,$(LLVM)),) -LLVM_SUFFIX := $(LLVM) +ifeq (0,$(MAKELEVEL)) + ifeq ($(OUTPUT),) + OUTPUT := $(shell pwd) + DEFAULT_INSTALL_HDR_PATH := 1 + endif endif +selfdir = $(realpath $(dir $(filter %/lib.mk,$(MAKEFILE_LIST)))) +top_srcdir = $(selfdir)/../../.. + +include $(top_srcdir)/tools/scripts/Makefile.include + +ifneq ($(LLVM),) CLANG := $(LLVM_PREFIX)clang$(LLVM_SUFFIX)
@@ -35,7 +41,8 @@ else CLANG_FLAGS += --target=$(CLANG_TARGET_FLAGS) endif # CLANG_TARGET_FLAGS else -CLANG_FLAGS += --target=$(notdir $(CROSS_COMPILE:%-=%)) +# CLANG_CROSS_FLAGS comes from Makefile.include +CLANG_FLAGS += $(CLANG_CROSS_FLAGS) endif # CROSS_COMPILE # gcc defaults to silence (off) for the following warnings, but clang defaults
@@ -51,15 +58,6 @@ else CC := $(CROSS_COMPILE)gcc endif # LLVM -ifeq (0,$(MAKELEVEL)) - ifeq ($(OUTPUT),) - OUTPUT := $(shell pwd) - DEFAULT_INSTALL_HDR_PATH := 1 - endif -endif -selfdir = $(realpath $(dir $(filter %/lib.mk,$(MAKEFILE_LIST)))) -top_srcdir = $(selfdir)/../../.. - # msg: emit succinct information message describing current building step # $1 - generic step name (e.g., CC, LINK, etc); # $2 - optional "flavor" specifier; if provided, will be emitted as [flavor];
@@ -202,6 +200,8 @@ CFLAGS += -D_GNU_SOURCE= # Additional include paths needed by kselftest.h and local headers CFLAGS += -I${top_srcdir}/tools/testing/selftests +CFLAGS += $(EXTRA_CFLAGS) + # Enables to extend CFLAGS and LDFLAGS from command line, e.g. # make USERCFLAGS=-Werror USERLDFLAGS=-static CFLAGS += $(USERCFLAGS)
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH v7 23/23] selftests: Include tools Makefile.include
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] Including `tools/scripts/Makefile.include` inside `tools/testing/selftests/lib.mk` breaks normal…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Including tools/scripts/Makefile.include inside tools/testing/selftests/lib.mk breaks normal assignments to EXTRA_CFLAGS in selftest Makefiles, causing silent loss of compiler flags and test coverage. --
commit 969534670ab7ca5eb2e61c1ef0a49417bd7e304d
Author: Leo Yan <[email protected]>
selftests: Include tools Makefile.include
This commit includes tools/scripts/Makefile.include from selftests/lib.mk to reuse LLVM cross-build validation and flags. It aims to improve Clang cross builds by deriving cross-compile options directly from the GCC cross toolchain.
Quoted 5 lines
tools/testing/selftests/lib.mk +0
-0@@ -1,11 +1,17 @@
[ ... ]
tools/testing/selftests/lib.mk line 12
Quoted 4 lines
tools/testing/selftests/lib.mk +4
-0+selfdir = $(realpath $(dir $(filter %/lib.mk,$(MAKEFILE_LIST)))) +top_srcdir = $(selfdir)/../../.. + +include $(top_srcdir)/tools/scripts/Makefile.include
[Severity: Medium]
Does including Makefile.include here break EXTRA_CFLAGS assignments in individual selftest makefiles?
tools/scripts/Makefile.include modifies EXTRA_CFLAGS using the override directive:
override EXTRA_CFLAGS += $(FLAG_ZERO_INIT)
According to GNU Make semantics, once a variable has been appended using override, any subsequent normal assignments without override are ignored.
For example, tools/testing/selftests/x86/Makefile attempts to append flags later:
EXTRA_CFLAGS += -DCAN_BUILD_32
Because of the earlier override, this normal assignment is silently dropped. Consequently, tests like single_step_syscall.c evaluate #ifdef CAN_BUILD_32 as false in main(), silently skipping 32-bit specific test coverage.
Could this be resolved by either removing the override in Makefile.include or updating selftest makefiles to also use override for EXTRA_CFLAGS?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=23