* [PATCH] selftests: do not override CFLAGS set by the build environment
@ 2026-03-06 0:21 Aleksei Oladko
0 siblings, 0 replies; only message in thread
From: Aleksei Oladko @ 2026-03-06 0:21 UTC (permalink / raw)
To: Shuah Khan, Kees Cook, Christian Brauner, Seth Forshee,
Tony Luck, Reinette Chatre, Dave Martin, James Morse, Babu Moger,
Andy Lutomirski, Thomas Gleixner, Vincenzo Frascino,
Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
Abhinav Saxena, Greg Kroah-Hartman
Cc: linux-kselftest, linux-kernel, linux-mm, linux-fsdevel, Aleksei Oladko
Some kselftests Makefiles assign CFLAGS using 'CFLAGS=...'
which overrides any CFLAGS provided by the build environment.
If the environment set flags, overriding CFLAGS may result in
inconsistent compiler and linker options and cause build failures,
for example when building PIE binaries:
# export CFLAGS="-fPIE"
# export LDFLAGS="-pie"
# make -C tools/testing/selftests/ TARGETS=mount_setattr
make: Entering directory '/build/kernel/tools/testing/selftests'
make[1]: Entering directory '/build/kernel/tools/testing/selftests/mount_setattr'
CC mount_setattr_test
/usr/bin/ld: warning: -z pack-relative-relocs ignored
/usr/bin/ld: /tmp/ccikConN.o: relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a PIE object; recompile with -fPIE
collect2: error: ld returned 1 exit status
make[1]: *** [../lib.mk:222: /build/kernel/tools/testing/selftests/mount_setattr/mount_setattr_test] Error 1
Fix this by appending to CFLAGS using 'CFLAGS+=' instead of
overriding them.
The fix is not applied to the Makefiles in x86, riscv, mm, arm64
and powerpc as they fully define their flags.
Signed-off-by: Aleksei Oladko <aleksey.oladko@virtuozzo.com>
---
tools/testing/selftests/efivarfs/Makefile | 2 +-
tools/testing/selftests/exec/Makefile | 2 +-
tools/testing/selftests/firmware/Makefile | 4 ++--
tools/testing/selftests/ipc/Makefile | 4 ++--
tools/testing/selftests/mount/Makefile | 4 ++--
tools/testing/selftests/mount_setattr/Makefile | 2 +-
tools/testing/selftests/move_mount_set_group/Makefile | 2 +-
tools/testing/selftests/resctrl/Makefile | 2 +-
tools/testing/selftests/safesetid/Makefile | 2 +-
tools/testing/selftests/signal/Makefile | 2 +-
tools/testing/selftests/timens/Makefile | 2 +-
tools/testing/selftests/tty/Makefile | 2 +-
tools/testing/selftests/vDSO/Makefile | 2 +-
13 files changed, 16 insertions(+), 16 deletions(-)
diff --git a/tools/testing/selftests/efivarfs/Makefile b/tools/testing/selftests/efivarfs/Makefile
index e3181338ba5e..f6c412059af3 100644
--- a/tools/testing/selftests/efivarfs/Makefile
+++ b/tools/testing/selftests/efivarfs/Makefile
@@ -1,5 +1,5 @@
# SPDX-License-Identifier: GPL-2.0-only
-CFLAGS = -Wall
+CFLAGS += -Wall
TEST_GEN_FILES := open-unlink create-read
TEST_PROGS := efivarfs.sh
diff --git a/tools/testing/selftests/exec/Makefile b/tools/testing/selftests/exec/Makefile
index 45a3cfc435cf..54cdefb9ccb0 100644
--- a/tools/testing/selftests/exec/Makefile
+++ b/tools/testing/selftests/exec/Makefile
@@ -1,5 +1,5 @@
# SPDX-License-Identifier: GPL-2.0
-CFLAGS = -Wall
+CFLAGS += -Wall
CFLAGS += -Wno-nonnull
CFLAGS += $(KHDR_INCLUDES)
diff --git a/tools/testing/selftests/firmware/Makefile b/tools/testing/selftests/firmware/Makefile
index 7992969deaa2..dd9acf972cf5 100644
--- a/tools/testing/selftests/firmware/Makefile
+++ b/tools/testing/selftests/firmware/Makefile
@@ -1,7 +1,7 @@
# SPDX-License-Identifier: GPL-2.0-only
# Makefile for firmware loading selftests
-CFLAGS = -Wall \
- -O2
+CFLAGS += -Wall \
+ -O2
TEST_PROGS := fw_run_tests.sh
TEST_FILES := fw_fallback.sh fw_filesystem.sh fw_upload.sh fw_lib.sh
diff --git a/tools/testing/selftests/ipc/Makefile b/tools/testing/selftests/ipc/Makefile
index 50e9c299fc4a..5a5577767a35 100644
--- a/tools/testing/selftests/ipc/Makefile
+++ b/tools/testing/selftests/ipc/Makefile
@@ -3,11 +3,11 @@ uname_M := $(shell uname -m 2>/dev/null || echo not)
ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/i386/)
ifeq ($(ARCH),i386)
ARCH := x86
- CFLAGS := -DCONFIG_X86_32 -D__i386__
+ CFLAGS += -DCONFIG_X86_32 -D__i386__
endif
ifeq ($(ARCH),x86_64)
ARCH := x86
- CFLAGS := -DCONFIG_X86_64 -D__x86_64__
+ CFLAGS += -DCONFIG_X86_64 -D__x86_64__
endif
CFLAGS += $(KHDR_INCLUDES)
diff --git a/tools/testing/selftests/mount/Makefile b/tools/testing/selftests/mount/Makefile
index 2d9454841644..38361a896363 100644
--- a/tools/testing/selftests/mount/Makefile
+++ b/tools/testing/selftests/mount/Makefile
@@ -1,7 +1,7 @@
# SPDX-License-Identifier: GPL-2.0
# Makefile for mount selftests.
-CFLAGS = -Wall \
- -O2
+CFLAGS += -Wall \
+ -O2
TEST_PROGS := run_unprivileged_remount.sh run_nosymfollow.sh
TEST_GEN_FILES := unprivileged-remount-test nosymfollow-test
diff --git a/tools/testing/selftests/mount_setattr/Makefile b/tools/testing/selftests/mount_setattr/Makefile
index 4d4f810cdf2c..fbdb8f69b548 100644
--- a/tools/testing/selftests/mount_setattr/Makefile
+++ b/tools/testing/selftests/mount_setattr/Makefile
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: GPL-2.0
# Makefile for mount selftests.
-CFLAGS = -g $(KHDR_INCLUDES) -Wall -O2 -pthread
+CFLAGS += -g $(KHDR_INCLUDES) -Wall -O2 -pthread
LOCAL_HDRS += ../filesystems/wrappers.h
diff --git a/tools/testing/selftests/move_mount_set_group/Makefile b/tools/testing/selftests/move_mount_set_group/Makefile
index 94235846b6f9..8771a5491ea3 100644
--- a/tools/testing/selftests/move_mount_set_group/Makefile
+++ b/tools/testing/selftests/move_mount_set_group/Makefile
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: GPL-2.0
# Makefile for mount selftests.
-CFLAGS = -g $(KHDR_INCLUDES) -Wall -O2
+CFLAGS += -g $(KHDR_INCLUDES) -Wall -O2
TEST_GEN_FILES += move_mount_set_group_test
diff --git a/tools/testing/selftests/resctrl/Makefile b/tools/testing/selftests/resctrl/Makefile
index 984534cfbf1b..1d566a91faa7 100644
--- a/tools/testing/selftests/resctrl/Makefile
+++ b/tools/testing/selftests/resctrl/Makefile
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: GPL-2.0
-CFLAGS = -g -Wall -O2 -D_FORTIFY_SOURCE=2
+CFLAGS += -g -Wall -O2 -D_FORTIFY_SOURCE=2
CFLAGS += $(KHDR_INCLUDES)
TEST_GEN_PROGS := resctrl_tests
diff --git a/tools/testing/selftests/safesetid/Makefile b/tools/testing/selftests/safesetid/Makefile
index e815bbf2d0f4..d3811515d8e3 100644
--- a/tools/testing/selftests/safesetid/Makefile
+++ b/tools/testing/selftests/safesetid/Makefile
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: GPL-2.0
# Makefile for SafeSetID selftest.
-CFLAGS = -Wall -O2
+CFLAGS += -Wall -O2
LDLIBS = -lcap
TEST_PROGS := safesetid-test.sh
diff --git a/tools/testing/selftests/signal/Makefile b/tools/testing/selftests/signal/Makefile
index e0bf7058d19c..6c437f95132d 100644
--- a/tools/testing/selftests/signal/Makefile
+++ b/tools/testing/selftests/signal/Makefile
@@ -1,5 +1,5 @@
# SPDX-License-Identifier: GPL-2.0-only
-CFLAGS = -Wall
+CFLAGS += -Wall
TEST_GEN_PROGS = mangle_uc_sigmask
TEST_GEN_PROGS += sas
diff --git a/tools/testing/selftests/timens/Makefile b/tools/testing/selftests/timens/Makefile
index f0d51d4d2c87..357077792395 100644
--- a/tools/testing/selftests/timens/Makefile
+++ b/tools/testing/selftests/timens/Makefile
@@ -1,7 +1,7 @@
TEST_GEN_PROGS := timens timerfd timer clock_nanosleep procfs exec futex vfork_exec
TEST_GEN_PROGS_EXTENDED := gettime_perf
-CFLAGS := -Wall -Werror -pthread
+CFLAGS += -Wall -Werror -pthread
LDLIBS := -lrt -ldl
include ../lib.mk
diff --git a/tools/testing/selftests/tty/Makefile b/tools/testing/selftests/tty/Makefile
index 7f6fbe5a0cd5..e9c22dafe5e1 100644
--- a/tools/testing/selftests/tty/Makefile
+++ b/tools/testing/selftests/tty/Makefile
@@ -1,5 +1,5 @@
# SPDX-License-Identifier: GPL-2.0
-CFLAGS = -O2 -Wall
+CFLAGS += -O2 -Wall
TEST_GEN_PROGS := tty_tstamp_update tty_tiocsti_test
LDLIBS += -lcap
diff --git a/tools/testing/selftests/vDSO/Makefile b/tools/testing/selftests/vDSO/Makefile
index e361aca22a74..1f4628ceb975 100644
--- a/tools/testing/selftests/vDSO/Makefile
+++ b/tools/testing/selftests/vDSO/Makefile
@@ -11,7 +11,7 @@ TEST_GEN_PROGS += vdso_test_correctness
TEST_GEN_PROGS += vdso_test_getrandom
TEST_GEN_PROGS += vdso_test_chacha
-CFLAGS := -std=gnu99 -O2 -Wall -Wstrict-prototypes
+CFLAGS += -std=gnu99 -O2 -Wall -Wstrict-prototypes
ifeq ($(CONFIG_X86_32),y)
LDLIBS += -lgcc_s
--
2.43.0
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-03-06 0:21 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-03-06 0:21 [PATCH] selftests: do not override CFLAGS set by the build environment Aleksei Oladko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox