Skip to contentSkip to conversation

tools build: Append -fzero-init-padding-bits=all option

PATCH Superseded Leo Yan 15 participants 77 messages Mar 8 – Mar 10

Subsystems (24)

v3 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Leo Yan

author
#0 lore raw

v3 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.

The variable name HOST_EXTRACFLAGS comes from kbuild conventions (see Documentation/kbuild/makefiles.rst).

This series is divided into three parts:

Patches 01 – 04: Preparation before adding the new compiler option.
These patches adjust Makefiles to ensure the newly introduced option does not cause regressions.
Patch 05: Propagate -fzero-init-padding-bits=all to
EXTRA_CFLAGS and HOST_EXTRACFLAGS for the CC and HOSTCC compilers, respectively.
Patches 06 – 30: Apply EXTRA_CFLAGS and HOST_EXTRACFLAGS in
project Makefiles.

The change has been verified:

Test 1: cross compiling perf with aarch64 GCC-15.2 [2]:

  ARCH=arm64 CROSS_COMPILE=aarch64-none-linux-gnu- \
       make LDFLAGS="-static" -C tools/perf VF=1 NO_JEVENTS=1 \
       DEBUG=1 V=1 NO_LIBELF=1 NO_LIBTRACEEVENT=1

Test 2: native selftest build on Arm64 machine:

make -C tools/testing/selftests TARGETS=hid SKIP_TARGETS="" V=1

[1] https://gcc.gnu.org/gcc-15/changes.html
[2] https://developer.arm.com/-/media/Files/downloads/gnu/15.2.rel1/binrel/arm-gnu-toolchain-15.2.rel1-x86_64-aarch64-none-linux-gnu.tar.xz

---
Changes in v3:
- Extended to support cross compilation (Quentin).
- Link to v2: https://lore.kernel.org/r/[email protected]

---
Leo Yan (30):
bpftool: Avoid adding EXTRA_CFLAGS to HOST_CFLAGS
libbpf: Initialize CFLAGS before including Makefile.include
tools: lib: thermal: Initialize CFLAGS before including Makefile.include tools/thermal: Initialize CFLAGS before including Makefile.include tools build: Append -fzero-init-padding-bits=all to extra cflags
bpftool: Append extra host flags
perf build: Append extra host flags
tools/bpf: build: Append extra cflags
tools build: Append extra host cflags
tools build: Append extra cflags for feature
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: nolibc: 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
tools: verification: Append extra cflags
selftests/bpf: 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/Makefile                             |  1 +
 tools/bpf/bpftool/Makefile                     |  9 +++++++--
 tools/build/Makefile                           |  6 ++++--
 tools/build/feature/Makefile                   |  2 ++
 tools/counter/Makefile                         |  1 +
 tools/dma/Makefile                             |  1 +
 tools/gpio/Makefile                            |  1 +
 tools/hv/Makefile                              |  1 +
 tools/iio/Makefile                             |  1 +
 tools/include/nolibc/Makefile                  |  2 +-
 tools/lib/bpf/Makefile                         | 16 ++++++++-------
 tools/lib/thermal/Makefile                     | 16 ++++++++-------
 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                 | 28 ++++++++++++++++++++++++++
 tools/spi/Makefile                             |  1 +
 tools/testing/selftests/bpf/Makefile           |  1 +
 tools/testing/selftests/hid/Makefile           |  1 +
 tools/testing/selftests/nolibc/Makefile.nolibc |  3 +++
 tools/testing/selftests/sched_ext/Makefile     |  1 +
 tools/thermal/lib/Makefile                     | 16 ++++++++-------
 tools/tracing/latency/Makefile                 |  1 +
 tools/usb/Makefile                             |  1 +
 tools/verification/rv/Makefile                 |  1 +
 29 files changed, 93 insertions(+), 27 deletions(-)

---
base-commit: 4ae12d8bd9a830799db335ee661d6cbc6597f838
change-id: 20260224-tools_build_fix_zero_init-dc5261bd8b8b

Best regards,

Signature · 1 line
Leo Yan <[email protected]>
author
#1 lore raw

PATCH v3 1/30 bpftool: Avoid adding EXTRA_CFLAGS to HOST_CFLAGS

Prepare 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
index 519ea5cb8ab1c0ee31acc67fc5f96b40e21005c2..3e7d8359e1b2a81a29a47544be8539e3b191a0e8 100644
@@ -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
maintainer Acked-by on v3 1/30
#2 lore raw

Re: [PATCH v3 01/30] bpftool: Avoid adding EXTRA_CFLAGS to HOST_CFLAGS

2026-03-08 16:46 UTC+0000 ~ Leo Yan <[email protected]>

Quoted 7 lines

Prepare 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.

reviewer
#3 lore raw

Re: [PATCH v3 01/30] bpftool: Avoid adding EXTRA_CFLAGS to HOST_CFLAGS

In reply to Leo Yan
Quoted 30 lines · Leo Yan

Prepare 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 -0
index 519ea5cb8ab1c0ee31acc67fc5f96b40e21005c2..3e7d8359e1b2a81a29a47544be8539e3b191a0e8 100644
@@ -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

tools/bpf/bpftool/Makefile ifneq ($(EXTRA_LDFLAGS),) · line 97

Quoted 6 lines
tools/bpf/bpftool/Makefile +0 -2
@@ -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)

This isn't an issue with the patch but AI code review is noting that "LDFLAGS += $(EXTRA_LDFLAGS)" happens above, and then here, "HOST_LDFLAGS := $(LDFLAGS)". This means something like EXTRA_LDFLAGS="--sysroot=/my/target" in the build would cause the host ld to pick up the --sysroot flag and probably break host builds which likely use the host bpftool when cross-compiling (perf's build should use the host bpftool). If the HOST_LDFLAGS were set to LDFLAGS before EXTRA_LDFLAGS are appended, this would not be an issue.

Thanks,
Ian

Quoted 5 lines
tools/bpf/bpftool/Makefile +0 -1
 INSTALL ?= install
 
--

2.34.1

maintainer
#4 lore raw

Re: [PATCH v3 01/30] bpftool: Avoid adding EXTRA_CFLAGS to HOST_CFLAGS

2026-03-09 10:40 UTC-0700 ~ Ian Rogers <[email protected]>

Quoted 34 lines · Leo Yan
Quoted 33 lines

Prepare 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 -0
index 519ea5cb8ab1c0ee31acc67fc5f96b40e21005c2..3e7d8359e1b2a81a29a47544be8539e3b191a0e8 100644
@@ -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
 
Quoted 12 lines

tools/bpf/bpftool/Makefile ifneq ($(EXTRA_LDFLAGS),) · line 97

Quoted 3 lines
tools/bpf/bpftool/Makefile +0 -2
-HOST_CFLAGS := $(subst -I$(LIBBPF_INCLUDE),-I$(LIBBPF_BOOTSTRAP_INCLUDE),\
-               $(subst $(CLANG_CROSS_FLAGS),,$(CFLAGS)))
 HOST_LDFLAGS := $(LDFLAGS)

This isn't an issue with the patch but AI code review is noting that "LDFLAGS += $(EXTRA_LDFLAGS)" happens above, and then here, "HOST_LDFLAGS := $(LDFLAGS)". This means something like EXTRA_LDFLAGS="--sysroot=/my/target" in the build would cause the host ld to pick up the --sysroot flag and probably break host builds which likely use the host bpftool when cross-compiling (perf's build should use the host bpftool). If the HOST_LDFLAGS were set to LDFLAGS before EXTRA_LDFLAGS are appended, this would not be an issue.

I noticed it when reviewing, but if the HOST_LDFLAGS were set before EXTRA_LDFLAGS, we wouldn't be able to pass additional HOST_LDFLAGS via any "EXTRA_..." variable, which would look inconsistent with how bpftool's Makefile handles the HOST_CFLAGS. I suppose the right fix would be to move HOST_LDFLAGS before EXTRA_LDFLAGS as you (and the AI) suggest, but also to add a HOST_EXTRALDFLAGS to it? Although I've not heard of any use case for passing different ld flags when cross-compiling bpftool, yet.

Quentin

author
#5 lore raw

PATCH v3 2/30 libbpf: Initialize CFLAGS before including Makefile.include

In reply to Leo Yan

Initialize CFLAGS to the default value before including tools/scripts/Makefile.include.

Defer appending EXTRA_CFLAGS to CFLAGS until after including Makefile.include, as it may extend EXTRA_CFLAGS in the future.

---
 tools/lib/bpf/Makefile | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
tools/lib/bpf/Makefile +9 -7
index 168140f8e6461bd06db40e23d21a3fb8847ccbf4..76cc802375f67b9d8f589904bd9764040947e5dd 100644
@@ -49,6 +49,14 @@ man_dir_SQ = '$(subst ','\'',$(man_dir))'
 export man_dir man_dir_SQ INSTALL
 export DESTDIR DESTDIR_SQ
 
+# 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 -O2
+endif
+
 include $(srctree)/tools/scripts/Makefile.include
 
 # copy a bit from Linux kbuild
@@ -70,14 +78,8 @@ LIB_TARGET	= libbpf.a libbpf.so.$(LIBBPF_VERSION)
 LIB_FILE	= libbpf.a libbpf.so*
 PC_FILE		= libbpf.pc
 
-# Set compile option CFLAGS
-ifdef EXTRA_CFLAGS
-  CFLAGS := $(EXTRA_CFLAGS)
-else
-  CFLAGS := -g -O2
-endif
-
 # Append required CFLAGS
+override CFLAGS += $(EXTRA_CFLAGS)
 override CFLAGS += -std=gnu89
 override CFLAGS += $(EXTRA_WARNINGS) -Wno-switch-enum
 override CFLAGS += -Werror -Wall
Signature · 1 line
2.34.1
reviewer
#6 lore raw

Re: [PATCH v3 02/30] libbpf: Initialize CFLAGS before including Makefile.include

Quoted 37 lines · Leo Yan

Initialize CFLAGS to the default value before including tools/scripts/Makefile.include.

Defer appending EXTRA_CFLAGS to CFLAGS until after including Makefile.include, as it may extend EXTRA_CFLAGS in the future.

---
 tools/lib/bpf/Makefile | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
tools/lib/bpf/Makefile +8 -2
index 168140f8e6461bd06db40e23d21a3fb8847ccbf4..76cc802375f67b9d8f589904bd9764040947e5dd 100644
@@ -49,6 +49,14 @@ man_dir_SQ = '$(subst ','\'',$(man_dir))'
 export man_dir man_dir_SQ INSTALL
 export DESTDIR DESTDIR_SQ
 
+# 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 -O2
+endif
+
 include $(srctree)/tools/scripts/Makefile.include
 
 # copy a bit from Linux kbuild
@@ -70,14 +78,8 @@ LIB_TARGET   = libbpf.a libbpf.so.$(LIBBPF_VERSION)
 LIB_FILE       = libbpf.a libbpf.so*
 PC_FILE                = libbpf.pc
 
-# Set compile option CFLAGS
-ifdef EXTRA_CFLAGS

tools/lib/bpf/Makefile LIB_TARGET = libbpf.a libbpf.so.$(LIBBPF_VERSION) · line 85

Quoted 10 lines
tools/lib/bpf/Makefile +1 -5
-  CFLAGS := $(EXTRA_CFLAGS)
-else
-  CFLAGS := -g -O2
-endif
-
 # Append required CFLAGS
+override CFLAGS += $(EXTRA_CFLAGS)
 override CFLAGS += -std=gnu89
 override CFLAGS += $(EXTRA_WARNINGS) -Wno-switch-enum
 override CFLAGS += -Werror -Wall

Not a problem with the change but AI assisted code review noticed something unusual. Below here is:
https://web.git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/lib/bpf/Makefile#n87

```
override CFLAGS += $(CLANG_CROSS_FLAGS)
```
and $(srctree)/tools/scripts/Makefile.include has when CROSS_COMPILE is set:
https://web.git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/scripts/Makefile.include#n116
```
CFLAGS += $(CLANG_CROSS_FLAGS)
```

so it looks like the CFLAGS is duplicating $(CLANG_CROSS_FLAGS).

Thanks,
Ian

Quoted 3 lines

--
2.34.1

author
#7 lore raw

PATCH v3 3/30 tools: lib: thermal: Initialize CFLAGS before including Makefile.include

In reply to Leo Yan

Initialize CFLAGS to the default value before including tools/scripts/Makefile.include.

Defer appending EXTRA_CFLAGS to CFLAGS until after including Makefile.include, as it may extend EXTRA_CFLAGS in the future.

---
 tools/lib/thermal/Makefile | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
tools/lib/thermal/Makefile +9 -7
index 41aa7a324ff4d76351b89d7d7cf382df3fc14052..50efa97163fc089455161d6b81db13aa0ae41af6 100644
@@ -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
@@ -60,6 +61,7 @@ INCLUDES = \
 -I$(srctree)/tools/include/uapi
 
 # Append required CFLAGS
+override CFLAGS += $(EXTRA_CFLAGS)
 override CFLAGS += $(EXTRA_WARNINGS)
 override CFLAGS += -Werror -Wall
 override CFLAGS += -fPIC
Signature · 1 line
2.34.1
reviewer
#8 lore raw

Re: [PATCH v3 03/30] tools: lib: thermal: Initialize CFLAGS before including Makefile.include

Quoted 46 lines · Leo Yan

Initialize CFLAGS to the default value before including tools/scripts/Makefile.include.

Defer appending EXTRA_CFLAGS to CFLAGS until after including Makefile.include, as it may extend EXTRA_CFLAGS in the future.

---
 tools/lib/thermal/Makefile | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
tools/lib/thermal/Makefile +8 -7
index 41aa7a324ff4d76351b89d7d7cf382df3fc14052..50efa97163fc089455161d6b81db13aa0ae41af6 100644
@@ -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

tools/lib/thermal/Makefile INCLUDES = \ · line 67

Quoted 7 lines
tools/lib/thermal/Makefile +1 -0
@@ -60,6 +61,7 @@ INCLUDES = \
 -I$(srctree)/tools/include/uapi
 
 # Append required CFLAGS
+override CFLAGS += $(EXTRA_CFLAGS)
 override CFLAGS += $(EXTRA_WARNINGS)
 override CFLAGS += -Werror -Wall
 override CFLAGS += -fPIC

The change lgtm. Running this patch through an AI review showed that what looks like a typo, CFLAGS becoming CFGLAS, is located below:
https://web.git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/lib/thermal/Makefile#n62

```
# Append required CFLAGS
override CFLAGS += $(EXTRA_WARNINGS)
override CFLAGS += -Werror -Wall
override CFLAGS += -fPIC
override CFLAGS += $(NL3_CFLAGS)
override CFLAGS += $(INCLUDES)
override CFLAGS += -fvisibility=hidden
override CFGLAS += -Wl,-L.
override CFGLAS += -Wl,-lthermal
```

Thanks,
Ian

Quoted 3 lines

--
2.34.1

author
#9 lore raw

PATCH v3 4/30 tools/thermal: Initialize CFLAGS before including Makefile.include

In reply to Leo Yan

Initialize CFLAGS to the default value before including tools/scripts/Makefile.include.

Defer appending EXTRA_CFLAGS to CFLAGS until after including Makefile.include, as it may extend EXTRA_CFLAGS in the future.

---
 tools/thermal/lib/Makefile | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
tools/thermal/lib/Makefile +9 -7
index 056d212f25cf51cd8c02260fbe2ef28dda5e4acb..1890779f1574ebd9015f3001b9bb31d4bc0ae5ce 100644
@@ -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 \
@@ -56,6 +57,7 @@ INCLUDES = \
 -I$(srctree)/tools/include/uapi
 
 # Append required CFLAGS
+override CFLAGS += $(EXTRA_CFLAGS)
 override CFLAGS += $(EXTRA_WARNINGS)
 override CFLAGS += -Werror -Wall
 override CFLAGS += -fPIC
Signature · 1 line
2.34.1
#10 lore raw

Re: [PATCH v3 04/30] tools/thermal: Initialize CFLAGS before including Makefile.include

Hi Leo,

Quoted 17 lines · Leo Yan

Initialize CFLAGS to the default value before including tools/scripts/Makefile.include.

Defer appending EXTRA_CFLAGS to CFLAGS until after including Makefile.include, as it may extend EXTRA_CFLAGS in the future.

---
  tools/thermal/lib/Makefile | 16 +++++++++-------
  1 file changed, 9 insertions(+), 7 deletions(-)
tools/thermal/lib/Makefile +0 -0
index 056d212f25cf51cd8c02260fbe2ef28dda5e4acb..1890779f1574ebd9015f3001b9bb31d4bc0ae5ce 100644
@@ -23,6 +23,14 @@ INSTALL = install
  DESTDIR ?=

tools/thermal/lib/Makefile INSTALL = install · line 33

Quoted 10 lines
tools/thermal/lib/Makefile +8 -0
  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
+

Sorry, I don't get the comment :/

Can you clarify the intended purpose with this change and the 'override' directive below ?

Quoted 26 lines
tools/thermal/lib/Makefile +1 -7
  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 \
@@ -56,6 +57,7 @@ INCLUDES = \
  -I$(srctree)/tools/include/uapi
 
  # Append required CFLAGS
+override CFLAGS += $(EXTRA_CFLAGS)
  override CFLAGS += $(EXTRA_WARNINGS)
  override CFLAGS += -Werror -Wall
  override CFLAGS += -fPIC
author
#11 lore raw

Re: [PATCH v3 04/30] tools/thermal: Initialize CFLAGS before including Makefile.include

Hi Daniel,

On Mon, Mar 09, 2026 at 09:41:16AM +0100, Daniel Lezcano wrote:

[...]

Quoted 30 lines · Leo Yan
Quoted 16 lines

Initialize CFLAGS to the default value before including tools/scripts/Makefile.include.

Defer appending EXTRA_CFLAGS to CFLAGS until after including Makefile.include, as it may extend EXTRA_CFLAGS in the future.

---
  tools/thermal/lib/Makefile | 16 +++++++++-------
  1 file changed, 9 insertions(+), 7 deletions(-)
tools/thermal/lib/Makefile +0 -0
index 056d212f25cf51cd8c02260fbe2ef28dda5e4acb..1890779f1574ebd9015f3001b9bb31d4bc0ae5ce 100644

tools/thermal/lib/Makefile INSTALL = install · line 32

Quoted 10 lines
tools/thermal/lib/Makefile +8 -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
+

Sorry, I don't get the comment :/

Quoted 1 line

Can you clarify the intended purpose with this change ?

Sure. Since this series sets EXTRA_CFLAGS in Makefile.include (patch 05). Without this patch, the init behavior of the thermal Makefile may change.

For example:

make -C tools/thermal/lib/

Before this series, the Makefile initializes:

CFLAGS := -g -Wall

If _only_ patch 05 is applied, EXTRA_CFLAGS is implicitly set in tools/scripts/Makefile.include to work around compiler bugs. The Makefile would initialize:

  CFLAGS := $(EXTRA_CFLAGS)

This patch preserves the original initialization of CFLAGS, but changes the sequence:

  CFLAGS := -g -Wall
  CFLAGS += $(EXTRA_CFLAGS)

If $(EXTRA_CFLAGS) is set by Makefile.include, it will be appended. Otherwise, if $(EXTRA_CFLAGS) is empty, the behavior remains unchanged.

Quoted 1 line

and the 'override' directive below ?

The override directive is used to override any CFLAGS set on the make command line. This patch does not introduce the directive; it simply follows the existing style. As you can see, the following lines already use the directive when appending options.

Thanks,
Leo

Quoted 24 lines
Quoted 23 lines
tools/thermal/lib/Makefile +1 -7
  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 \
@@ -56,6 +57,7 @@ INCLUDES = \
  -I$(srctree)/tools/include/uapi
  # Append required CFLAGS
+override CFLAGS += $(EXTRA_CFLAGS)
  override CFLAGS += $(EXTRA_WARNINGS)
  override CFLAGS += -Werror -Wall
  override CFLAGS += -fPIC
 
#12 lore raw

Re: [PATCH v3 04/30] tools/thermal: Initialize CFLAGS before including Makefile.include

Hi Leo,

Quoted 64 lines · Leo Yan

Hi Daniel,

On Mon, Mar 09, 2026 at 09:41:16AM +0100, Daniel Lezcano wrote:

[...]

Quoted 30 lines · Leo Yan
Quoted 16 lines

Initialize CFLAGS to the default value before including tools/scripts/Makefile.include.

Defer appending EXTRA_CFLAGS to CFLAGS until after including Makefile.include, as it may extend EXTRA_CFLAGS in the future.

---
   tools/thermal/lib/Makefile | 16 +++++++++-------
   1 file changed, 9 insertions(+), 7 deletions(-)
tools/thermal/lib/Makefile +0 -0
index 056d212f25cf51cd8c02260fbe2ef28dda5e4acb..1890779f1574ebd9015f3001b9bb31d4bc0ae5ce 100644

tools/thermal/lib/Makefile INSTALL = install · line 32

Quoted 10 lines
tools/thermal/lib/Makefile +8 -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
+

Sorry, I don't get the comment :/

Quoted 1 line

Can you clarify the intended purpose with this change ?

Sure. Since this series sets EXTRA_CFLAGS in Makefile.include (patch 05). Without this patch, the init behavior of the thermal Makefile may change.

For example:

make -C tools/thermal/lib/

Before this series, the Makefile initializes:

CFLAGS := -g -Wall

If _only_ patch 05 is applied, EXTRA_CFLAGS is implicitly set in tools/scripts/Makefile.include to work around compiler bugs. The Makefile would initialize:

   CFLAGS := $(EXTRA_CFLAGS)

This patch preserves the original initialization of CFLAGS, but changes the sequence:

   CFLAGS := -g -Wall
   CFLAGS += $(EXTRA_CFLAGS)

If $(EXTRA_CFLAGS) is set by Makefile.include, it will be appended. Otherwise, if $(EXTRA_CFLAGS) is empty, the behavior remains unchanged.

Quoted 6 lines
Quoted 1 line

and the 'override' directive below ?

The override directive is used to override any CFLAGS set on the make command line. This patch does not introduce the directive; it simply follows the existing style. As you can see, the following lines already use the directive when appending options.

Thanks for the clarification

author
#13 lore raw

PATCH v3 5/30 tools build: Append -fzero-init-padding-bits=all to extra cflags

In reply to 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_CFLAGS and HOST_EXTRACFLAGS respectively.

[1] https://gcc.gnu.org/gcc-15/changes.html

---
 tools/scripts/Makefile.include | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
tools/scripts/Makefile.include +28 -0
index b5ecf137febcae59f506e107a7f2e2ad72f4bef4..bab3174565f0d1e40ec574a360a0fddcee641f7e 100644
@@ -137,6 +137,34 @@ 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 }'
+override EXTRA_CFLAGS += $(call cc-option,-fzero-init-padding-bits=all)
+override HOST_EXTRACFLAGS += $(call host-cc-option,-fzero-init-padding-bits=all)
+
 ifneq ($(findstring $(MAKEFLAGS), w),w)
 PRINT_DIR = --no-print-directory
 else
Signature · 1 line
2.34.1
maintainer Acked-by on v3 5/30
#14 lore raw

Re: [PATCH v3 05/30] tools build: Append -fzero-init-padding-bits=all to extra cflags

2026-03-08 16:46 UTC+0000 ~ Leo Yan <[email protected]>

Quoted 17 lines

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.

Quoted 8 lines

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

I can't speak for the maintainers of the other tools of course, but as far as bpftool is concerned, this looks OK to me. Thanks for this work!

reviewer
#15 lore raw

Re: [PATCH v3 05/30] tools build: Append -fzero-init-padding-bits=all to extra cflags

In reply to Leo Yan
Quoted 55 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_CFLAGS and HOST_EXTRACFLAGS respectively.

[1] https://gcc.gnu.org/gcc-15/changes.html

---
 tools/scripts/Makefile.include | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
tools/scripts/Makefile.include +17 -0
index b5ecf137febcae59f506e107a7f2e2ad72f4bef4..bab3174565f0d1e40ec574a360a0fddcee641f7e 100644
@@ -137,6 +137,34 @@ 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 }'
+override EXTRA_CFLAGS += $(call cc-option,-fzero-init-padding-bits=all)
+override HOST_EXTRACFLAGS += $(call host-cc-option,-fzero-init-padding-bits=all)

Could this slow down builds, as each reference to EXTRA_CFLAGS and HOST_EXTRACFLAGS will invoke cc-option, which shells out and runs cc? Perhaps you could evaluate the values once then reference them something like:

```makefile
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)
```

Thanks,
Ian

Quoted 8 lines
tools/scripts/Makefile.include +1 -1
+
 ifneq ($(findstring $(MAKEFLAGS), w),w)
 PRINT_DIR = --no-print-directory
 else
 
--

2.34.1

author
#16 lore raw

PATCH v3 6/30 bpftool: Append extra host flags

In reply to Leo Yan

Append 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
index 3e7d8359e1b2a81a29a47544be8539e3b191a0e8..762fcf0e62a189625053798dddeaf17d409fe248 100644
@@ -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
author
#18 lore raw

PATCH v3 7/30 perf build: Append extra host flags

In reply to Leo Yan

Append 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
index a8dc72cfe48eec52bd9e2352c46c88f5d8047765..f4004ec148a19c784bfe3ee9b5cc3901a3db25a3 100644
@@ -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
author
#19 lore raw

PATCH v3 8/30 tools/bpf: build: Append extra cflags

In reply to Leo Yan

Append EXTRA_CFLAGS to CFLAGS so that additional flags can be applied to the compiler.

---
 tools/bpf/Makefile | 1 +
 1 file changed, 1 insertion(+)
tools/bpf/Makefile +1 -0
index fd2585af1252669c59228af3a77320e449e1a1ab..f7d7978b4e2c1e592f980c2b8153608b9d821d89 100644
@@ -8,6 +8,7 @@ YACC = bison
 MAKE = make
 INSTALL ?= install
 
+CFLAGS += $(EXTRA_CFLAGS)
 CFLAGS += -Wall -O2
 CFLAGS += -D__EXPORTED_HEADERS__ -I$(srctree)/tools/include/uapi \
 	  -I$(srctree)/tools/include
Signature · 1 line
2.34.1
reviewer
#20 lore raw

Re: [PATCH v3 08/30] tools/bpf: build: Append extra cflags

Quoted 14 lines · Leo Yan

Append EXTRA_CFLAGS to CFLAGS so that additional flags can be applied to the compiler.

---
 tools/bpf/Makefile | 1 +
 1 file changed, 1 insertion(+)
tools/bpf/Makefile +0 -0
index fd2585af1252669c59228af3a77320e449e1a1ab..f7d7978b4e2c1e592f980c2b8153608b9d821d89 100644

tools/bpf/Makefile YACC = bison · line 14

Quoted 7 lines
tools/bpf/Makefile +1 -0
@@ -8,6 +8,7 @@ YACC = bison
 MAKE = make
 INSTALL ?= install
 
+CFLAGS += $(EXTRA_CFLAGS)
 CFLAGS += -Wall -O2
 CFLAGS += -D__EXPORTED_HEADERS__ -I$(srctree)/tools/include/uapi \
          -I$(srctree)/tools/include

Should appending to CFLAGS happen last so that the user can override the default CFLAGS values?

Thanks,
Ian

Quoted 3 lines

--
2.34.1

author
#21 lore raw

PATCH v3 9/30 tools build: Append extra host cflags

In reply to Leo Yan

Append 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
index 3a5a3808ab2a1dedd40f35ea322913e8a0788130..a86ce3d99e2bb1c005942d9c32191e6eaa55cf50 100644
@@ -40,14 +40,16 @@ endif
 FIXDEP		:= $(OUTPUT)fixdep
 FIXDEP_IN	:= $(OUTPUT)fixdep-in.o
 
+HOSTCFLAGS	:= $(HOST_EXTRACFLAGS) $(KBUILD_HOSTCFLAGS)
+
 # 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
author
#22 lore raw

PATCH v3 10/30 tools build: Append extra cflags for feature

In reply to Leo Yan

Append EXTRA_CFLAGS to CFLAGS so that additional flags can be applied to the feature build.

---
 tools/build/feature/Makefile | 2 ++
 1 file changed, 2 insertions(+)
tools/build/feature/Makefile +2 -0
index 1fbcb3ce74d2173072748a417fc63bd9a5b13888..103d8b71e7a4e8d0979242cfc95c1c0b946222b5 100644
@@ -1,6 +1,8 @@
 # SPDX-License-Identifier: GPL-2.0
 include ../../scripts/Makefile.include
 
+CFLAGS += $(EXTRA_CFLAGS)
+
 FILES=                                          \
          test-all.bin                           \
          test-backtrace.bin                     \
Signature · 1 line
2.34.1
reviewer
#23 lore raw

Re: [PATCH v3 10/30] tools build: Append extra cflags for feature

Quoted 14 lines · Leo Yan

Append EXTRA_CFLAGS to CFLAGS so that additional flags can be applied to the feature build.

---
 tools/build/feature/Makefile | 2 ++
 1 file changed, 2 insertions(+)
tools/build/feature/Makefile +0 -0
index 1fbcb3ce74d2173072748a417fc63bd9a5b13888..103d8b71e7a4e8d0979242cfc95c1c0b946222b5 100644

tools/build/feature/Makefile line 5

Quoted 5 lines
tools/build/feature/Makefile +2 -0
@@ -1,6 +1,8 @@
 # SPDX-License-Identifier: GPL-2.0
 include ../../scripts/Makefile.include
 
+CFLAGS += $(EXTRA_CFLAGS)
+

Is this necessary? In Makefile.feature:
https://web.git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/build/Makefile.feature#n11
The build invocation does "CFLAGS="$(EXTRA_CFLAGS)" and so the locally set CFLAGS appear to be ignored.

Thanks,
Ian

Quoted 7 lines
tools/build/feature/Makefile +0 -1
 FILES=                                          \
          test-all.bin                           \
          test-backtrace.bin                     \
 
--

2.34.1

author
#24 lore raw

Re: [PATCH v3 10/30] tools build: Append extra cflags for feature

Quoted 18 lines · Ian Rogers
Quoted 17 lines · Leo Yan

Append EXTRA_CFLAGS to CFLAGS so that additional flags can be applied to the feature build.

---
 tools/build/feature/Makefile | 2 ++
 1 file changed, 2 insertions(+)
tools/build/feature/Makefile +0 -0
index 1fbcb3ce74d2173072748a417fc63bd9a5b13888..103d8b71e7a4e8d0979242cfc95c1c0b946222b5 100644
@@ -1,6 +1,8 @@
 # SPDX-License-Identifier: GPL-2.0
 include ../../scripts/Makefile.include
 
Quoted 7 lines

tools/build/feature/Makefile line 5

Quoted 2 lines
tools/build/feature/Makefile +2 -0
+CFLAGS += $(EXTRA_CFLAGS)
+

Is this necessary? In Makefile.feature:
https://web.git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/build/Makefile.feature#n11
The build invocation does "CFLAGS="$(EXTRA_CFLAGS)" and so the locally set CFLAGS appear to be ignored.

You are right. So far, some projects (perf, latency, rtla and verification/rv) calls feature_check with "CFLAGS=$(EXTRA_CFLAGS) ...". I confirmed with pref build, the -fzero-init-padding-bits=all option has been properly appended and passed to feature build:

gcc -fzero-init-padding-bits=all -I/usr/include/python3.12 ...

As a result, it is useless for this patch. I will drop it.

Thanks,
Leo

author
#25 lore raw

PATCH v3 11/30 tools: bootconfig: Append extra cflags

In reply to Leo Yan

Append 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
index 90eb47c9d8de67b0ccc74a8de0af3a7e0b97feeb..6bbf4dfdb5b56fcb2a43ccda18b59a270778267b 100644
@@ -10,6 +10,7 @@ srctree := $(patsubst %/,%,$(dir $(srctree)))
 endif
 
 LIBSRC = $(srctree)/lib/bootconfig.c $(srctree)/include/linux/bootconfig.h
+override CFLAGS += $(EXTRA_CFLAGS)
 override CFLAGS += -Wall -g -I$(CURDIR)/include
 
 ALL_TARGETS := bootconfig
Signature · 1 line
2.34.1
maintainer Acked-by on v3 11/30
#26 lore raw

Re: [PATCH v3 11/30] tools: bootconfig: Append extra cflags

Quoted 4 lines · On Sun, 08 Mar 2026 16:46:16 +0000 Leo Yan <[email protected]> wrote:

Append EXTRA_CFLAGS to CFLAGS so that additional flags can be applied to the compiler.

This looks good to me.

Thanks,

Quoted 20 lines
---
 tools/bootconfig/Makefile | 1 +
 1 file changed, 1 insertion(+)
tools/bootconfig/Makefile +1 -0
index 90eb47c9d8de67b0ccc74a8de0af3a7e0b97feeb..6bbf4dfdb5b56fcb2a43ccda18b59a270778267b 100644
@@ -10,6 +10,7 @@ srctree := $(patsubst %/,%,$(dir $(srctree)))
 endif
 
 LIBSRC = $(srctree)/lib/bootconfig.c $(srctree)/include/linux/bootconfig.h
+override CFLAGS += $(EXTRA_CFLAGS)
 override CFLAGS += -Wall -g -I$(CURDIR)/include
 
 ALL_TARGETS := bootconfig
Signature · 2 lines
-- 
2.34.1
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
reviewer
#27 lore raw

Re: [PATCH v3 11/30] tools: bootconfig: Append extra cflags

In reply to Leo Yan
Quoted 14 lines · Leo Yan

Append 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 +0 -0
index 90eb47c9d8de67b0ccc74a8de0af3a7e0b97feeb..6bbf4dfdb5b56fcb2a43ccda18b59a270778267b 100644

tools/bootconfig/Makefile srctree := $(patsubst %/,%,$(dir $(srctree))) · line 14

Quoted 5 lines
tools/bootconfig/Makefile +1 -0
@@ -10,6 +10,7 @@ srctree := $(patsubst %/,%,$(dir $(srctree)))
 endif
 
 LIBSRC = $(srctree)/lib/bootconfig.c $(srctree)/include/linux/bootconfig.h
+override CFLAGS += $(EXTRA_CFLAGS)
 override CFLAGS += -Wall -g -I$(CURDIR)/include

Should the EXTRA_CFLAGS be appended last so that the user can override the default CFLAGS (e.g. switching off warnings) ?

Thanks,
Ian

Quoted 5 lines
tools/bootconfig/Makefile +0 -1
 ALL_TARGETS := bootconfig
 
--

2.34.1

author
#28 lore raw

PATCH v3 12/30 tools: counter: Append extra cflags

In reply to Leo Yan

Append 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
index d82d35a520f610260abb43f6ae28e56d73268231..c0628677af3807bdc331ce2dba92b4e5f1a25b68 100644
@@ -12,6 +12,7 @@ endif
 # (this improves performance and avoids hard-to-debug behaviour);
 MAKEFLAGS += -r
 
+override CFLAGS += $(EXTRA_CFLAGS)
 override CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include \
 	 -I$(srctree)/tools/include
 
Signature · 1 line
2.34.1
reviewer
#29 lore raw

Re: [PATCH v3 12/30] tools: counter: Append extra cflags

Quoted 14 lines · Leo Yan

Append 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 +0 -0
index d82d35a520f610260abb43f6ae28e56d73268231..c0628677af3807bdc331ce2dba92b4e5f1a25b68 100644

tools/counter/Makefile endif · line 17

Quoted 6 lines
tools/counter/Makefile +1 -0
@@ -12,6 +12,7 @@ endif
 # (this improves performance and avoids hard-to-debug behaviour);
 MAKEFLAGS += -r
 
+override CFLAGS += $(EXTRA_CFLAGS)
 override CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include \
         -I$(srctree)/tools/include

The append should probably happen last to allow the default values to be overridden.

Thanks,
Ian

Quoted 4 lines
tools/counter/Makefile +0 -1
--

2.34.1

author
#30 lore raw

PATCH v3 13/30 tools: dma: Append extra cflags

In reply to Leo Yan

Append 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
index e4abf37bf020ca613b6dca340299198cb887126a..bdca05c69a8a12a4f9419eed8c1df71adac4f26d 100644
@@ -16,6 +16,7 @@ endif
 # (this improves performance and avoids hard-to-debug behaviour);
 MAKEFLAGS += -r
 
+override CFLAGS += $(EXTRA_CFLAGS)
 override CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include
 
 ALL_TARGETS := dma_map_benchmark
Signature · 1 line
2.34.1
maintainer Acked-by on v3 13/30
#31 lore raw

Re: [PATCH v3 13/30] tools: dma: Append extra cflags

Quoted 14 lines · Leo Yan

Append 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 +0 -0
index e4abf37bf020ca613b6dca340299198cb887126a..bdca05c69a8a12a4f9419eed8c1df71adac4f26d 100644

tools/dma/Makefile endif · line 22

Quoted 7 lines
tools/dma/Makefile +1 -0
@@ -16,6 +16,7 @@ endif
  # (this improves performance and avoids hard-to-debug behaviour);
  MAKEFLAGS += -r
 
+override CFLAGS += $(EXTRA_CFLAGS)
  override CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include
 
  ALL_TARGETS := dma_map_benchmark
Signature · 2 lines
Thanks,
Qinxin
reviewer
#32 lore raw

Re: [PATCH v3 13/30] tools: dma: Append extra cflags

In reply to Leo Yan
Quoted 14 lines · Leo Yan

Append 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 +0 -0
index e4abf37bf020ca613b6dca340299198cb887126a..bdca05c69a8a12a4f9419eed8c1df71adac4f26d 100644

tools/dma/Makefile endif · line 20

Quoted 5 lines
tools/dma/Makefile +1 -0
@@ -16,6 +16,7 @@ endif
 # (this improves performance and avoids hard-to-debug behaviour);
 MAKEFLAGS += -r
 
+override CFLAGS += $(EXTRA_CFLAGS)
 override CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include

The append should probably happen last to allow the default values to be overridden.

Thanks,
Ian

Quoted 5 lines
tools/dma/Makefile +0 -1
 ALL_TARGETS := dma_map_benchmark
 
--

2.34.1

author
#33 lore raw

PATCH v3 14/30 tools: gpio: Append extra cflags

In reply to Leo Yan

Append 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
index 342e056c8c665ac075041ff7c7ca7ba94c691187..206fb6c91a569d64b1e4b906ada5ec866323053c 100644
@@ -16,6 +16,7 @@ endif
 # (this improves performance and avoids hard-to-debug behaviour);
 MAKEFLAGS += -r
 
+override CFLAGS += $(EXTRA_CFLAGS)
 override CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include
 
 ALL_TARGETS := lsgpio gpio-hammer gpio-event-mon gpio-watch
Signature · 1 line
2.34.1
maintainer Acked-by on v3 14/30
#34 lore raw

Re: [PATCH v3 14/30] tools: gpio: Append extra cflags

Quoted 22 lines · Leo Yan

Append 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 -1
index 342e056c8c665ac075041ff7c7ca7ba94c691187..206fb6c91a569d64b1e4b906ada5ec866323053c 100644
@@ -16,6 +16,7 @@ endif
 # (this improves performance and avoids hard-to-debug behaviour);
 MAKEFLAGS += -r
 
+override CFLAGS += $(EXTRA_CFLAGS)
 override CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include
 
 ALL_TARGETS := lsgpio gpio-hammer gpio-event-mon gpio-watch
 
--
Quoted 3 lines

2.34.1

reviewer
#35 lore raw

Re: [PATCH v3 14/30] tools: gpio: Append extra cflags

In reply to Leo Yan
Quoted 14 lines · Leo Yan

Append 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 +0 -0
index 342e056c8c665ac075041ff7c7ca7ba94c691187..206fb6c91a569d64b1e4b906ada5ec866323053c 100644

tools/gpio/Makefile endif · line 20

Quoted 5 lines
tools/gpio/Makefile +1 -0
@@ -16,6 +16,7 @@ endif
 # (this improves performance and avoids hard-to-debug behaviour);
 MAKEFLAGS += -r
 
+override CFLAGS += $(EXTRA_CFLAGS)
 override CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include

The append should probably happen last to allow the default values to be overridden.

Thanks,
Ian

Quoted 5 lines
tools/gpio/Makefile +0 -1
 ALL_TARGETS := lsgpio gpio-hammer gpio-event-mon gpio-watch
 
--

2.34.1

author
#36 lore raw

PATCH v3 15/30 tools: hv: Append extra cflags

In reply to Leo Yan

Append 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
index 34ffcec264ab0fdf7075d25456ef012cb866796b..e39c16325b451ee7c2ddc581cc4d168915472ed6 100644
@@ -16,6 +16,7 @@ endif
 # (this improves performance and avoids hard-to-debug behaviour);
 MAKEFLAGS += -r
 
+override CFLAGS += $(EXTRA_CFLAGS)
 override CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include
 override CFLAGS += -Wno-address-of-packed-member
 
Signature · 1 line
2.34.1
maintainer Reviewed-by on v3 15/30
#37 lore raw

RE: [EXTERNAL] [PATCH v3 15/30] tools: hv: Append extra cflags

Quoted 63 lines

-----Original Message-----
From: Leo Yan <[email protected]>
Sent: Sunday, March 8, 2026 12:46 PM
To: Arnaldo Carvalho de Melo <[email protected]>; Ian Rogers <[email protected]>; Namhyung Kim <[email protected]>; James Clark <[email protected]>; Kees Cook <[email protected]>; Quentin Monnet <[email protected]>; Nathan Chancellor <[email protected]>; Nicolas Schier <[email protected]>; Nick Desaulniers <[email protected]>; Bill Wendling <[email protected]>; Justin Stitt <[email protected]>; Alexei Starovoitov <[email protected]>; Daniel Borkmann <[email protected]>; Andrii Nakryiko <[email protected]>; Martin KaFai Lau <[email protected]>; Eduard Zingerman <[email protected]>; Song Liu <[email protected]>; Yonghong Song <[email protected]>; John Fastabend <[email protected]>; KP Singh <[email protected]>; Stanislav Fomichev <[email protected]>; Hao Luo <[email protected]>; Jiri Olsa <[email protected]>; Rafael J. Wysocki <[email protected]>; Daniel Lezcano <[email protected]>; Zhang Rui <[email protected]>; Lukasz Luba <[email protected]>; Peter Zijlstra <[email protected]>; Ingo Molnar <[email protected]>; Mark Rutland <[email protected]>; Alexander Shishkin <[email protected]>; Adrian Hunter <[email protected]>; Masami Hiramatsu <[email protected]>; William Breathitt Gray <[email protected]>; Barry Song <[email protected]>; Qinxin Xia <[email protected]>; Bartosz Golaszewski <[email protected]>; Kent Gibson <[email protected]>; KY Srinivasan <[email protected]>; Haiyang Zhang <[email protected]>; Wei Liu <[email protected]>; Dexuan Cui <[email protected]>; Long Li <[email protected]>; Jonathan Cameron <[email protected]>; David Lechner <[email protected]>; Nuno Sá <[email protected]>; Andy Shevchenko <[email protected]>; Andrew Morton <[email protected]>; Willy Tarreau <[email protected]>; Thomas Weißschuh <[email protected]>; Josh Poimboeuf <[email protected]>; Robert Moore <[email protected]>; Len Brown <[email protected]>; Srinivas Pandruvada <[email protected]>; Tejun Heo <[email protected]>; David Vernet <[email protected]>; Andrea Righi <[email protected]>; Changwoo Min <[email protected]>; Mark Brown <[email protected]>; Steven Rostedt <[email protected]>; Gabriele Monaco <[email protected]>; Shuah Khan <[email protected]>; Jiri Kosina <[email protected]>; Benjamin Tissoires <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; linux-perf- [email protected]; Leo Yan <[email protected]>
Subject: [EXTERNAL] [PATCH v3 15/30] tools: hv: Append extra cflags

[Some people who received this message don't often get email from [email protected]. Learn why this is important at
https://aka.ms/LearnAboutSenderIdentification ]

Append 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 +0 -0

index 34ffcec264ab0fdf7075d25456ef012cb866796b..e39c16325b451ee7c2ddc581cc4d1689 15472ed6 100644

tools/hv/Makefile endif · line 21

Quoted 6 lines
tools/hv/Makefile +1 -0
@@ -16,6 +16,7 @@ endif
 # (this improves performance and avoids hard-to-debug behaviour);
 MAKEFLAGS += -r
 
+override CFLAGS += $(EXTRA_CFLAGS)
 override CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include
 override CFLAGS += -Wno-address-of-packed-member
reviewer
#38 lore raw

Re: [PATCH v3 15/30] tools: hv: Append extra cflags

In reply to Leo Yan
Quoted 14 lines · Leo Yan

Append 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 +0 -0
index 34ffcec264ab0fdf7075d25456ef012cb866796b..e39c16325b451ee7c2ddc581cc4d168915472ed6 100644

tools/hv/Makefile endif · line 21

Quoted 6 lines
tools/hv/Makefile +1 -0
@@ -16,6 +16,7 @@ endif
 # (this improves performance and avoids hard-to-debug behaviour);
 MAKEFLAGS += -r
 
+override CFLAGS += $(EXTRA_CFLAGS)
 override CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include
 override CFLAGS += -Wno-address-of-packed-member

The append should probably happen last to allow the default values to be overridden.

Thanks,
Ian

Quoted 4 lines
tools/hv/Makefile +0 -1
--

2.34.1

author
#39 lore raw

PATCH v3 16/30 tools: iio: Append extra cflags

In reply to Leo Yan

Append 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
index 3bcce0b7d10f42208765be83dac047faa2e0ceb1..c189af6286751d141348957e4d63d33b87410381 100644
@@ -12,6 +12,7 @@ endif
 # (this improves performance and avoids hard-to-debug behaviour);
 MAKEFLAGS += -r
 
+override CFLAGS += $(EXTRA_CFLAGS)
 override CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include
 
 ALL_TARGETS := iio_event_monitor lsiio iio_generic_buffer
Signature · 1 line
2.34.1
reviewer
#40 lore raw

Re: [PATCH v3 16/30] tools: iio: Append extra cflags

Quoted 14 lines · Leo Yan

Append 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 +0 -0
index 3bcce0b7d10f42208765be83dac047faa2e0ceb1..c189af6286751d141348957e4d63d33b87410381 100644

tools/iio/Makefile endif · line 16

Quoted 5 lines
tools/iio/Makefile +1 -0
@@ -12,6 +12,7 @@ endif
 # (this improves performance and avoids hard-to-debug behaviour);
 MAKEFLAGS += -r
 
+override CFLAGS += $(EXTRA_CFLAGS)
 override CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include

The append should probably happen last to allow the default values to be overridden.

Thanks,
Ian

Quoted 5 lines
tools/iio/Makefile +0 -1
 ALL_TARGETS := iio_event_monitor lsiio iio_generic_buffer
 
--

2.34.1

author
#41 lore raw

PATCH v3 17/30 tools: mm: Append extra cflags

In reply to Leo Yan

Append 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
index f5725b5c23aa261994b5b42f37c443bee2edebf2..742c1639db0a6f7aee59cf8f4634cb40eacd49b2 100644
@@ -9,6 +9,7 @@ INSTALL_TARGETS = $(BUILD_TARGETS) thpmaps
 LIB_DIR = ../lib/api
 LIBS = $(LIB_DIR)/libapi.a
 
+CFLAGS += $(EXTRA_CFLAGS)
 CFLAGS += -Wall -Wextra -I../lib/ -pthread
 LDFLAGS += $(LIBS) -pthread
 
Signature · 1 line
2.34.1
reviewer
#42 lore raw

Re: [PATCH v3 17/30] tools: mm: Append extra cflags

Quoted 14 lines · Leo Yan

Append 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 +0 -0
index f5725b5c23aa261994b5b42f37c443bee2edebf2..742c1639db0a6f7aee59cf8f4634cb40eacd49b2 100644

tools/mm/Makefile INSTALL_TARGETS = $(BUILD_TARGETS) thpmaps · line 13

Quoted 5 lines
tools/mm/Makefile +1 -0
@@ -9,6 +9,7 @@ INSTALL_TARGETS = $(BUILD_TARGETS) thpmaps
 LIB_DIR = ../lib/api
 LIBS = $(LIB_DIR)/libapi.a
 
+CFLAGS += $(EXTRA_CFLAGS)
 CFLAGS += -Wall -Wextra -I../lib/ -pthread

The append should probably happen last to allow the default values to be overridden.

Thanks,
Ian

Quoted 6 lines
tools/mm/Makefile +0 -1
 LDFLAGS += $(LIBS) -pthread
 
 
--

2.34.1

author
#43 lore raw

PATCH v3 18/30 tools: nolibc: Append extra cflags

In reply to Leo Yan

Append EXTRA_CFLAGS to CFLAGS so that additional flags can be applied to the compiler.

---
 tools/include/nolibc/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/include/nolibc/Makefile +1 -1
index 1958dda988954d8a604b28f5feb75ebb67ee2e14..b7f0385ccba14fdaa08aab6192acf0296b47cdbc 100644
@@ -105,7 +105,7 @@ headers_standalone: headers
 	$(Q)$(MAKE) -C $(srctree) headers_install INSTALL_HDR_PATH=$(OUTPUT)sysroot
 
 CFLAGS_s390 := -m64
-CFLAGS := $(CFLAGS_$(ARCH))
+CFLAGS := $(CFLAGS_$(ARCH)) $(EXTRA_CFLAGS)
 
 headers_check: headers_standalone
 	$(Q)for header in $(filter-out crt.h std.h,$(all_files)); do \
Signature · 1 line
2.34.1
#44 lore raw

Re: [PATCH v3 18/30] tools: nolibc: Append extra cflags

Hi Leo,

Quoted 13 lines · Leo Yan

Append EXTRA_CFLAGS to CFLAGS so that additional flags can be applied to the compiler.

---
 tools/include/nolibc/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/include/nolibc/Makefile +0 -0
index 1958dda988954d8a604b28f5feb75ebb67ee2e14..b7f0385ccba14fdaa08aab6192acf0296b47cdbc 100644

tools/include/nolibc/Makefile headers_standalone: headers · line 108

Quoted 5 lines
tools/include/nolibc/Makefile +1 -1
@@ -105,7 +105,7 @@ headers_standalone: headers
 	$(Q)$(MAKE) -C $(srctree) headers_install INSTALL_HDR_PATH=$(OUTPUT)sysroot
 
 CFLAGS_s390 := -m64
-CFLAGS := $(CFLAGS_$(ARCH))
+CFLAGS := $(CFLAGS_$(ARCH)) $(EXTRA_CFLAGS)

I don't think we need additional cflags in tools/include/nolibc. The only thing this Makefile does is to test-compile some headers.

tools/include/nolibc/Makefile headers_standalone: headers · line 111

Quoted 2 lines
tools/include/nolibc/Makefile +0 -0
 headers_check: headers_standalone
 	$(Q)for header in $(filter-out crt.h std.h,$(all_files)); do \

Thomas

author
#45 lore raw

PATCH v3 19/30 tools: objtool: Append extra host cflags

In reply to Leo Yan

Append 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
index 76bcd4e85de345048bba0a6e0066c3cf61dac979..716e84cc33eaccb0e4ae592746eb1888edc2f850 100644
@@ -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
author
#47 lore raw

PATCH v3 20/30 tools: power: acpi: Append extra cflags

In reply to Leo Yan

Append 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
index cd7106876a5f39dfda38e286c54c3a7c268b34a2..4978c06828af7b0f47e533735ad82c962b7e0765 100644
@@ -67,6 +67,7 @@ WARNINGS += $(call cc-supports,-Wdeclaration-after-statement)
 
 KERNEL_INCLUDE := $(OUTPUT)include
 ACPICA_INCLUDE := $(srctree)/../../../drivers/acpi/acpica
+CFLAGS += $(EXTRA_CFLAGS)
 CFLAGS += -D_LINUX -I$(KERNEL_INCLUDE) -I$(ACPICA_INCLUDE)
 CFLAGS += $(WARNINGS)
 MKDIR = mkdir
Signature · 1 line
2.34.1
reviewer
#48 lore raw

Re: [PATCH v3 20/30] tools: power: acpi: Append extra cflags

Quoted 14 lines · Leo Yan

Append 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 +0 -0
index cd7106876a5f39dfda38e286c54c3a7c268b34a2..4978c06828af7b0f47e533735ad82c962b7e0765 100644

tools/power/acpi/Makefile.config WARNINGS += $(call cc-supports,-Wdeclaration-after-statement) · line 72

Quoted 6 lines
tools/power/acpi/Makefile.config +1 -0
@@ -67,6 +67,7 @@ WARNINGS += $(call cc-supports,-Wdeclaration-after-statement)
 
 KERNEL_INCLUDE := $(OUTPUT)include
 ACPICA_INCLUDE := $(srctree)/../../../drivers/acpi/acpica
+CFLAGS += $(EXTRA_CFLAGS)
 CFLAGS += -D_LINUX -I$(KERNEL_INCLUDE) -I$(ACPICA_INCLUDE)
 CFLAGS += $(WARNINGS)

The append should probably happen last to allow the default values to be overridden.

Thanks,
Ian

Quoted 5 lines
tools/power/acpi/Makefile.config +0 -1
 MKDIR = mkdir
 
--

2.34.1

author
#49 lore raw

PATCH v3 21/30 tools: power: x86/intel-speed-select: Append extra cflags

In reply to Leo Yan

Append 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
index 6b299aae2ded89c3a70a3649996e258b98001ee7..61d6e81f3cf1d6427addb4f31c1369ac663ba3d6 100644
@@ -19,6 +19,7 @@ ifeq ($(NL3_CFLAGS),)
 NL3_CFLAGS = -I/usr/include/libnl3
 endif
 
+override CFLAGS += $(EXTRA_CFLAGS)
 override CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include $(NL3_CFLAGS)
 override LDFLAGS += -lnl-genl-3 -lnl-3
 
Signature · 1 line
2.34.1
maintainer Acked-by on v3 21/30
#50 lore raw

Re: [PATCH v3 21/30] tools: power: x86/intel-speed-select: Append extra cflags

Quoted 5 lines · Leo Yan

Append EXTRA_CFLAGS to CFLAGS so that additional flags can be applied to
the compiler.

Quoted 20 lines

---
 tools/power/x86/intel-speed-select/Makefile | 1 +

 1 file changed, 1 insertion(+)
tools/power/x86/intel-speed-select/Makefile +0 -0

index 6b299aae2ded89c3a70a3649996e258b98001ee7..61d6e81f3cf1d6427addb4f31c1 369ac663ba3d6 100644

tools/power/x86/intel-speed-select/Makefile +0 -0
@@ -19,6 +19,7 @@ ifeq ($(NL3_CFLAGS),)

 NL3_CFLAGS = -I/usr/include/libnl3
 endif

+override CFLAGS += $(EXTRA_CFLAGS)
 override CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include $(NL3_CFLAGS)
 override LDFLAGS += -lnl-genl-3 -lnl-3

reviewer
#51 lore raw

Re: [PATCH v3 21/30] tools: power: x86/intel-speed-select: Append extra cflags

In reply to Leo Yan
Quoted 14 lines · Leo Yan

Append 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 +0 -0
index 6b299aae2ded89c3a70a3649996e258b98001ee7..61d6e81f3cf1d6427addb4f31c1369ac663ba3d6 100644

tools/power/x86/intel-speed-select/Makefile ifeq ($(NL3_CFLAGS),) · line 23

Quoted 5 lines
tools/power/x86/intel-speed-select/Makefile +1 -0
@@ -19,6 +19,7 @@ ifeq ($(NL3_CFLAGS),)
 NL3_CFLAGS = -I/usr/include/libnl3
 endif
 
+override CFLAGS += $(EXTRA_CFLAGS)
 override CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include $(NL3_CFLAGS)

The append should probably happen last to allow the default values to be overridden.

Thanks,
Ian

Quoted 6 lines
tools/power/x86/intel-speed-select/Makefile +0 -1
 override LDFLAGS += -lnl-genl-3 -lnl-3
 
 
--

2.34.1

author
#52 lore raw

PATCH v3 22/30 tools: sched_ext: Append extra cflags

In reply to Leo Yan

Append 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
index 21554f0896923fa9c2e5b98c85d65d964152e592..7b97af037ae55981bc84d4a9140766fdf4c62a6c 100644
@@ -89,6 +89,7 @@ ifneq ($(wildcard $(GENHDR)),)
   GENFLAGS := -DHAVE_GENHDR
 endif
 
+CFLAGS += $(EXTRA_CFLAGS)
 CFLAGS += -g -O2 -rdynamic -pthread -Wall -Werror $(GENFLAGS)			\
 	  -I$(INCLUDE_DIR) -I$(GENDIR) -I$(LIBDIR)				\
 	  -I$(TOOLSINCDIR) -I$(APIDIR) -I$(CURDIR)/include
Signature · 1 line
2.34.1
reviewer
#53 lore raw

Re: [PATCH v3 22/30] tools: sched_ext: Append extra cflags

Quoted 14 lines · Leo Yan

Append 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 +0 -0
index 21554f0896923fa9c2e5b98c85d65d964152e592..7b97af037ae55981bc84d4a9140766fdf4c62a6c 100644

tools/sched_ext/Makefile ifneq ($(wildcard $(GENHDR)),) · line 95

Quoted 7 lines
tools/sched_ext/Makefile +1 -0
@@ -89,6 +89,7 @@ ifneq ($(wildcard $(GENHDR)),)
   GENFLAGS := -DHAVE_GENHDR
 endif
 
+CFLAGS += $(EXTRA_CFLAGS)
 CFLAGS += -g -O2 -rdynamic -pthread -Wall -Werror $(GENFLAGS)                  \
          -I$(INCLUDE_DIR) -I$(GENDIR) -I$(LIBDIR)                              \
          -I$(TOOLSINCDIR) -I$(APIDIR) -I$(CURDIR)/include

The append should probably happen last to allow the default values to be overridden.

Thanks,
Ian

Quoted 3 lines

--
2.34.1

author
#54 lore raw

PATCH v3 23/30 tools: spi: Append extra cflags

In reply to Leo Yan

Append 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
index 7fccd245a53515ab019529c8e5e91a044eaaa68b..1e3b3f91634cc2561c434c02f812942fa881685f 100644
@@ -12,6 +12,7 @@ endif
 # (this improves performance and avoids hard-to-debug behaviour);
 MAKEFLAGS += -r
 
+CFLAGS += $(EXTRA_CFLAGS)
 CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include
 
 ALL_TARGETS := spidev_test spidev_fdx
Signature · 1 line
2.34.1
maintainer Acked-by on v3 23/30
#55 lore raw

Re: [PATCH v3 23/30] tools: spi: Append extra cflags

Quoted 2 lines · Leo Yan

Append EXTRA_CFLAGS to CFLAGS so that additional flags can be applied to the compiler.

reviewer
#56 lore raw

Re: [PATCH v3 23/30] tools: spi: Append extra cflags

In reply to Leo Yan
Quoted 14 lines · Leo Yan

Append 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 +0 -0
index 7fccd245a53515ab019529c8e5e91a044eaaa68b..1e3b3f91634cc2561c434c02f812942fa881685f 100644

tools/spi/Makefile endif · line 16

Quoted 5 lines
tools/spi/Makefile +1 -0
@@ -12,6 +12,7 @@ endif
 # (this improves performance and avoids hard-to-debug behaviour);
 MAKEFLAGS += -r
 
+CFLAGS += $(EXTRA_CFLAGS)
 CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include

The append should probably happen last to allow the default values to be overridden.

Thanks,
Ian

Quoted 5 lines
tools/spi/Makefile +0 -1
 ALL_TARGETS := spidev_test spidev_fdx
 
--

2.34.1

author
#57 lore raw

PATCH v3 24/30 tools: tracing: Append extra cflags

In reply to Leo Yan

Append 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
index 257a56b1899f23837de533353e9c2cebdb6035bd..1468640117dd540b2976cbcafb2371ab16e104e9 100644
@@ -56,6 +56,7 @@ ifeq ($(config),1)
   include Makefile.config
 endif
 
+CFLAGS		+= $(EXTRA_CFLAGS)
 CFLAGS		+= $(INCLUDES) $(LIB_INCLUDES)
 
 export CFLAGS OUTPUT srctree
Signature · 1 line
2.34.1
reviewer
#59 lore raw

Re: [PATCH v3 24/30] tools: tracing: Append extra cflags

Quoted 10 lines · Steven Rostedt
Quoted 4 lines · On Sun, 08 Mar 2026 16:46:29 +0000 Leo Yan <[email protected]> wrote:

Append EXTRA_CFLAGS to CFLAGS so that additional flags can be applied to the compiler.

Not a problem with the change but running this patch through an AI agent brought up:

Should CFLAGS be initialized with default optimization and warning flags (e.g., -g -O2 -Wall)?

Currently, latency-collector is built without these standard compilation flags because they are missing from the Makefile. In other commits in this series (like for libbpf and thermal), CFLAGS was explicitly initialized to
-g -O2 or -g -Wall when EXTRA_CFLAGS is not set.

Additionally, should EXTRA_WARNINGS (provided by tools/scripts/Makefile.include) be appended to CFLAGS here, similar to how it is done for other tools?

Thanks,
Ian

author
#60 lore raw

Re: [PATCH v3 24/30] tools: tracing: Append extra cflags

Quoted 18 lines · Ian Rogers
Quoted 10 lines · Steven Rostedt
Quoted 4 lines · On Sun, 08 Mar 2026 16:46:29 +0000 Leo Yan <[email protected]> wrote:

Append EXTRA_CFLAGS to CFLAGS so that additional flags can be applied to the compiler.

Not a problem with the change but running this patch through an AI agent brought up:

Should CFLAGS be initialized with default optimization and warning flags (e.g., -g -O2 -Wall)?

Quoted 8 lines

Currently, latency-collector is built without these standard compilation flags because they are missing from the Makefile. In other commits in this series (like for libbpf and thermal), CFLAGS was explicitly initialized to
-g -O2 or -g -Wall when EXTRA_CFLAGS is not set.

Additionally, should EXTRA_WARNINGS (provided by tools/scripts/Makefile.include) be appended to CFLAGS here, similar to how it is done for other tools?

Thanks for sharing this, Ian.

I would like to keep the scope of this series focused on appending the -fzero-init-padding-bits=all option. The comment above from AI is not relevant to this purpose, I'd leave it to the project maintainer for further refactoring.

As you suggested in other reples, I will update to append EXTRA_CFLAGS at the last so that it can override the default values. I will also collect Steven's ACK tag.

If there are any concerns, please let me know.

Leo

author
#61 lore raw

PATCH v3 25/30 tools: usb: Append extra cflags

In reply to Leo Yan

Append 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
index c6235667dd46223b646bbab5c82c810221750182..db2ff5b8e5ab7b76e424df32ed5a9458daa5d516 100644
@@ -13,6 +13,7 @@ endif
 # (this improves performance and avoids hard-to-debug behaviour);
 MAKEFLAGS += -r
 
+override CFLAGS += $(EXTRA_CFLAGS)
 override CFLAGS += -O2 -Wall -Wextra -g -D_GNU_SOURCE -I$(OUTPUT)include -I$(srctree)/tools/include
 override LDFLAGS += -lpthread
 
Signature · 1 line
2.34.1
reviewer
#62 lore raw

Re: [PATCH v3 25/30] tools: usb: Append extra cflags

Quoted 14 lines · Leo Yan

Append 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 +0 -0
index c6235667dd46223b646bbab5c82c810221750182..db2ff5b8e5ab7b76e424df32ed5a9458daa5d516 100644

tools/usb/Makefile endif · line 17

Quoted 5 lines
tools/usb/Makefile +1 -0
@@ -13,6 +13,7 @@ endif
 # (this improves performance and avoids hard-to-debug behaviour);
 MAKEFLAGS += -r
 
+override CFLAGS += $(EXTRA_CFLAGS)
 override CFLAGS += -O2 -Wall -Wextra -g -D_GNU_SOURCE -I$(OUTPUT)include -I$(srctree)/tools/include

The append should probably happen last to allow the default values to be overridden.

Thanks,
Ian

Quoted 6 lines
tools/usb/Makefile +0 -1
 override LDFLAGS += -lpthread
 
 
--

2.34.1

author
#63 lore raw

PATCH v3 26/30 tools: verification: Append extra cflags

In reply to Leo Yan

Append EXTRA_CFLAGS to CFLAGS so that additional flags can be applied to the compiler.

---
 tools/verification/rv/Makefile | 1 +
 1 file changed, 1 insertion(+)
tools/verification/rv/Makefile +1 -0
index 5b898360ba4818b12e8a16c27bd88c75d0076fb9..2882f0e93dca03b31d790b42d2ee3d8f73cc5c8b 100644
@@ -55,6 +55,7 @@ ifeq ($(config),1)
   include Makefile.config
 endif
 
+CFLAGS		+= $(EXTRA_CFLAGS)
 CFLAGS		+= $(INCLUDES) $(LIB_INCLUDES)
 
 export CFLAGS OUTPUT srctree
Signature · 1 line
2.34.1
maintainer
#64 lore raw

Re: [PATCH v3 26/30] tools: verification: Append extra cflags

Quoted 4 lines · Leo Yan

Append EXTRA_CFLAGS to CFLAGS so that additional flags can be applied to the compiler.

Thanks, for the patch, however I don't think this is necessary for RV as EXTRA_CFLAGS are already appended to CFLAGS elsewhere [1].

Makefile.rv is included after the various Makefile.include, so I presume that's good to go for the new flags you're appending in this series.
I did a quick check and I see -fzero-init-padding-bits=all by just adding 05/30 of this series.

[1] -
https://elixir.bootlin.com/linux/v6.19.3/source/tools/verification/rv/Makefile.rv#L29

Quoted 18 lines

---
 tools/verification/rv/Makefile | 1 +

 1 file changed, 1 insertion(+)
tools/verification/rv/Makefile +0 -0

index 5b898360ba4818b12e8a16c27bd88c75d0076fb9..2882f0e93dca03b31d790b42d2ee3d8f73cc 5c8b 100644

tools/verification/rv/Makefile +0 -0
@@ -55,6 +55,7 @@ ifeq ($(config),1)

   include Makefile.config
 endif

+CFLAGS += $(EXTRA_CFLAGS)
 CFLAGS += $(INCLUDES) $(LIB_INCLUDES)

 export CFLAGS OUTPUT srctree

author
#65 lore raw

Re: [PATCH v3 26/30] tools: verification: Append extra cflags

Quoted 9 lines · Gabriele Monaco
Quoted 4 lines · Leo Yan

Append EXTRA_CFLAGS to CFLAGS so that additional flags can be applied to the compiler.

Thanks, for the patch, however I don't think this is necessary for RV as EXTRA_CFLAGS are already appended to CFLAGS elsewhere [1].

Quoted 7 lines

Makefile.rv is included after the various Makefile.include, so I presume that's good to go for the new flags you're appending in this series.
I did a quick check and I see -fzero-init-padding-bits=all by just adding 05/30 of this series.

[1] -
https://elixir.bootlin.com/linux/v6.19.3/source/tools/verification/rv/Makefile.rv#L29

Thanks! I will drop this one in next spin.

author
#66 lore raw

PATCH v3 27/30 selftests/bpf: Append extra cflags

In reply to Leo Yan

Append EXTRA_CFLAGS to CFLAGS so that additional flags can be applied to the compiler.

---
 tools/testing/selftests/bpf/Makefile | 1 +
 1 file changed, 1 insertion(+)
tools/testing/selftests/bpf/Makefile +1 -0
index 72a9ba41f95ebb825d25799c07ba3f0311243e45..29dfcdbe98c781b53f1e87dcebecf2027bafcd5d 100644
@@ -49,6 +49,7 @@ srctree := $(patsubst %/,%,$(dir $(srctree)))
 srctree := $(patsubst %/,%,$(dir $(srctree)))
 endif
 
+CFLAGS += $(EXTRA_CFLAGS)
 CFLAGS += -g $(OPT_FLAGS) -rdynamic -std=gnu11				\
 	  -Wall -Werror -fno-omit-frame-pointer				\
 	  -Wno-unused-but-set-variable					\
Signature · 1 line
2.34.1
reviewer
#67 lore raw

Re: [PATCH v3 27/30] selftests/bpf: Append extra cflags

Quoted 14 lines · Leo Yan

Append EXTRA_CFLAGS to CFLAGS so that additional flags can be applied to the compiler.

---
 tools/testing/selftests/bpf/Makefile | 1 +
 1 file changed, 1 insertion(+)
tools/testing/selftests/bpf/Makefile +0 -0
index 72a9ba41f95ebb825d25799c07ba3f0311243e45..29dfcdbe98c781b53f1e87dcebecf2027bafcd5d 100644

tools/testing/selftests/bpf/Makefile srctree := $(patsubst %/,%,$(dir $(srctree))) · line 55

Quoted 7 lines
tools/testing/selftests/bpf/Makefile +1 -0
@@ -49,6 +49,7 @@ srctree := $(patsubst %/,%,$(dir $(srctree)))
 srctree := $(patsubst %/,%,$(dir $(srctree)))
 endif
 
+CFLAGS += $(EXTRA_CFLAGS)
 CFLAGS += -g $(OPT_FLAGS) -rdynamic -std=gnu11                         \
          -Wall -Werror -fno-omit-frame-pointer                         \
          -Wno-unused-but-set-variable                                  \

The append should probably happen last to allow the default values to be overridden.

Thanks,
Ian

Quoted 3 lines

--
2.34.1

author
#68 lore raw

Re: [PATCH v3 27/30] selftests/bpf: Append extra cflags

In reply to Leo Yan
Quoted 4 lines · Leo Yan

Append EXTRA_CFLAGS to CFLAGS so that additional flags can be applied to the compiler.

FWIW, this patch causes bpf selftest build failure and was reported in:

https://github.com/kernel-patches/bpf/actions/runs/22825654003

The Makefile reuses CFLAGS for clang to build urandom_read, which may cause GCC specific flags to feed to clang and causes errors.

The updated patch will introduce a new variable URANDOM_READ_CFLAGS, without appending EXTRA_CFLAGS, this can effectively avoid incompatible options.

Thanks,
Leo

Quoted 20 lines
---
 tools/testing/selftests/bpf/Makefile | 1 +
 1 file changed, 1 insertion(+)
tools/testing/selftests/bpf/Makefile +1 -0
index 72a9ba41f95ebb825d25799c07ba3f0311243e45..29dfcdbe98c781b53f1e87dcebecf2027bafcd5d 100644
@@ -49,6 +49,7 @@ srctree := $(patsubst %/,%,$(dir $(srctree)))
 srctree := $(patsubst %/,%,$(dir $(srctree)))
 endif
 
+CFLAGS += $(EXTRA_CFLAGS)
 CFLAGS += -g $(OPT_FLAGS) -rdynamic -std=gnu11				\
 	  -Wall -Werror -fno-omit-frame-pointer				\
 	  -Wno-unused-but-set-variable					\
Signature · 2 lines
-- 
2.34.1
author
#69 lore raw

PATCH v3 28/30 selftests/hid: Append extra cflags

In reply to Leo Yan

Append 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
index 50ec9e0406abaf316fba232c5da1967e27d0fa9b..d0dfa411af9b56ea3458184b8a81ef61bd44b1fe 100644
@@ -24,6 +24,7 @@ CXX ?= $(CROSS_COMPILE)g++
 
 HOSTPKG_CONFIG := pkg-config
 
+CFLAGS += $(EXTRA_CFLAGS)
 CFLAGS += -g -O0 -rdynamic -Wall -Werror -I$(OUTPUT)
 CFLAGS += -I$(OUTPUT)/tools/include
 
Signature · 1 line
2.34.1
reviewer
#70 lore raw

Re: [PATCH v3 28/30] selftests/hid: Append extra cflags

Quoted 14 lines · Leo Yan

Append 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 +0 -0
index 50ec9e0406abaf316fba232c5da1967e27d0fa9b..d0dfa411af9b56ea3458184b8a81ef61bd44b1fe 100644

tools/testing/selftests/hid/Makefile CXX ?= $(CROSS_COMPILE)g++ · line 29

Quoted 6 lines
tools/testing/selftests/hid/Makefile +1 -0
@@ -24,6 +24,7 @@ CXX ?= $(CROSS_COMPILE)g++
 
 HOSTPKG_CONFIG := pkg-config
 
+CFLAGS += $(EXTRA_CFLAGS)
 CFLAGS += -g -O0 -rdynamic -Wall -Werror -I$(OUTPUT)
 CFLAGS += -I$(OUTPUT)/tools/include

The append should probably happen last to allow the default values to be overridden.

Thanks,
Ian

Quoted 4 lines
tools/testing/selftests/hid/Makefile +0 -1
--

2.34.1

author
#71 lore raw

PATCH v3 29/30 selftests/nolibc: Append extra cflags

In reply to Leo Yan

Append EXTRA_CFLAGS to CFLAGS so that additional flags can be applied to the compiler.

---
 tools/testing/selftests/nolibc/Makefile.nolibc | 3 +++
 1 file changed, 3 insertions(+)
tools/testing/selftests/nolibc/Makefile.nolibc +3 -0
index f5704193038f7da935d57e0f894970b6e29b78da..e58b2f5eb2b231bb1c194db7365fff7b4e244e5d 100644
@@ -252,6 +252,9 @@ endif
 # Modify CFLAGS based on LLVM=
 include $(srctree)/tools/scripts/Makefile.include
 
+# Append EXTRA_CFLAGS if it is set in tools/scripts/Makefile.include
+CFLAGS  += $(EXTRA_CFLAGS)
+
 REPORT  ?= awk '/\[OK\][\r]*$$/{p++} /\[FAIL\][\r]*$$/{if (!f) printf("\n"); f++; print;} /\[SKIPPED\][\r]*$$/{s++} \
 		/^Total number of errors:/{done++} \
 		END{ printf("\n%3d test(s): %3d passed, %3d skipped, %3d failed => status: ", p+s+f, p, s, f); \
Signature · 1 line
2.34.1
#72 lore raw

Re: [PATCH v3 29/30] selftests/nolibc: Append extra cflags

Hi Leo,

Quoted 13 lines · Leo Yan

Append EXTRA_CFLAGS to CFLAGS so that additional flags can be applied to the compiler.

---
 tools/testing/selftests/nolibc/Makefile.nolibc | 3 +++
 1 file changed, 3 insertions(+)
tools/testing/selftests/nolibc/Makefile.nolibc +0 -0
index f5704193038f7da935d57e0f894970b6e29b78da..e58b2f5eb2b231bb1c194db7365fff7b4e244e5d 100644

tools/testing/selftests/nolibc/Makefile.nolibc endif · line 256

Quoted 5 lines
tools/testing/selftests/nolibc/Makefile.nolibc +2 -0
@@ -252,6 +252,9 @@ endif
 # Modify CFLAGS based on LLVM=
 include $(srctree)/tools/scripts/Makefile.include
 
+# Append EXTRA_CFLAGS if it is set in tools/scripts/Makefile.include
+CFLAGS  += $(EXTRA_CFLAGS)

Makefile.nolibc here is completely self-contained. It is not expected to inherit any flags from the regular selftests. So I don't think this makes sense. There is a similar, custom "CFLAGS_EXTRA" variable, which could be aligned, but probably not as part of this series.

There is a regular 'Makefile' in this directory which *is* integrated with the regular selftest build system. If you could make sure that it works correctly with what you are doing, that would be great.

Thomas

Quoted 8 lines
tools/testing/selftests/nolibc/Makefile.nolibc +1 -0
+
 REPORT  ?= awk '/\[OK\][\r]*$$/{p++} /\[FAIL\][\r]*$$/{if (!f) printf("\n"); f++; print;} /\[SKIPPED\][\r]*$$/{s++} \
 		/^Total number of errors:/{done++} \
 		END{ printf("\n%3d test(s): %3d passed, %3d skipped, %3d failed => status: ", p+s+f, p, s, f); \
Signature · 2 lines
-- 
2.34.1
author
#73 lore raw

Re: [PATCH v3 29/30] selftests/nolibc: Append extra cflags

Quoted 27 lines · Thomas Weißschuh

Hi Leo,

Quoted 13 lines · Leo Yan

Append EXTRA_CFLAGS to CFLAGS so that additional flags can be applied to the compiler.

---
 tools/testing/selftests/nolibc/Makefile.nolibc | 3 +++
 1 file changed, 3 insertions(+)
tools/testing/selftests/nolibc/Makefile.nolibc +0 -0
index f5704193038f7da935d57e0f894970b6e29b78da..e58b2f5eb2b231bb1c194db7365fff7b4e244e5d 100644

tools/testing/selftests/nolibc/Makefile.nolibc endif · line 256

Quoted 5 lines
tools/testing/selftests/nolibc/Makefile.nolibc +2 -0
@@ -252,6 +252,9 @@ endif
 # Modify CFLAGS based on LLVM=
 include $(srctree)/tools/scripts/Makefile.include
 
+# Append EXTRA_CFLAGS if it is set in tools/scripts/Makefile.include
+CFLAGS  += $(EXTRA_CFLAGS)

Makefile.nolibc here is completely self-contained. It is not expected to inherit any flags from the regular selftests. So I don't think this makes sense. There is a similar, custom "CFLAGS_EXTRA" variable, which could be aligned, but probably not as part of this series.

Quoted 3 lines

There is a regular 'Makefile' in this directory which *is* integrated with the regular selftest build system. If you could make sure that it works correctly with what you are doing, that would be great.

Sure, I will update the regular Makefile.

As you suggested, I also will drop patch 18 in new version.

Thanks for suggestions!

author
#74 lore raw

PATCH v3 30/30 selftests/sched_ext: Append extra cflags

In reply to Leo Yan

Append 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
index 006300ac6dff88a48104977398d8517753e7e385..81d8f4a184245d8c330cf45b75bd868b2a7aa7dc 100644
@@ -53,6 +53,7 @@ ifneq ($(wildcard $(GENHDR)),)
   GENFLAGS := -DHAVE_GENHDR
 endif
 
+CFLAGS += $(EXTRA_CFLAGS)
 CFLAGS += -g -O2 -rdynamic -pthread -Wall -Werror $(GENFLAGS)			\
 	  -I$(INCLUDE_DIR) -I$(GENDIR) -I$(LIBDIR)				\
 	  -I$(TOOLSINCDIR) -I$(APIDIR) -I$(CURDIR)/include -I$(SCXTOOLSINCDIR)
Signature · 1 line
2.34.1
reviewer Acked-by on v3 30/30
#75 lore raw

Re: [PATCH v3 30/30] selftests/sched_ext: Append extra cflags

Quoted 4 lines · Leo Yan

Append EXTRA_CFLAGS to CFLAGS so that additional flags can be applied to the compiler.

Thanks,
-Andrea

Quoted 20 lines
---
 tools/testing/selftests/sched_ext/Makefile | 1 +
 1 file changed, 1 insertion(+)
tools/testing/selftests/sched_ext/Makefile +1 -0
index 006300ac6dff88a48104977398d8517753e7e385..81d8f4a184245d8c330cf45b75bd868b2a7aa7dc 100644
@@ -53,6 +53,7 @@ ifneq ($(wildcard $(GENHDR)),)
   GENFLAGS := -DHAVE_GENHDR
 endif
 
+CFLAGS += $(EXTRA_CFLAGS)
 CFLAGS += -g -O2 -rdynamic -pthread -Wall -Werror $(GENFLAGS)			\
 	  -I$(INCLUDE_DIR) -I$(GENDIR) -I$(LIBDIR)				\
 	  -I$(TOOLSINCDIR) -I$(APIDIR) -I$(CURDIR)/include -I$(SCXTOOLSINCDIR)
Signature · 2 lines
-- 
2.34.1
reviewer
#76 lore raw

Re: [PATCH v3 30/30] selftests/sched_ext: Append extra cflags

In reply to Leo Yan
Quoted 14 lines · Leo Yan

Append 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 +0 -0
index 006300ac6dff88a48104977398d8517753e7e385..81d8f4a184245d8c330cf45b75bd868b2a7aa7dc 100644

tools/testing/selftests/sched_ext/Makefile ifneq ($(wildcard $(GENHDR)),) · line 59

Quoted 7 lines
tools/testing/selftests/sched_ext/Makefile +1 -0
@@ -53,6 +53,7 @@ ifneq ($(wildcard $(GENHDR)),)
   GENFLAGS := -DHAVE_GENHDR
 endif
 
+CFLAGS += $(EXTRA_CFLAGS)
 CFLAGS += -g -O2 -rdynamic -pthread -Wall -Werror $(GENFLAGS)                  \
          -I$(INCLUDE_DIR) -I$(GENDIR) -I$(LIBDIR)                              \
          -I$(TOOLSINCDIR) -I$(APIDIR) -I$(CURDIR)/include -I$(SCXTOOLSINCDIR)

The append should probably happen last to allow the default values to be overridden.

Thanks,
Ian

Quoted 3 lines

--
2.34.1