tools build: Append -fzero-init-padding-bits=all option
Subsystems (21)
v5 cover tools build: Append -fzero-init-padding-bits=all option
Thank you for reviewing and commenting on v4.
For anyone new to the series, the reason for appending this compiler option is described in v3 (see "Link to v3" below).
In this version, the BPF related patches have been split out and will be sent separately (note that I have kept the bpftool patches in this series, as I have gathered Quentin's Acked-by tags).
The changes are organized into three parts:
Patches 01 – 05: Preparation before adding the new compiler option.
Fix typos, adjust Makefiles to ensure the newly introduced option does not cause regressions.
Patch 06: Propagate -fzero-init-padding-bits=all to
EXTRA_CFLAGS and HOST_EXTRACFLAGS for the CC and HOSTCC compilers, respectively.
Patches 07 – 26: Apply EXTRA_CFLAGS and HOST_EXTRACFLAGS in
project Makefiles.
The change has been verified:
Test 1: Cross compiling perf
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: Native compiling selftest bpf and sched_ext
host: gcc 15.2.0 (x86_64)
make -C tools/testing/selftests/ TARGETS="bpf sched_ext" SKIP_TARGETS=""
---
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]
Changes in v4:
- Placed EXTRA_CFLAGS last so it can override the default options (Ian).
- Cached evaluated values to avoid invoking cc-option when each
reference EXTRA_CFLAGS/HOST_EXTRACFLAGS (Ian).
- Dropped useless patches for feature, verification and nolibc
(Gabriele / Ian / Thomas).
- Fixed typos for thermal (Ian).
- Removed duplicate $(CLANG_CROSS_FLAGS) in libbpf (Ian).
- Collected maintainers' reviewed and ACK tags.
- Link to v3: https://lore.kernel.org/r/[email protected]
---
Leo Yan (26):
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
bpftool: Avoid adding EXTRA_CFLAGS to HOST_CFLAGS
tools build: Append -fzero-init-padding-bits=all to extra cflags
bpftool: Append extra host flags
perf build: Append extra host flags
tools build: Append extra host cflags
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/hid: Append extra cflags
selftests/nolibc: Append extra cflags
selftests/sched_ext: Append extra cflags
tools/bootconfig/Makefile | 1 + tools/bpf/bpftool/Makefile | 9 +++++++-- tools/build/Makefile | 6 ++++-- 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/hid/Makefile | 1 + tools/testing/selftests/nolibc/Makefile | 7 +++---- tools/testing/selftests/sched_ext/Makefile | 1 + tools/thermal/lib/Makefile | 20 ++++++++++--------- tools/tracing/latency/Makefile | 1 + tools/usb/Makefile | 1 + 23 files changed, 84 insertions(+), 27 deletions(-)
---
base-commit: a989fde763f4f24209e4702f50a45be572340e68
change-id: 20260224-tools_build_fix_zero_init-dc5261bd8b8b
Best regards,
Signature · 1 line
Leo Yan <[email protected]>
PATCH v5 1/26 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
PATCH v5 2/26 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
PATCH v5 3/26 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
PATCH v5 4/26 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 v5 5/26 bpftool: Avoid adding EXTRA_CFLAGS to HOST_CFLAGS
In reply to Leo YanPrepare for future changes where EXTRA_CFLAGS may include flags not applicable to the host compiler.
Move the HOST_CFLAGS assignment before appending EXTRA_CFLAGS to CFLAGS so that HOST_CFLAGS does not inherit flags from EXTRA_CFLAGS.
--- tools/bpf/bpftool/Makefile | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
tools/bpf/bpftool/Makefile +6 -2
@@ -81,6 +81,12 @@ CFLAGS += -DPACKAGE='"bpftool"' -D__EXPORTED_HEADERS__ \ ifneq ($(BPFTOOL_VERSION),) CFLAGS += -DBPFTOOL_VERSION='"$(BPFTOOL_VERSION)"' endif + +# This must be done before appending EXTRA_CFLAGS to CFLAGS to avoid +# including flags that are not applicable to the host compiler. +HOST_CFLAGS := $(subst -I$(LIBBPF_INCLUDE),-I$(LIBBPF_BOOTSTRAP_INCLUDE),\ + $(subst $(CLANG_CROSS_FLAGS),,$(CFLAGS))) + ifneq ($(EXTRA_CFLAGS),) CFLAGS += $(EXTRA_CFLAGS) endif
@@ -88,8 +94,6 @@ ifneq ($(EXTRA_LDFLAGS),) LDFLAGS += $(EXTRA_LDFLAGS) endif -HOST_CFLAGS := $(subst -I$(LIBBPF_INCLUDE),-I$(LIBBPF_BOOTSTRAP_INCLUDE),\ - $(subst $(CLANG_CROSS_FLAGS),,$(CFLAGS))) HOST_LDFLAGS := $(LDFLAGS) INSTALL ?= install
Signature · 1 line
2.34.1
PATCH v5 6/26 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
@@ -137,6 +137,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
Ian Rogers
reviewerRe: [PATCH v5 06/26] tools build: Append -fzero-init-padding-bits=all to extra cflags
Quoted 57 lines · Leo Yan
GCC-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_CFLAGSandHOST_EXTRACFLAGSrespectively.[1] https://gcc.gnu.org/gcc-15/changes.html
Acked-by Quentin Monnet <[email protected]>Acked-by Namhyung Kim <[email protected]>Signed-off-by Leo Yan <[email protected]>--- tools/scripts/Makefile.include | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)tools/scripts/Makefile.include +17
-0@@ -137,6 +137,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
tools/scripts/Makefile.include else · line 166
Quoted 10 lines
tools/scripts/Makefile.include +10
-0+# 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)
Sashiko [1] noted a possibly unintended consequence of this change for libbpf:
Does this override unintentionally drop the default compiler flags for libbpf?
Looking at tools/lib/bpf/Makefile, the default compiler flags like -g and -O2 are only applied if EXTRA_CFLAGS is undefined:
tools/lib/bpf/Makefile:
ifndef EXTRA_CFLAGSEXTRA_CFLAGS := -g -O2
endif
Since tools/scripts/Makefile.include unconditionally appends to EXTRA_CFLAGS here, the variable will be defined before tools/lib/bpf/Makefile evaluates it.
This causes libbpf to silently drop the default -g and -O2 flags.
While later commits in this series fix this exact issue for tools/lib/thermal/Makefile, it appears tools/lib/bpf/Makefile was missed.
Thanks,
Ian
[1] https://sashiko.dev/#/patchset/20260318-tools_build_fix_zero_init-v5-0-bbeffd8da199%40arm.com
Quoted 10 lines
tools/scripts/Makefile.include +3
-1+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 --2.34.1
Re: [PATCH v5 06/26] tools build: Append -fzero-init-padding-bits=all to extra cflags
Hi Ian,
On Wed, Mar 18, 2026 at 09:38:43AM -0700, Ian Rogers wrote:
[...]
Quoted 51 lines
Quoted 28 lines
tools/scripts/Makefile.include | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)tools/scripts/Makefile.include +17
-0@@ -137,6 +137,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-optiontools/scripts/Makefile.include else · line 166
Quoted 10 lines
tools/scripts/Makefile.include +10
-0+# 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)Sashiko [1] noted a possibly unintended consequence of this change for libbpf:
Does this override unintentionally drop the default compiler flags for libbpf?
Looking at
tools/lib/bpf/Makefile, the default compiler flags like -g and -O2 are only applied ifEXTRA_CFLAGSis undefined:
tools/lib/bpf/Makefile:
ifndefEXTRA_CFLAGSEXTRA_CFLAGS:= -g -O2
endif
Quoted 7 lines
Since
tools/scripts/Makefile.includeunconditionally appends toEXTRA_CFLAGShere, the variable will be defined beforetools/lib/bpf/Makefileevaluates it.This causes libbpf to silently drop the default -g and -O2 flags.
While later commits in this series fix this exact issue for
tools/lib/thermal/Makefile, it appearstools/lib/bpf/Makefilewas missed.
This is expected. As Alexei suggested, BPF patches should go via the bpf tree and be sent separately [2]. As a result, the AI review has no full context and misses the BPF pieces.
I will send a new series and a BPF/bpftool series separately. If AI still complains this, I'd suggest we simply ignore this false positive.
Thanks,
Leo
[email protected]
AI reviewRe: [PATCH v5 06/26] tools build: Append -fzero-init-padding-bits=all to extra cflags
In reply to Leo YanThank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider: - [High] Unconditional appending to `EXTRA_CFLAGS` breaks default optimization and debug flags for…
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] Unconditional appending to EXTRA_CFLAGS breaks default optimization and debug flags for libbpf.
- [High] The try-run macro attempts to write to the source tree during Makefile parsing, breaking out-of-tree builds on read-only filesystems.
- [Medium] The compiler flag -fzero-init-padding-bits=all is appended to HOST_EXTRACFLAGS, which is never evaluated by the tools build framework, resulting in silent omission of the flag for host programs like bpftool.
- [Medium] The try-run macro uses a predictable temporary directory name (.tmp_$$), exposing the build process to a local symlink attack (CWE-377).
--
--- Patch [6]: [PATCH v5 06/26] tools build: Append -fzero-init-padding-bits=all to extra cflags --- commit 526bce400539d6fdc8b0869f05e77b5305dcbce2
Author: Leo Yan <[email protected]>
tools build: Append -fzero-init-padding-bits=all to extra cflags
This commit adds -fzero-init-padding-bits=all for tools building to mitigate a new GCC-15 union initialization behavior. It implements cc-option and host-cc-option macros to dynamically detect support for this flag.
Quoted 4 lines
tools/scripts/Makefile.include +0
-0
[ ... ]
tools/scripts/Makefile.include else · line 148
Quoted 13 lines
tools/scripts/Makefile.include +9
-0@@ -137,6 +137,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; \
[Severity: Medium]
Is this predictable temporary directory safe against local symlink attacks?
If a user builds the kernel tools in a shared directory, an attacker could pre-create .tmp_<PID> directories containing a symlink named tmp pointing to a target file. Because mkdir -p succeeds on existing directories, the compiler command overwrites the attacker's symlink target.
tools/scripts/Makefile.include else · line 150
Quoted 2 lines
tools/scripts/Makefile.include +2
-0+ trap "rm -rf $(TMPOUT)" EXIT; \ + mkdir -p $(TMPOUT); \
[Severity: High]
Does this directory creation break out-of-tree builds on read-only trees?
Unlike Kbuild, tools Makefiles evaluate shell commands in the source tree directory. This attempts to write to the source tree instead of the designated output directory. The mkdir fails on a read-only filesystem, and set -e aborts the snippet, dropping the compiler flag check.
Quoted 4 lines
tools/scripts/Makefile.include +4
-0+ if ($(1)) >/dev/null 2>&1; \ + then echo "$(2)"; \ + else echo "$(3)"; \ + fi)
[ ... ]
tools/scripts/Makefile.include else · line 166
Quoted 3 lines
tools/scripts/Makefile.include +3
-0+# 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 unconditionally appending to EXTRA_CFLAGS break the default optimization and debug flags for libraries like libbpf?
Because Makefile.include is included before libbpf evaluates its flags, EXTRA_CFLAGS is always defined. This forces libbpf to bypass its fallback logic:
tools/lib/bpf/Makefile:
ifdef EXTRA_CFLAGS
CFLAGS := $(EXTRA_CFLAGS)
else
CFLAGS := -g -O2endif
and builds the library without debug symbols and optimizations.
tools/scripts/Makefile.include else · line 168
Quoted 2 lines
tools/scripts/Makefile.include +2
-0+HOST_FLAG_ZERO_INIT := $(call host-cc-option,-fzero-init-padding-bits=all) +override HOST_EXTRACFLAGS += $(HOST_FLAG_ZERO_INIT)
[Severity: Medium]
Is HOST_EXTRACFLAGS evaluated by the standalone tools build framework?
The tools build framework relies exclusively on HOSTCFLAGS for host programs, so appending to HOST_EXTRACFLAGS causes the flag to be ignored for tools like bpftool.
Quoted 4 lines
+
ifneq ($(findstring $(MAKEFLAGS), w),w)
PRINT_DIR= --no-print-directory
else
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
PATCH v5 7/26 bpftool: 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/bpf/bpftool/Makefile | 1 + 1 file changed, 1 insertion(+)
tools/bpf/bpftool/Makefile +1 -0
@@ -86,6 +86,7 @@ endif # including flags that are not applicable to the host compiler. HOST_CFLAGS := $(subst -I$(LIBBPF_INCLUDE),-I$(LIBBPF_BOOTSTRAP_INCLUDE),\ $(subst $(CLANG_CROSS_FLAGS),,$(CFLAGS))) +HOST_CFLAGS += $(HOST_EXTRACFLAGS) ifneq ($(EXTRA_CFLAGS),) CFLAGS += $(EXTRA_CFLAGS)
Signature · 1 line
2.34.1
PATCH v5 8/26 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 v5 9/26 tools build: 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/build/Makefile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
tools/build/Makefile +4 -2
@@ -40,14 +40,16 @@ endif FIXDEP := $(OUTPUT)fixdep FIXDEP_IN := $(OUTPUT)fixdep-in.o +HOSTCFLAGS := $(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="$(HOSTCFLAGS)"; \ rm -f $(FIXDEP).o; \ fi - $(Q)$(MAKE) $(build)=fixdep HOSTCFLAGS="$(KBUILD_HOSTCFLAGS)" + $(Q)$(MAKE) $(build)=fixdep HOSTCFLAGS="$(HOSTCFLAGS)" $(FIXDEP): $(FIXDEP_IN)
Signature · 1 line
2.34.1
PATCH v5 10/26 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 v5 11/26 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
PATCH v5 12/26 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 v5 13/26 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 v5 14/26 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 ($(ARCH), aarch64)
Signature · 1 line
2.34.1
PATCH v5 15/26 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 v5 16/26 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 v5 17/26 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
@@ -60,6 +60,8 @@ INCLUDES := -I$(srctree)/tools/include \ -I$(srctree)/tools/objtool/arch/$(SRCARCH)/include \ -I$(LIBSUBCMD_OUTPUT)/include +HOSTCFLAGS += $(HOST_EXTRACFLAGS) + OBJTOOL_CFLAGS := -std=gnu11 -fomit-frame-pointer -O2 -g $(WARNINGS) \ $(INCLUDES) $(LIBELF_FLAGS) $(LIBXXHASH_CFLAGS) $(HOSTCFLAGS)
Signature · 1 line
2.34.1
PATCH v5 18/26 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
PATCH v5 19/26 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 v5 20/26 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
PATCH v5 21/26 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 v5 22/26 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 + 1 file changed, 1 insertion(+)
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
Signature · 1 line
2.34.1
PATCH v5 23/26 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 v5 24/26 selftests/hid: Append extra cflags
In reply to Leo YanAppend EXTRA_CFLAGS to CFLAGS so that additional flags can be applied to the compiler.
--- tools/testing/selftests/hid/Makefile | 1 + 1 file changed, 1 insertion(+)
tools/testing/selftests/hid/Makefile +1 -0
@@ -26,6 +26,7 @@ HOSTPKG_CONFIG := pkg-config CFLAGS += -g -O0 -rdynamic -Wall -Werror -I$(OUTPUT) CFLAGS += -I$(OUTPUT)/tools/include +CFLAGS += $(EXTRA_CFLAGS) LDLIBS += -lelf -lz -lrt -lpthread
Signature · 1 line
2.34.1
PATCH v5 25/26 selftests/nolibc: Append extra cflags
In reply to Leo YanInclude tools/scripts/Makefile.include, which may provide additional flags in EXTRA_CFLAGS, and append to CFLAGS.
Since Makefile.include already defines cc-option, remove the redundant definition and include.
--- tools/testing/selftests/nolibc/Makefile | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
tools/testing/selftests/nolibc/Makefile +3 -4
@@ -3,18 +3,17 @@ TEST_GEN_PROGS := nolibc-test libc-test include ../lib.mk -include $(top_srcdir)/scripts/Makefile.compiler - -cc-option = $(call __cc-option, $(CC),,$(1),$(2)) +include $(top_srcdir)/tools/scripts/Makefile.include include Makefile.include $(OUTPUT)/nolibc-test: CFLAGS = -nostdlib -nostdinc -static \ -isystem $(top_srcdir)/tools/include/nolibc -isystem $(top_srcdir)/usr/include \ - $(CFLAGS_NOLIBC_TEST) + $(CFLAGS_NOLIBC_TEST) $(EXTRA_CFLAGS) $(OUTPUT)/nolibc-test: LDLIBS = $(if $(LLVM),,-lgcc) $(OUTPUT)/nolibc-test: nolibc-test.c nolibc-test-linkage.c | headers +$(OUTPUT)/libc-test: CFLAGS += $(EXTRA_CFLAGS) $(OUTPUT)/libc-test: nolibc-test.c nolibc-test-linkage.c $(call msg,CC,,$@) $(Q)$(LINK.c) $^ -o $@
Signature · 1 line
2.34.1
PATCH v5 26/26 selftests/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/testing/selftests/sched_ext/Makefile | 1 + 1 file changed, 1 insertion(+)
tools/testing/selftests/sched_ext/Makefile +1 -0
@@ -56,6 +56,7 @@ endif CFLAGS += -g -O2 -rdynamic -pthread -Wall -Werror $(GENFLAGS) \ -I$(INCLUDE_DIR) -I$(GENDIR) -I$(LIBDIR) \ -I$(TOOLSINCDIR) -I$(APIDIR) -I$(CURDIR)/include -I$(SCXTOOLSINCDIR) +CFLAGS += $(EXTRA_CFLAGS) # Silence some warnings when compiled with clang ifneq ($(LLVM),)
Signature · 1 line
2.34.1
Peter Zijlstra
maintainerQuoted 4 lines · Leo Yan
Thank you for reviewing and commenting on v4.
For anyone new to the series, the reason for appending this compiler option is described in v3 (see "Link to v3" below).
So why can't you just copy-paste that yourself, and save me from having to go find a browser and copy/paste the stupid link, just to find something that should have been here to begin with?!
Quoted 9 lines · Peter Zijlstra
Quoted 4 lines · Leo Yan
Thank you for reviewing and commenting on v4.
For anyone new to the series, the reason for appending this compiler option is described in v3 (see "Link to v3" below).
So why can't you just copy-paste that yourself, and save me from having to go find a browser and copy/paste the stupid link, just to find something that should have been here to begin with?!
Sorry about that!
I didn't expect a link to cause trouble. I'll include the information instead later.
Quentin Monnet
maintainer2026-03-18 09:16 UTC+0000 ~ Leo Yan <[email protected]>
Quoted 8 lines
Thank you for reviewing and commenting on v4.
For anyone new to the series, the reason for appending this compiler option is described in v3 (see "Link to v3" below).
In this version, the BPF related patches have been split out and will be sent separately (note that I have kept the bpftool patches in this series, as I have gathered Quentin's Acked-by tags).
Hi Leo, if it's all the same to you, could bpftool patches go through the bpf-next tree as well, please? (You can keep my tags, of course.)
Thanks,
Quentin
Quoted 6 lines · Quentin Monnet
2026-03-18 09:16 UTC+0000 ~ Leo Yan <[email protected]>
Quoted 5 lines
Thank you for reviewing and commenting on v4.
For anyone new to the series, the reason for appending this compiler option is described in v3 (see "Link to v3" below).
Quoted 7 lines
Quoted 3 lines
In this version, the BPF related patches have been split out and will be sent separately (note that I have kept the bpftool patches in this series, as I have gathered Quentin's Acked-by tags).
Hi Leo, if it's all the same to you, could bpftool patches go through the bpf-next tree as well, please? (You can keep my tags, of course.)
Sure!
I need to look into BPF CI failures, seems the extra cflags causes regressions in eBPF selftest [1][2]. After make things clear, I will send patch series separately (a common one and a BPF one).
Thanks,
Leo
[1] https://github.com/kernel-patches/bpf/actions/runs/23238743267/job/67551317220
[2] https://github.com/kernel-patches/bpf/actions/runs/23238743267/job/67551683133