On 2/17/26 16:55, 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 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.
https://virtuozzo.atlassian.net/browse/VSTOR-123250
Signed-off-by: Aleksei Oladko <[email protected]>
---
v2:
- added fix to Makefiles in ve_printk, size, efivarfs, vDSO, resctrl,
move_mount_set_group, firmware, filesystems/overlayfs
---
...
diff --git a/tools/testing/selftests/size/Makefile
b/tools/testing/selftests/size/Makefile
index b87facc00a6e..c17d0c1f6f4a 100644
--- a/tools/testing/selftests/size/Makefile
+++ b/tools/testing/selftests/size/Makefile
@@ -1,5 +1,5 @@
# SPDX-License-Identifier: GPL-2.0-only
-CFLAGS := -static -ffreestanding -nostartfiles -s
+CFLAGS += -static -ffreestanding -nostartfiles -s
1. `size/Makefile` — should NOT be changed (bug)
/ttt/kernels/rh9/diff-10-selftests-do-not-override-CFLAGS-set-by-the-build-environment
lines 211-213
# SPDX-License-Identifier: GPL-2.0-only
-CFLAGS := -static -ffreestanding -nostartfiles -s
+CFLAGS += -static -ffreestanding -nostartfiles -s
This test (get_size) builds a minimal static binary without standard startup files to measure
kernel size overhead.
The flags -static -ffreestanding -nostartfiles -s fundamentally define the build mode. If the
environment provides -fPIE + -pie, it directly conflicts with -static, and the combination of -fPIE
with -ffreestanding -nostartfiles is nonsensical.
The commit message itself says: "The fix is not applied to the Makefiles in x86, riscv, mm, arm64
and powerpc as they fully define their flags." The size/Makefile also fully defines its flags in a
highly specialized way and should be excluded for the same reason.
TEST_GEN_PROGS := get_size
_______________________________________________
Devel mailing list
[email protected]
https://lists.openvz.org/mailman/listinfo/devel