[Devel] [PATCH vz10] selftests: do not override CFLAGS set by the build environment

Konstantin Khorenko khorenko at virtuozzo.com
Fri Feb 13 18:25:54 MSK 2026


   |-----------------------------------------|--------------------------------------------------|
   | selftests/ve_printk/Makefile            | CFLAGS = -g -I../../../../usr/include/ -Wall -O2 |
   | selftests/resctrl/Makefile              | CFLAGS = -g -Wall -O2 -D_FORTIFY_SOURCE=2        |
   | selftests/move_mount_set_group/Makefile | CFLAGS = -g $(KHDR_INCLUDES) -Wall -O2           |
   | selftests/mm/Makefile                   | CFLAGS = -Wall -I $(top_srcdir) ...              |
   | selftests/firmware/Makefile             | CFLAGS = -Wall \                                 |
   | selftests/efivarfs/Makefile             | CFLAGS = -Wall                                   |

To extend the patch to cover those files as well?

--
Best regards,

Konstantin Khorenko,
Virtuozzo Linux Kernel Team

On 2/9/26 21:14, Aleksei Oladko wrote:
> 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 LDFLGAGS="-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.
> 
> https://virtuozzo.atlassian.net/browse/VSTOR-123250
> 
> Signed-off-by: Aleksei Oladko <aleksey.oladko at virtuozzo.com>
> ---
>   tools/testing/selftests/exec/Makefile          | 2 +-
>   tools/testing/selftests/ipc/Makefile           | 4 ++--
>   tools/testing/selftests/mount/Makefile         | 4 ++--
>   tools/testing/selftests/mount_setattr/Makefile | 2 +-
>   tools/testing/selftests/nsfs/Makefile          | 2 +-
>   tools/testing/selftests/safesetid/Makefile     | 2 +-
>   tools/testing/selftests/sigaltstack/Makefile   | 2 +-
>   tools/testing/selftests/timens/Makefile        | 2 +-
>   tools/testing/selftests/tty/Makefile           | 2 +-
>   9 files changed, 11 insertions(+), 11 deletions(-)
> 
> diff --git a/tools/testing/selftests/exec/Makefile b/tools/testing/selftests/exec/Makefile
> index ba012bc5aab9..e0d3f7cbf54c 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
>   
>   ALIGNS := 0x1000 0x200000 0x1000000
> 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 0c0d7b1234c1..f5eb8d8223d7 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
>   
>   TEST_GEN_PROGS := mount_setattr_test
>   
> diff --git a/tools/testing/selftests/nsfs/Makefile b/tools/testing/selftests/nsfs/Makefile
> index dd9bd50b7b93..b51379b3f35c 100644
> --- a/tools/testing/selftests/nsfs/Makefile
> +++ b/tools/testing/selftests/nsfs/Makefile
> @@ -1,6 +1,6 @@
>   # SPDX-License-Identifier: GPL-2.0-only
>   TEST_GEN_PROGS := owner pidns
>   
> -CFLAGS := -Wall -Werror
> +CFLAGS += -Wall -Werror
>   
>   include ../lib.mk
> 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/sigaltstack/Makefile b/tools/testing/selftests/sigaltstack/Makefile
> index 3e96d5d47036..5b41d660143c 100644
> --- a/tools/testing/selftests/sigaltstack/Makefile
> +++ b/tools/testing/selftests/sigaltstack/Makefile
> @@ -1,5 +1,5 @@
>   # SPDX-License-Identifier: GPL-2.0-only
> -CFLAGS = -Wall
> +CFLAGS += -Wall
>   TEST_GEN_PROGS = sas
>   
>   include ../lib.mk
> 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 50d7027b2ae3..03cb8de7e20e 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
>   
>   include ../lib.mk



More information about the Devel mailing list