Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests: centralize -D_GNU_SOURCE= to CFLAGS in lib.mk

Centralize the _GNU_SOURCE definition to CFLAGS in lib.mk. Remove
redundant defines from Makefiles that import lib.mk. Convert any usage of
"#define _GNU_SOURCE 1" to "#define _GNU_SOURCE".

This uses the form "-D_GNU_SOURCE=", which is equivalent to
"#define _GNU_SOURCE".

Otherwise using "-D_GNU_SOURCE" is equivalent to "-D_GNU_SOURCE=1" and
"#define _GNU_SOURCE 1", which is less commonly seen in source code and
would require many changes in selftests to avoid redefinition warnings.

Link: https://lkml.kernel.org/r/20240625223454.1586259-2-edliaw@google.com
Signed-off-by: Edward Liaw <edliaw@google.com>
Suggested-by: John Hubbard <jhubbard@nvidia.com>
Acked-by: Shuah Khan <skhan@linuxfoundation.org>
Reviewed-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
Cc: Albert Ou <aou@eecs.berkeley.edu>
Cc: André Almeida <andrealmeid@igalia.com>
Cc: Darren Hart <dvhart@infradead.org>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Davidlohr Bueso <dave@stgolabs.net>
Cc: David S. Miller <davem@davemloft.net>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Eric W. Biederman <ebiederm@xmission.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Jarkko Sakkinen <jarkko@kernel.org>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Kees Cook <kees@kernel.org>
Cc: Kevin Tian <kevin.tian@intel.com>
Cc: Palmer Dabbelt <palmer@dabbelt.com>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Paul Walmsley <paul.walmsley@sifive.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Reinette Chatre <reinette.chatre@intel.com>
Cc: Sean Christopherson <seanjc@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Edward Liaw and committed by
Andrew Morton
cc937dad 95139d94

+12 -15
-1
tools/testing/selftests/exec/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 2 CFLAGS = -Wall 3 3 CFLAGS += -Wno-nonnull 4 - CFLAGS += -D_GNU_SOURCE 5 4 6 5 TEST_PROGS := binfmt_script.py 7 6 TEST_GEN_PROGS := execveat load_address_4096 load_address_2097152 load_address_16777216 non-regular
+1 -1
tools/testing/selftests/futex/functional/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 2 INCLUDES := -I../include -I../../ $(KHDR_INCLUDES) 3 - CFLAGS := $(CFLAGS) -g -O2 -Wall -D_GNU_SOURCE= -pthread $(INCLUDES) $(KHDR_INCLUDES) 3 + CFLAGS := $(CFLAGS) -g -O2 -Wall -pthread $(INCLUDES) $(KHDR_INCLUDES) 4 4 LDLIBS := -lpthread -lrt 5 5 6 6 LOCAL_HDRS := \
+1 -1
tools/testing/selftests/intel_pstate/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 - CFLAGS := $(CFLAGS) -Wall -D_GNU_SOURCE 2 + CFLAGS := $(CFLAGS) -Wall 3 3 LDLIBS += -lm 4 4 5 5 ARCH ?= $(shell uname -m 2>/dev/null || echo not)
-2
tools/testing/selftests/iommu/Makefile
··· 2 2 CFLAGS += -Wall -O2 -Wno-unused-function 3 3 CFLAGS += $(KHDR_INCLUDES) 4 4 5 - CFLAGS += -D_GNU_SOURCE 6 - 7 5 TEST_GEN_PROGS := 8 6 TEST_GEN_PROGS += iommufd 9 7 TEST_GEN_PROGS += iommufd_fail_nth
+1 -1
tools/testing/selftests/kvm/Makefile
··· 231 231 endif 232 232 CFLAGS += -Wall -Wstrict-prototypes -Wuninitialized -O2 -g -std=gnu99 \ 233 233 -Wno-gnu-variable-sized-type-not-at-end -MD -MP -DCONFIG_64BIT \ 234 - -D_GNU_SOURCE -fno-builtin-memcmp -fno-builtin-memcpy \ 234 + -fno-builtin-memcmp -fno-builtin-memcpy \ 235 235 -fno-builtin-memset -fno-builtin-strnlen \ 236 236 -fno-stack-protector -fno-PIE -I$(LINUX_TOOL_INCLUDE) \ 237 237 -I$(LINUX_TOOL_ARCH_INCLUDE) -I$(LINUX_HDR_PATH) -Iinclude \
+3
tools/testing/selftests/lib.mk
··· 188 188 clean: $(if $(TEST_GEN_MODS_DIR),clean_mods_dir) 189 189 $(CLEAN) 190 190 191 + # Build with _GNU_SOURCE by default 192 + CFLAGS += -D_GNU_SOURCE= 193 + 191 194 # Enables to extend CFLAGS and LDFLAGS from command line, e.g. 192 195 # make USERCFLAGS=-Werror USERLDFLAGS=-static 193 196 CFLAGS += $(USERCFLAGS)
+1 -1
tools/testing/selftests/mm/thuge-gen.c
··· 13 13 sudo ipcs | awk '$1 == "0x00000000" {print $2}' | xargs -n1 sudo ipcrm -m 14 14 (warning this will remove all if someone else uses them) */ 15 15 16 - #define _GNU_SOURCE 1 16 + #define _GNU_SOURCE 17 17 #include <sys/mman.h> 18 18 #include <linux/mman.h> 19 19 #include <stdlib.h>
+1 -1
tools/testing/selftests/net/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 2 # Makefile for net selftests 3 3 4 - CFLAGS = -Wall -Wl,--no-as-needed -O2 -g 4 + CFLAGS += -Wall -Wl,--no-as-needed -O2 -g 5 5 CFLAGS += -I../../../../usr/include/ $(KHDR_INCLUDES) 6 6 # Additional include paths needed by kselftest.h 7 7 CFLAGS += -I../
+1 -1
tools/testing/selftests/net/tcp_ao/Makefile
··· 26 26 LDLIBS += $(LIB) -pthread 27 27 LIBDEPS := lib/aolib.h Makefile 28 28 29 - CFLAGS := -Wall -O2 -g -D_GNU_SOURCE -fno-strict-aliasing 29 + CFLAGS += -Wall -O2 -g -fno-strict-aliasing 30 30 CFLAGS += $(KHDR_INCLUDES) 31 31 CFLAGS += -iquote ./lib/ -I ../../../../include/ 32 32
-1
tools/testing/selftests/proc/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0-only 2 2 CFLAGS += -Wall -O2 -Wno-unused-function 3 - CFLAGS += -D_GNU_SOURCE 4 3 LDFLAGS += -pthread 5 4 6 5 TEST_GEN_PROGS :=
+1 -1
tools/testing/selftests/resctrl/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 2 3 - CFLAGS = -g -Wall -O2 -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE 3 + CFLAGS = -g -Wall -O2 -D_FORTIFY_SOURCE=2 4 4 CFLAGS += $(KHDR_INCLUDES) 5 5 6 6 TEST_GEN_PROGS := resctrl_tests
-1
tools/testing/selftests/ring-buffer/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 2 CFLAGS += -Wl,-no-as-needed -Wall 3 3 CFLAGS += $(KHDR_INCLUDES) 4 - CFLAGS += -D_GNU_SOURCE 5 4 6 5 TEST_GEN_PROGS = map_test 7 6
+1 -1
tools/testing/selftests/riscv/mm/Makefile
··· 3 3 # Originally tools/testing/arm64/abi/Makefile 4 4 5 5 # Additional include paths needed by kselftest.h and local headers 6 - CFLAGS += -D_GNU_SOURCE -std=gnu99 -I. 6 + CFLAGS += -std=gnu99 -I. 7 7 8 8 TEST_GEN_FILES := mmap_default mmap_bottomup 9 9
+1 -1
tools/testing/selftests/sgx/Makefile
··· 12 12 endif 13 13 14 14 INCLUDES := -I$(top_srcdir)/tools/include 15 - HOST_CFLAGS := -Wall -Werror -g $(INCLUDES) -fPIC 15 + HOST_CFLAGS := -Wall -Werror -g $(INCLUDES) -fPIC $(CFLAGS) 16 16 HOST_LDFLAGS := -z noexecstack -lcrypto 17 17 ENCL_CFLAGS += -Wall -Werror -static-pie -nostdlib -ffreestanding -fPIE \ 18 18 -fno-stack-protector -mrdrnd $(INCLUDES)
-1
tools/testing/selftests/tmpfs/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0-only 2 2 CFLAGS += -Wall -O2 3 - CFLAGS += -D_GNU_SOURCE 4 3 5 4 TEST_GEN_PROGS := 6 5 TEST_GEN_PROGS += bug-link-o-tmpfile