tools build: Append -fzero-init-padding-bits=all option
Subsystems (23)
v4 cover tools build: Append -fzero-init-padding-bits=all option
Thank you for reviewing v3 and I appreciate much Ian's suggestions, most of which have been adopted into this series.
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 changes are organized into three parts:
Patches 01 – 07: Preparation before adding the new compiler option.
Fix typos, adjust Makefiles to ensure the newly introduced option does not cause regressions.
Patch 08: Propagate -fzero-init-padding-bits=all to
EXTRA_CFLAGS and HOST_EXTRACFLAGS for the CC and HOSTCC compilers, respectively.
Patches 09 – 30: 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 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]
Changes in v3:
- Extended to support cross compilation (Quentin).
- Link to v2: https://lore.kernel.org/r/[email protected]
---
Leo Yan (30):
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
libbpf: Remove duplicate $(CLANG_CROSS_FLAGS)
libbpf: 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: 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/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/counter/Makefile | 1 + tools/dma/Makefile | 1 + tools/gpio/Makefile | 1 + tools/hv/Makefile | 1 + tools/iio/Makefile | 1 + tools/lib/bpf/Makefile | 17 ++++++++-------- 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/bpf/Makefile | 10 ++++++++-- tools/testing/selftests/hid/Makefile | 1 + tools/testing/selftests/nolibc/Makefile | 6 ++---- tools/testing/selftests/sched_ext/Makefile | 1 + tools/thermal/lib/Makefile | 20 ++++++++++--------- tools/tracing/latency/Makefile | 1 + tools/usb/Makefile | 1 + 26 files changed, 101 insertions(+), 37 deletions(-)
---
base-commit: 4ae12d8bd9a830799db335ee661d6cbc6597f838
change-id: 20260224-tools_build_fix_zero_init-dc5261bd8b8b
Best regards,
Signature · 1 line
Leo Yan <[email protected]>
PATCH v4 1/30 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
Re: [PATCH v4 01/30] tools: lib: thermal: Fix typo
Quoted 5 lines · Leo Yan
s/CFGLAS/CFLAGS
Fixes 47c4b0de080a ("tools/lib/thermal: Add a thermal library")Signed-off-by Leo Yan <[email protected]>---
Thanks !
PATCH v4 2/30 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
Re: [PATCH v4 02/30] tools/thermal: Fix typo
Quoted 5 lines · Leo Yan
s/CFGLAS/CFLAGS
Fixes 3b7c5e8adf9c ("tools/thermal: Add util library")Signed-off-by Leo Yan <[email protected]>---
Thanks !
PATCH v4 3/30 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
Re: [PATCH v4 03/30] tools: lib: thermal: Initialize CFLAGS before including Makefile.include
Quoted 9 lines · Leo Yan
tools/scripts/Makefile.includemay expandEXTRA_CFLAGSin a future change. This could alter the initialization of CFLAGS in the thermalMakefile, as the default options "-g -Wall" would never be set onceEXTRA_CFLAGSis expanded.Prepare for this by moving the CFLAGS initialization before including
tools/scripts/Makefile.include, so it is not affected by the extendedEXTRA_CFLAGS.
Quoted 6 lines
Append
EXTRA_CFLAGSto CFLAGS only after including Makefile.include and place it last so that the extra flags propagate properly and can override the default options.Signed-off-by Leo Yan <[email protected]>---
Thanks !
PATCH v4 4/30 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 v4 5/30 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
Ian Rogers
reviewerRe: [PATCH v4 05/30] bpftool: Avoid adding EXTRA_CFLAGS to HOST_CFLAGS
Quoted 31 lines · Leo Yan
Prepare for future changes where
EXTRA_CFLAGSmay include flags not applicable to the host compiler.Move the
HOST_CFLAGSassignment before appendingEXTRA_CFLAGSto CFLAGS so thatHOST_CFLAGSdoes not inherit flags fromEXTRA_CFLAGS.Acked-by Quentin Monnet <[email protected]>Signed-off-by Leo Yan <[email protected]>--- tools/bpf/bpftool/Makefile | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)tools/bpf/bpftool/Makefile +6
-0@@ -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)
Should HOST_LDFLAGS be similarly moved? Otherwise, it seems target flags in EXTRA_LDFLAGS will be added for the host.
Thanks,
Ian
Quoted 5 lines
tools/bpf/bpftool/Makefile +0
-1INSTALL ?= install --2.34.1
Re: [PATCH v4 05/30] bpftool: Avoid adding EXTRA_CFLAGS to HOST_CFLAGS
Quoted 35 lines · Ian Rogers
Quoted 34 lines · Leo Yan
Prepare for future changes where
EXTRA_CFLAGSmay include flags not applicable to the host compiler.Move the
HOST_CFLAGSassignment before appendingEXTRA_CFLAGSto CFLAGS so thatHOST_CFLAGSdoes not inherit flags fromEXTRA_CFLAGS.Acked-by Quentin Monnet <[email protected]>Signed-off-by Leo Yan <[email protected]>--- tools/bpf/bpftool/Makefile | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)tools/bpf/bpftool/Makefile +6
-0@@ -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 6 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)Should
HOST_LDFLAGSbe similarly moved? Otherwise, it seems target flags inEXTRA_LDFLAGSwill be added for the host.
Though this series is irrelevant to LDFLAGS, I am fine to move HOST_LDFLAGS together.
Quentin, how about you think?
Quentin Monnet
maintainerRe: [PATCH v4 05/30] bpftool: Avoid adding EXTRA_CFLAGS to HOST_CFLAGS
2026-03-13 15:56 UTC+0000 ~ Leo Yan <[email protected]>
Quoted 43 lines · Ian Rogers
Quoted 35 lines · Leo Yan
Quoted 34 lines
Prepare for future changes where
EXTRA_CFLAGSmay include flags not applicable to the host compiler.Move the
HOST_CFLAGSassignment before appendingEXTRA_CFLAGSto CFLAGS so thatHOST_CFLAGSdoes not inherit flags fromEXTRA_CFLAGS.Acked-by Quentin Monnet <[email protected]>Signed-off-by Leo Yan <[email protected]>--- tools/bpf/bpftool/Makefile | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)tools/bpf/bpftool/Makefile +6
-0@@ -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) endifQuoted 6 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)Should
HOST_LDFLAGSbe similarly moved? Otherwise, it seems target flags inEXTRA_LDFLAGSwill be added for the host.
Quoted 2 lines
Though this series is irrelevant to LDFLAGS, I am fine to move
HOST_LDFLAGStogether.
If we move the HOST_LDFLAGS earlier so that they no longer receive the EXTRA_LDFLAGS, then we lose the possibility to use any EXTRA variable to pass additional flags to HOST_LDFLAGS. So OK to move, but maybe add a "HOST_LDFLAGS += $(HOST_EXTRALDFLAGS)" to it for consistency with the processing of HOST_CFLAGS?
Quentin
Re: [PATCH v4 05/30] bpftool: Avoid adding EXTRA_CFLAGS to HOST_CFLAGS
On Fri, Mar 13, 2026 at 04:07:27PM +0000, Quentin Monnet wrote:
[...]
Quoted 24 lines
Quoted 20 lines
Quoted 13 lines
Quoted 13 lines
tools/bpf/bpftool/Makefile +6
-0+ +# 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) endifQuoted 6 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)Should
HOST_LDFLAGSbe similarly moved? Otherwise, it seems target flags inEXTRA_LDFLAGSwill be added for the host.Quoted 2 lines
Though this series is irrelevant to LDFLAGS, I am fine to move
HOST_LDFLAGStogether.
Quoted 5 lines
If we move the
HOST_LDFLAGSearlier so that they no longer receive theEXTRA_LDFLAGS, then we lose the possibility to use any EXTRA variable to pass additional flags toHOST_LDFLAGS. So OK to move, but maybe add a "HOST_LDFLAGS+= $(HOST_EXTRALDFLAGS)" to it for consistency with the processing ofHOST_CFLAGS?
Adding HOST_EXTRALDFLAGS seems a bit over designed to me, as there is no use case for it currently. To avoid complexity, let's keep this patch as it is, we can add HOST_EXTRALDFLAGS if later have requirement.
P.s. I saw that you already replied the same comment in the previous version. I should have confirmed at that time, sorry for the duplicate discussion.
Quentin Monnet
maintainerRe: [PATCH v4 05/30] bpftool: Avoid adding EXTRA_CFLAGS to HOST_CFLAGS
2026-03-13 16:24 UTC+0000 ~ Leo Yan <[email protected]>
Quoted 34 lines · Quentin Monnet
[...]
Quoted 24 lines
Quoted 20 lines
Quoted 13 lines
Quoted 13 lines
tools/bpf/bpftool/Makefile +6
-0+ +# 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) endifQuoted 6 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)Should
HOST_LDFLAGSbe similarly moved? Otherwise, it seems target flags inEXTRA_LDFLAGSwill be added for the host.Quoted 2 lines
Though this series is irrelevant to LDFLAGS, I am fine to move
HOST_LDFLAGStogether.Quoted 5 lines
If we move the
HOST_LDFLAGSearlier so that they no longer receive theEXTRA_LDFLAGS, then we lose the possibility to use any EXTRA variable to pass additional flags toHOST_LDFLAGS. So OK to move, but maybe add a "HOST_LDFLAGS+= $(HOST_EXTRALDFLAGS)" to it for consistency with the processing ofHOST_CFLAGS?
Quoted 7 lines
Adding
HOST_EXTRALDFLAGSseems a bit over designed to me, as there is no use case for it currently. To avoid complexity, let's keep this patch as it is, we can addHOST_EXTRALDFLAGSif later have requirement.P.s. I saw that you already replied the same comment in the previous version. I should have confirmed at that time, sorry for the duplicate discussion.
That's fine :) - And agreed, it's probably best to leave it as-is for now. Thanks!
Quentin
PATCH v4 6/30 libbpf: Remove duplicate $(CLANG_CROSS_FLAGS)
In reply to Leo Yantools/scripts/Makefile.include already appends $(CLANG_CROSS_FLAGS) to CFLAGS:
CFLAGS += $(CLANG_CROSS_FLAGS)
Since Makefile.include is included, the libbpf Makefile appends $(CLANG_CROSS_FLAGS) again, resulting in duplicate flags.
Remove the redundant append.
--- tools/lib/bpf/Makefile | 1 - 1 file changed, 1 deletion(-)
tools/lib/bpf/Makefile +0 -1
@@ -84,7 +84,6 @@ override CFLAGS += -Werror -Wall override CFLAGS += $(INCLUDES) override CFLAGS += -fvisibility=hidden override CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -override CFLAGS += $(CLANG_CROSS_FLAGS) # flags specific for shared library SHLIB_FLAGS := -DSHARED -fPIC
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH v4 06/30] libbpf: Remove duplicate $(CLANG_CROSS_FLAGS)
At this commit, doesn't this removal lose CLANG_CROSS_FLAGS entirely from the libbpf build?
tools/lib/bpf/Makefile override CFLAGS += -Werror -Wall · line 87
Quoted 9 lines
tools/lib/bpf/Makefile +0
-1@@ -84,7 +84,6 @@ override CFLAGS += -Werror -Wall override CFLAGS += $(INCLUDES) override CFLAGS += -fvisibility=hidden override CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -override CFLAGS += $(CLANG_CROSS_FLAGS)
At this commit, doesn't this removal lose CLANG_CROSS_FLAGS entirely from the libbpf build?
The libbpf Makefile includes Makefile.include at the top, which does append CLANG_CROSS_FLAGS to CFLAGS. But then the libbpf Makefile overwrites CFLAGS with :=
CFLAGS := -g -O2
which destroys everything Makefile.include appended. The removed line above was the only thing that re-added the cross-compile flags after that overwrite.
The next commit in the series (233d70853154 "libbpf: Initialize CFLAGS before including Makefile.include") fixes this by moving the CFLAGS initialization before the include, so Makefile.include's addition survives. But at this commit, cross-compilation with Clang appears broken.
Could these two patches be squashed or reordered so that the initialization move comes first?
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/22943905432
Re: [PATCH v4 06/30] libbpf: Remove duplicate $(CLANG_CROSS_FLAGS)
Quoted 23 lines · On Wed, Mar 11, 2026 at 09:02:13AM +0000, [email protected] wrote:
tools/lib/bpf/Makefile override CFLAGS += -Werror -Wall · line 87
Quoted 9 lines
tools/lib/bpf/Makefile +0
-1@@ -84,7 +84,6 @@ override CFLAGS += -Werror -Wall override CFLAGS += $(INCLUDES) override CFLAGS += -fvisibility=hidden override CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -override CFLAGS += $(CLANG_CROSS_FLAGS)At this commit, doesn't this removal lose
CLANG_CROSS_FLAGSentirely from the libbpf build?The libbpf
Makefileincludes Makefile.include at the top, which does appendCLANG_CROSS_FLAGSto CFLAGS. But then the libbpfMakefileoverwrites CFLAGS with :=CFLAGS := -g -O2which destroys everything Makefile.include appended. The removed line above was the only thing that re-added the cross-compile flags after that overwrite.
Quoted 8 lines
The next commit in the series (
233d70853154"libbpf: Initialize CFLAGS before including Makefile.include") fixes this by moving the CFLAGS initialization before the include, so Makefile.include's addition survives. But at this commit, cross-compilation with Clang appears broken.Could these two patches be squashed or reordered so that the initialization move comes first?
To be honest, I feel much more comfortable being corrected by a human rather than a bot :)
The comment is fair enough, I will squash the two patches.
Thanks,
Leo
PATCH v4 7/30 libbpf: 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, as the default options "-g -O2" 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/bpf/Makefile | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
tools/lib/bpf/Makefile +9 -7
@@ -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,13 +78,6 @@ 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 += -std=gnu89 override CFLAGS += $(EXTRA_WARNINGS) -Wno-switch-enum
@@ -84,6 +85,7 @@ override CFLAGS += -Werror -Wall override CFLAGS += $(INCLUDES) override CFLAGS += -fvisibility=hidden override CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 +override CFLAGS += $(EXTRA_CFLAGS) # flags specific for shared library SHLIB_FLAGS := -DSHARED -fPIC
Signature · 1 line
2.34.1
Re: [PATCH v4 07/30] libbpf: Initialize CFLAGS before including Makefile.include
Hi BPF maintainers,
Quoted 8 lines · Leo Yan
tools/scripts/Makefile.includemay expandEXTRA_CFLAGSin a future change. This could alter the initialization of CFLAGS, as the default options "-g -O2" would never be set onceEXTRA_CFLAGSis expanded.Prepare for this by moving the CFLAGS initialization before including
tools/scripts/Makefile.include, so it is not affected by the extendedEXTRA_CFLAGS.
Quoted 5 lines
Append
EXTRA_CFLAGSto CFLAGS only after including Makefile.include and place it last so that the extra flags propagate properly and can override the default options.Signed-off-by Leo Yan <[email protected]>
Before sending a new version, I'd check if you have a chance to review the libbpf patches. The libbpf change is crucial for this series.
Another reason for pinging because I received a bpf-ci report about test failures for this series [1]. The failures looks to be unrelated, as the tests fail starting from the first patch, which is irrelevant to BPF code [2]. I tried reaching [email protected] last week but haven't received a response yet.
If bpf-ci testing is mandatory for libbpf patches, could you advise me on the correct workflow (e.g., whether the patches should be based on a specific branch)?
Thanks.
[1] https://github.com/kernel-patches/bpf/actions/runs/22944268645
[2] https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
Quoted 49 lines
--- tools/lib/bpf/Makefile | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)tools/lib/bpf/Makefile +9
-7@@ -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,13 +78,6 @@ 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 += -std=gnu89 override CFLAGS += $(EXTRA_WARNINGS) -Wno-switch-enum@@ -84,6 +85,7 @@ override CFLAGS += -Werror -Wall override CFLAGS += $(INCLUDES) override CFLAGS += -fvisibility=hidden override CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 +override CFLAGS += $(EXTRA_CFLAGS) # flags specific for shared library SHLIB_FLAGS := -DSHARED -fPICSignature · 2 lines
-- 2.34.1
Re: [PATCH v4 07/30] libbpf: Initialize CFLAGS before including Makefile.include
Quoted 27 lines · Leo Yan
Hi BPF maintainers,
Quoted 8 lines · Leo Yan
tools/scripts/Makefile.includemay expandEXTRA_CFLAGSin a future change. This could alter the initialization of CFLAGS, as the default options "-g -O2" would never be set onceEXTRA_CFLAGSis expanded.Prepare for this by moving the CFLAGS initialization before including
tools/scripts/Makefile.include, so it is not affected by the extendedEXTRA_CFLAGS.Quoted 5 lines
Append
EXTRA_CFLAGSto CFLAGS only after including Makefile.include and place it last so that the extra flags propagate properly and can override the default options.Signed-off-by Leo Yan <[email protected]>Before sending a new version, I'd check if you have a chance to review the libbpf patches. The libbpf change is crucial for this series.
Another reason for pinging because I received a bpf-ci report about test failures for this series [1]. The failures looks to be unrelated, as the tests fail starting from the first patch, which is irrelevant to BPF code [2]. I tried reaching [email protected] last week but haven't received a response yet.
Quoted 3 lines
If bpf-ci testing is mandatory for libbpf patches, could you advise me on the correct workflow (e.g., whether the patches should be based on a specific branch)?
yes. It is mandatory and libbpf patches must go through bpf-next tree, so pls send them separately.
PATCH v4 8/30 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
Re: [PATCH v4 08/30] tools build: Append -fzero-init-padding-bits=all to extra cflags
Quoted 22 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.
Quoted 4 lines
[1] https://gcc.gnu.org/gcc-15/changes.html
Acked-by Quentin Monnet <[email protected]>Signed-off-by Leo Yan <[email protected]>
Thanks,
Namhyung
Quoted 49 lines
--- 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 elseSignature · 2 lines
-- 2.34.1
PATCH v4 9/30 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 v4 10/30 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
Re: [PATCH v4 10/30] perf build: Append extra host flags
Quoted 4 lines · Leo Yan
Append
HOST_EXTRACFLAGStoHOST_CFLAGSso that additional flags can be applied to the host compiler.Signed-off-by Leo Yan <[email protected]>
Thanks,
Namhyung
Quoted 21 lines
--- 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 · 2 lines
-- 2.34.1
PATCH v4 11/30 tools/bpf: build: Append extra cflags
In reply to Leo YanAppend 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
@@ -11,6 +11,7 @@ INSTALL ?= install CFLAGS += -Wall -O2 CFLAGS += -D__EXPORTED_HEADERS__ -I$(srctree)/tools/include/uapi \ -I$(srctree)/tools/include +CFLAGS += $(EXTRA_CFLAGS) # This will work when bpf is built in tools env. where srctree # isn't set and when invoked from selftests build, where srctree
Signature · 1 line
2.34.1
PATCH v4 12/30 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 := $(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
Ian Rogers
reviewerRe: [PATCH v4 12/30] tools build: Append extra host cflags
Quoted 14 lines · Leo Yan
Append
HOST_EXTRACFLAGSto HOSTCFLAGS so that additional flags can be applied to the host compiler.Signed-off-by Leo Yan <[email protected]>--- tools/build/Makefile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)tools/build/Makefile +0
-0
tools/build/Makefile endif · line 43
Quoted 4 lines
tools/build/Makefile +1
-0@@ -40,14 +40,16 @@ endif FIXDEP := $(OUTPUT)fixdep FIXDEP_IN := $(OUTPUT)fixdep-in.o +HOSTCFLAGS := $(HOST_EXTRACFLAGS) $(KBUILD_HOSTCFLAGS)
Hi Leo, should HOST_EXTRACFLAGS appear after KBUILD_HOSTCFLAGS here? This allows the extra flags to override the build system's flags.
Thanks,
Ian
Quoted 19 lines
tools/build/Makefile +3
-3+ # 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) --2.34.1
PATCH v4 13/30 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 v4 14/30 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 v4 15/30 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 v4 16/30 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 v4 17/30 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 v4 18/30 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
Re: [PATCH v4 18/30] tools: iio: Append extra cflags
Quoted 4 lines · On Wed, 11 Mar 2026 08:29:43 +0000 Leo Yan <[email protected]> wrote:
Append
EXTRA_CFLAGSto CFLAGS so that additional flags can be applied to the compiler.Signed-off-by Leo Yan <[email protected]>
Given discussion leading to:
https://lore.kernel.org/all/[email protected]/
I'm assuming I don't need to do anything beyond.
Shout if otherwise.
Quoted 17 lines
--- 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))
PATCH v4 19/30 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 v4 20/30 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 v4 21/30 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 v4 22/30 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 v4 23/30 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 v4 24/30 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 v4 25/30 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 v4 26/30 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 v4 27/30 selftests/bpf: Append extra cflags
In reply to Leo YanAppend EXTRA_CFLAGS to CFLAGS so that additional flags can be applied to the compiler.
urandom_read is built with clang. Introduce URANDOM_READ_CFLAGS to copy the compiler flags without appending EXTRA_CFLAGS, which may contain incompatible options with clang.
--- tools/testing/selftests/bpf/Makefile | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/Makefile +8 -2
@@ -71,6 +71,12 @@ ifneq ($(LLVM),) CFLAGS += -Wno-unused-command-line-argument endif +# urandom_read is built with clang. Copy $(CFLAGS) before EXTRA_CFLAGS are +# appended so that it does not inherit potentially incompatible options. +URANDOM_READ_CFLAGS := $(CFLAGS) + +CFLAGS += $(EXTRA_CFLAGS) + # Check whether bpf cpu=v4 is supported or not by clang ifneq ($(shell $(CLANG) --target=bpf -mcpu=help 2>&1 | grep 'v4'),) CLANG_CPUV4 := 1
@@ -255,7 +261,7 @@ endif $(OUTPUT)/liburandom_read.so: urandom_read_lib1.c urandom_read_lib2.c liburandom_read.map $(call msg,LIB,,$@) $(Q)$(CLANG) $(CLANG_TARGET_ARCH) \ - $(filter-out -static,$(CFLAGS) $(LDFLAGS)) \ + $(filter-out -static,$(URANDOM_READ_CFLAGS) $(LDFLAGS)) \ $(filter %.c,$^) $(filter-out -static,$(LDLIBS)) \ -Wno-unused-command-line-argument \ -fuse-ld=$(LLD) -Wl,-znoseparate-code -Wl,--build-id=sha1 \
@@ -265,7 +271,7 @@ $(OUTPUT)/liburandom_read.so: urandom_read_lib1.c urandom_read_lib2.c liburandom $(OUTPUT)/urandom_read: urandom_read.c urandom_read_aux.c $(OUTPUT)/liburandom_read.so $(call msg,BINARY,,$@) $(Q)$(CLANG) $(CLANG_TARGET_ARCH) \ - $(filter-out -static,$(CFLAGS) $(LDFLAGS)) $(filter %.c,$^) \ + $(filter-out -static,$(URANDOM_READ_CFLAGS) $(LDFLAGS)) $(filter %.c,$^) \ -Wno-unused-command-line-argument \ -lurandom_read $(filter-out -static,$(LDLIBS)) -L$(OUTPUT) \ -fuse-ld=$(LLD) -Wl,-znoseparate-code -Wl,--build-id=sha1 \
Signature · 1 line
2.34.1
Ian Rogers
reviewerRe: [PATCH v4 27/30] selftests/bpf: Append extra cflags
Quoted 18 lines · Leo Yan
Append
EXTRA_CFLAGSto CFLAGS so that additional flags can be applied to the compiler.
urandom_readis built with clang. IntroduceURANDOM_READ_CFLAGSto copy the compiler flags without appendingEXTRA_CFLAGS, which may contain incompatible options with clang.Signed-off-by Leo Yan <[email protected]>--- tools/testing/selftests/bpf/Makefile | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)tools/testing/selftests/bpf/Makefile +0
-0
tools/testing/selftests/bpf/Makefile ifneq ($(LLVM),) · line 76
Quoted 6 lines
tools/testing/selftests/bpf/Makefile +3
-0@@ -71,6 +71,12 @@ ifneq ($(LLVM),) CFLAGS += -Wno-unused-command-line-argument endif +# urandom_read is built with clang. Copy $(CFLAGS) before EXTRA_CFLAGS are +# appended so that it does not inherit potentially incompatible options. +URANDOM_READ_CFLAGS := $(CFLAGS)
Later in the Makefile, include ../lib.mk is executed and it appends CFLAGS like -D_GNU_SOURCE= which will be missing from URANDOM_READ_CFLAGS here. Perhaps move these assignments below the include?
Thanks,
Ian
Quoted 28 lines
tools/testing/selftests/bpf/Makefile +5
-3+ +CFLAGS += $(EXTRA_CFLAGS) + # Check whether bpf cpu=v4 is supported or not by clang ifneq ($(shell $(CLANG) --target=bpf -mcpu=help 2>&1 | grep 'v4'),) CLANG_CPUV4 := 1@@ -255,7 +261,7 @@ endif $(OUTPUT)/liburandom_read.so: urandom_read_lib1.c urandom_read_lib2.c liburandom_read.map $(call msg,LIB,,$@) $(Q)$(CLANG) $(CLANG_TARGET_ARCH) \ - $(filter-out -static,$(CFLAGS) $(LDFLAGS)) \ + $(filter-out -static,$(URANDOM_READ_CFLAGS) $(LDFLAGS)) \ $(filter %.c,$^) $(filter-out -static,$(LDLIBS)) \ -Wno-unused-command-line-argument \ -fuse-ld=$(LLD) -Wl,-znoseparate-code -Wl,--build-id=sha1 \@@ -265,7 +271,7 @@ $(OUTPUT)/liburandom_read.so: urandom_read_lib1.c urandom_read_lib2.c liburandom $(OUTPUT)/urandom_read: urandom_read.c urandom_read_aux.c $(OUTPUT)/liburandom_read.so $(call msg,BINARY,,$@) $(Q)$(CLANG) $(CLANG_TARGET_ARCH) \ - $(filter-out -static,$(CFLAGS) $(LDFLAGS)) $(filter %.c,$^) \ + $(filter-out -static,$(URANDOM_READ_CFLAGS) $(LDFLAGS)) $(filter %.c,$^) \ -Wno-unused-command-line-argument \ -lurandom_read $(filter-out -static,$(LDLIBS)) -L$(OUTPUT) \ -fuse-ld=$(LLD) -Wl,-znoseparate-code -Wl,--build-id=sha1 \ --2.34.1
Re: [PATCH v4 27/30] selftests/bpf: Append extra cflags
Quoted 22 lines · Ian Rogers
Quoted 21 lines · Leo Yan
Append
EXTRA_CFLAGSto CFLAGS so that additional flags can be applied to the compiler.
urandom_readis built with clang. IntroduceURANDOM_READ_CFLAGSto copy the compiler flags without appendingEXTRA_CFLAGS, which may contain incompatible options with clang.Signed-off-by Leo Yan <[email protected]>--- tools/testing/selftests/bpf/Makefile | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)tools/testing/selftests/bpf/Makefile +0
-0@@ -71,6 +71,12 @@ ifneq ($(LLVM),) CFLAGS += -Wno-unused-command-line-argument endif
Quoted 8 lines
tools/testing/selftests/bpf/Makefile ifneq ($(LLVM),) · line 76
Quoted 3 lines
tools/testing/selftests/bpf/Makefile +3
-0+# urandom_read is built with clang. Copy $(CFLAGS) before EXTRA_CFLAGS are +# appended so that it does not inherit potentially incompatible options. +URANDOM_READ_CFLAGS := $(CFLAGS)Later in the
Makefile, include../lib.mkis executed and it appends CFLAGS like -D_GNU_SOURCE= which will be missing fromURANDOM_READ_CFLAGShere. Perhaps move these assignments below the include?
Will do, thanks!
PATCH v4 28/30 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
Re: [PATCH v4 28/30] selftests/hid: Append extra cflags
Quoted 13 lines · Leo Yan
Append
EXTRA_CFLAGSto CFLAGS so that additional flags can be applied to the compiler.Signed-off-by Leo Yan <[email protected]>--- tools/testing/selftests/hid/Makefile | 1 + 1 file changed, 1 insertion(+)tools/testing/selftests/hid/Makefile +0
-0
tools/testing/selftests/hid/Makefile HOSTPKG_CONFIG := pkg-config · line 29
Quoted 4 lines
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)
Cheers,
Benjamin
Quoted 8 lines
tools/testing/selftests/hid/Makefile +0
-0LDLIBS += -lelf -lz -lrt -lpthreadSignature · 1 line
2.34.1
PATCH v4 29/30 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 | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
tools/testing/selftests/nolibc/Makefile +2 -4
@@ -3,15 +3,13 @@ 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
Signature · 1 line
2.34.1
Thomas Weißschuh
maintainerRe: [PATCH v4 29/30] selftests/nolibc: Append extra cflags
Quoted 22 lines · Leo Yan
Include
tools/scripts/Makefile.include, which may provide additional flags inEXTRA_CFLAGS, and append to CFLAGS.Since Makefile.include already defines cc-option, remove the redundant definition and include.
Signed-off-by Leo Yan <[email protected]>--- tools/testing/selftests/nolibc/Makefile | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)tools/testing/selftests/nolibc/Makefile +0
-3@@ -3,15 +3,13 @@ TEST_GEN_PROGS := nolibc-test libc-test include ../lib.mk -include $(top_srcdir)/scripts/Makefile.compiler - -cc-option = $(call __cc-option, $(CC),,$(1),$(2))
tools/testing/selftests/nolibc/Makefile line 14
Quoted 10 lines
tools/testing/selftests/nolibc/Makefile +2
-1+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
The rule for "libc-test", which uses the standard $(LINK.c) to invoke the compiler, does not respect $(EXTRA_CFLAGS) automatically. Is this intentional? It also affects all other users of lib.mk which don't have any custom cflags handling.
If so, there should be an override for the "libc-test" target, too. But if I am supposed to pick up this patch, I can fix it up when applying.
Thomas
Re: [PATCH v4 29/30] selftests/nolibc: Append extra cflags
Quoted 27 lines · Thomas Weißschuh
Quoted 26 lines · Leo Yan
Include
tools/scripts/Makefile.include, which may provide additional flags inEXTRA_CFLAGS, and append to CFLAGS.Since Makefile.include already defines cc-option, remove the redundant definition and include.
Signed-off-by Leo Yan <[email protected]>--- tools/testing/selftests/nolibc/Makefile | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)tools/testing/selftests/nolibc/Makefile +1
-3@@ -3,15 +3,13 @@ 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
Quoted 10 lines
tools/testing/selftests/nolibc/Makefile line 14
Quoted 6 lines
tools/testing/selftests/nolibc/Makefile +1
-1$(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 | headersThe rule for "libc-test", which uses the standard $(LINK.c) to invoke the compiler, does not respect $(EXTRA_CFLAGS) automatically. Is this intentional?
Thanks for the review. Is the change below OK with you? I can update it before sending a new series.
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 $@
Quoted 2 lines
It also affects all other users of lib.mk which
don't have any custom cflags handling.
Many projects include lib.mk, but most do not include tools/scripts/Makefile.include. Without it, the appended EXTRA_CFLAGS cannot be inherited. This is why I did not touch those projects.
Appending EXTRA_CFLAGS in lib.mk may not be a good idea ? as such a global change could break some builds.
Thanks,
Leo
PATCH v4 30/30 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
Hi Leo,
Quoted 8 lines · Leo Yan
Thank you for reviewing v3 and I appreciate much Ian's suggestions, most of which have been adopted into this series.
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 changes are organized into three parts:
Quoted 9 lines
Patches 01 – 07: Preparation before adding the new compiler option.
Fix typos, adjust Makefiles to ensure the newly introduced option does not cause regressions.
Patch 08: Propagate -fzero-init-padding-bits=all to
EXTRA_CFLAGSandHOST_EXTRACFLAGSfor the CC and HOSTCC compilers, respectively.
Patches 09 – 30: ApplyEXTRA_CFLAGSandHOST_EXTRACFLAGSin
project Makefiles.
Through which tree do you expect these patch to be picked up ? Each maintainer picks the patches related to their subsystem ?
Jonathan Cameron
maintainerQuoted 20 lines · On Wed, 11 Mar 2026 09:44:16 +0100 Daniel Lezcano…
Hi Leo,
Quoted 8 lines · Leo Yan
Thank you for reviewing v3 and I appreciate much Ian's suggestions, most of which have been adopted into this series.
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 changes are organized into three parts:
Quoted 9 lines
Patches 01 – 07: Preparation before adding the new compiler option.
Fix typos, adjust Makefiles to ensure the newly introduced option does not cause regressions.
Patch 08: Propagate -fzero-init-padding-bits=all to
EXTRA_CFLAGSandHOST_EXTRACFLAGSfor the CC and HOSTCC compilers, respectively.
Patches 09 – 30: ApplyEXTRA_CFLAGSandHOST_EXTRACFLAGSin
project Makefiles.
Quoted 2 lines
Through which tree do you expect these patch to be picked up ? Each maintainer picks the patches related to their subsystem ?
If that's the case it would be helpful to +CC the relevant subsystem lists on the patches that you expect to go that path.
Jonathan
Quoted 23 lines · Jonathan Cameron
Quoted 20 lines · On Wed, 11 Mar 2026 09:44:16 +0100 Daniel Lezcano…
Hi Leo,
Quoted 17 lines · Leo Yan
Thank you for reviewing v3 and I appreciate much Ian's suggestions, most of which have been adopted into this series.
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 changes are organized into three parts:
Patches 01 – 07: Preparation before adding the new compiler option.
Fix typos, adjust Makefiles to ensure the newly introduced option does not cause regressions.
Patch 08: Propagate -fzero-init-padding-bits=all to
EXTRA_CFLAGSandHOST_EXTRACFLAGSfor the CC and HOSTCC compilers, respectively.
Patches 09 – 30: ApplyEXTRA_CFLAGSandHOST_EXTRACFLAGSin
project Makefiles.
Quoted 5 lines
Quoted 2 lines
Through which tree do you expect these patch to be picked up ? Each maintainer picks the patches related to their subsystem ?
If that's the case it would be helpful to +CC the relevant subsystem lists on the patches that you expect to go that path.
I deliberately looped mainatiners but not CC'ed each subsystem lists, as it is a long list so I don't want to spam them.
If we conclude to go via subsystem trees, I will CC subsystem lists. Thanks for reminding.
Andrew Morton
maintainerQuoted 24 lines · On Wed, 11 Mar 2026 09:23:31 +0000 Leo Yan <[email protected]> wrote:
Quoted 23 lines · Jonathan Cameron
Quoted 20 lines · On Wed, 11 Mar 2026 09:44:16 +0100 Daniel Lezcano…
Hi Leo,
Quoted 17 lines · Leo Yan
Thank you for reviewing v3 and I appreciate much Ian's suggestions, most of which have been adopted into this series.
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 changes are organized into three parts:
Patches 01 – 07: Preparation before adding the new compiler option.
Fix typos, adjust Makefiles to ensure the newly introduced option does not cause regressions.
Patch 08: Propagate -fzero-init-padding-bits=all to
EXTRA_CFLAGSandHOST_EXTRACFLAGSfor the CC and HOSTCC compilers, respectively.
Patches 09 – 30: ApplyEXTRA_CFLAGSandHOST_EXTRACFLAGSin
project Makefiles.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Through which tree do you expect these patch to be picked up ? Each maintainer picks the patches related to their subsystem ?
My common approach to this sort of thing (which works) is to put everything into mm.git, try to cc the whole world.
If Mark alerts us to the appearance of particular patches in linux-next via another tree, I drop the mm.git copy, so maintainers can simply cherrypick things and it's all automatic.
If maintainers send an ack (easiest!) then great.
Whatever is left over I upstream in the next merge window.
Quoted 8 lines
Quoted 2 lines
If that's the case it would be helpful to +CC the relevant subsystem lists on the patches that you expect to go that path.
I deliberately looped mainatiners but not CC'ed each subsystem lists, as it is a long list so I don't want to spam them.
If we conclude to go via subsystem trees, I will CC subsystem lists. Thanks for reminding.
Sure.
I can ensure that the appropriate maintainers are cc'ed on the relevant
mm.git commits. I generally don't auto-cc mailing lists - I already spray
out too many emails!
Hi Daniel,
On Wed, Mar 11, 2026 at 09:44:16AM +0100, Daniel Lezcano wrote:
[...]
Quoted 11 lines
Quoted 11 lines
In this version, the changes are organized into three parts:
Patches 01 – 07: Preparation before adding the new compiler option.
Fix typos, adjust Makefiles to ensure the newly introduced option does not cause regressions.
Patch 08: Propagate -fzero-init-padding-bits=all to
EXTRA_CFLAGSandHOST_EXTRACFLAGSfor the CC and HOSTCC compilers, respectively.
Patches 09 – 30: ApplyEXTRA_CFLAGSandHOST_EXTRACFLAGSin
project Makefiles.
Quoted 2 lines
Through which tree do you expect these patch to be picked up ? Each maintainer picks the patches related to their subsystem ?
I can propose a pickup sequence, but this may need confirmation from the tools maintainers (especially perf, bpftool, BPF).
I expect patches 01-08 can be merged in one go, as this would be safe not break anything. Afterwards, patches 09–30 can be picked up separately by subsystem maintainers, or merged together.
So far, IIUC, there are no maintainers for the tools build. If no objection from maintainers to merge in one go, I think we have chance via perf-tools-next tree. Arnaldo, Namhyung, how about you think ? (sorry this might introduce extra efforts for you).
Thanks,
Leo