Skip to content

Commit cc937da

Browse files
edliawakpm00
authored andcommitted
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/[email protected] Signed-off-by: Edward Liaw <[email protected]> Suggested-by: John Hubbard <[email protected]> Acked-by: Shuah Khan <[email protected]> Reviewed-by: Muhammad Usama Anjum <[email protected]> Cc: Albert Ou <[email protected]> Cc: André Almeida <[email protected]> Cc: Darren Hart <[email protected]> Cc: Dave Hansen <[email protected]> Cc: Davidlohr Bueso <[email protected]> Cc: David S. Miller <[email protected]> Cc: Eric Dumazet <[email protected]> Cc: Eric W. Biederman <[email protected]> Cc: Fenghua Yu <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jakub Kicinski <[email protected]> Cc: Jarkko Sakkinen <[email protected]> Cc: Jason Gunthorpe <[email protected]> Cc: Kees Cook <[email protected]> Cc: Kevin Tian <[email protected]> Cc: Palmer Dabbelt <[email protected]> Cc: Paolo Abeni <[email protected]> Cc: Paolo Bonzini <[email protected]> Cc: Paul Walmsley <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Reinette Chatre <[email protected]> Cc: Sean Christopherson <[email protected]> Cc: Thomas Gleixner <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 95139d9 commit cc937da

File tree

15 files changed

+12
-15
lines changed

15 files changed

+12
-15
lines changed

tools/testing/selftests/exec/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# SPDX-License-Identifier: GPL-2.0
22
CFLAGS = -Wall
33
CFLAGS += -Wno-nonnull
4-
CFLAGS += -D_GNU_SOURCE
54

65
TEST_PROGS := binfmt_script.py
76
TEST_GEN_PROGS := execveat load_address_4096 load_address_2097152 load_address_16777216 non-regular

tools/testing/selftests/futex/functional/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# SPDX-License-Identifier: GPL-2.0
22
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)
44
LDLIBS := -lpthread -lrt
55

66
LOCAL_HDRS := \

tools/testing/selftests/intel_pstate/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# SPDX-License-Identifier: GPL-2.0
2-
CFLAGS := $(CFLAGS) -Wall -D_GNU_SOURCE
2+
CFLAGS := $(CFLAGS) -Wall
33
LDLIBS += -lm
44

55
ARCH ?= $(shell uname -m 2>/dev/null || echo not)

tools/testing/selftests/iommu/Makefile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
CFLAGS += -Wall -O2 -Wno-unused-function
33
CFLAGS += $(KHDR_INCLUDES)
44

5-
CFLAGS += -D_GNU_SOURCE
6-
75
TEST_GEN_PROGS :=
86
TEST_GEN_PROGS += iommufd
97
TEST_GEN_PROGS += iommufd_fail_nth

tools/testing/selftests/kvm/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ LINUX_TOOL_ARCH_INCLUDE = $(top_srcdir)/tools/arch/$(ARCH)/include
231231
endif
232232
CFLAGS += -Wall -Wstrict-prototypes -Wuninitialized -O2 -g -std=gnu99 \
233233
-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 \
235235
-fno-builtin-memset -fno-builtin-strnlen \
236236
-fno-stack-protector -fno-PIE -I$(LINUX_TOOL_INCLUDE) \
237237
-I$(LINUX_TOOL_ARCH_INCLUDE) -I$(LINUX_HDR_PATH) -Iinclude \

tools/testing/selftests/lib.mk

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ endef
188188
clean: $(if $(TEST_GEN_MODS_DIR),clean_mods_dir)
189189
$(CLEAN)
190190

191+
# Build with _GNU_SOURCE by default
192+
CFLAGS += -D_GNU_SOURCE=
193+
191194
# Enables to extend CFLAGS and LDFLAGS from command line, e.g.
192195
# make USERCFLAGS=-Werror USERLDFLAGS=-static
193196
CFLAGS += $(USERCFLAGS)

tools/testing/selftests/mm/thuge-gen.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
sudo ipcs | awk '$1 == "0x00000000" {print $2}' | xargs -n1 sudo ipcrm -m
1414
(warning this will remove all if someone else uses them) */
1515

16-
#define _GNU_SOURCE 1
16+
#define _GNU_SOURCE
1717
#include <sys/mman.h>
1818
#include <linux/mman.h>
1919
#include <stdlib.h>

tools/testing/selftests/net/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# SPDX-License-Identifier: GPL-2.0
22
# Makefile for net selftests
33

4-
CFLAGS = -Wall -Wl,--no-as-needed -O2 -g
4+
CFLAGS += -Wall -Wl,--no-as-needed -O2 -g
55
CFLAGS += -I../../../../usr/include/ $(KHDR_INCLUDES)
66
# Additional include paths needed by kselftest.h
77
CFLAGS += -I../

tools/testing/selftests/net/tcp_ao/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ LIB := $(LIBDIR)/libaotst.a
2626
LDLIBS += $(LIB) -pthread
2727
LIBDEPS := lib/aolib.h Makefile
2828

29-
CFLAGS := -Wall -O2 -g -D_GNU_SOURCE -fno-strict-aliasing
29+
CFLAGS += -Wall -O2 -g -fno-strict-aliasing
3030
CFLAGS += $(KHDR_INCLUDES)
3131
CFLAGS += -iquote ./lib/ -I ../../../../include/
3232

tools/testing/selftests/proc/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# SPDX-License-Identifier: GPL-2.0-only
22
CFLAGS += -Wall -O2 -Wno-unused-function
3-
CFLAGS += -D_GNU_SOURCE
43
LDFLAGS += -pthread
54

65
TEST_GEN_PROGS :=

tools/testing/selftests/resctrl/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# SPDX-License-Identifier: GPL-2.0
22

3-
CFLAGS = -g -Wall -O2 -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE
3+
CFLAGS = -g -Wall -O2 -D_FORTIFY_SOURCE=2
44
CFLAGS += $(KHDR_INCLUDES)
55

66
TEST_GEN_PROGS := resctrl_tests

tools/testing/selftests/ring-buffer/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# SPDX-License-Identifier: GPL-2.0
22
CFLAGS += -Wl,-no-as-needed -Wall
33
CFLAGS += $(KHDR_INCLUDES)
4-
CFLAGS += -D_GNU_SOURCE
54

65
TEST_GEN_PROGS = map_test
76

tools/testing/selftests/riscv/mm/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Originally tools/testing/arm64/abi/Makefile
44

55
# Additional include paths needed by kselftest.h and local headers
6-
CFLAGS += -D_GNU_SOURCE -std=gnu99 -I.
6+
CFLAGS += -std=gnu99 -I.
77

88
TEST_GEN_FILES := mmap_default mmap_bottomup
99

tools/testing/selftests/sgx/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ OBJCOPY := $(CROSS_COMPILE)objcopy
1212
endif
1313

1414
INCLUDES := -I$(top_srcdir)/tools/include
15-
HOST_CFLAGS := -Wall -Werror -g $(INCLUDES) -fPIC
15+
HOST_CFLAGS := -Wall -Werror -g $(INCLUDES) -fPIC $(CFLAGS)
1616
HOST_LDFLAGS := -z noexecstack -lcrypto
1717
ENCL_CFLAGS += -Wall -Werror -static-pie -nostdlib -ffreestanding -fPIE \
1818
-fno-stack-protector -mrdrnd $(INCLUDES)

tools/testing/selftests/tmpfs/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# SPDX-License-Identifier: GPL-2.0-only
22
CFLAGS += -Wall -O2
3-
CFLAGS += -D_GNU_SOURCE
43

54
TEST_GEN_PROGS :=
65
TEST_GEN_PROGS += bug-link-o-tmpfile

0 commit comments

Comments
 (0)