From nobody Thu Dec 18 06:22:17 2025 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CCB2717F366 for ; Tue, 25 Jun 2024 22:35:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719354908; cv=none; b=VS+U/MTbZC/9vHbwaqSTGwt0o5gysau3nS/TMb5LyzP58W3Gxw3wyNnKxnOp6c98A8bt7F7mZciygLmPTY/ekvH4YHzLdEPdTvyX5eCdvoNgdyWVRUaRRNNtfQF80nF7IUwlwtfzNDjngtnVe+Tk8UoRN6jQY68/8bkt24OUAro= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719354908; c=relaxed/simple; bh=Nz14t21hcHX1PDz4gX9brGggz6D63/l/IGgEClEx/P4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=EN8LfYgZ6YALsGYjsa6tAAymuDwgEv01J/yb4+gUH/Sfn0/NIRm4AC0Oim1PKbxC/XCGSSxgPRqBJuapeSehuWvbdbUh2mM64QNJFI8582UlKAUYtT4/a43YbG2Bt8nzNBd1G1rn/RP5ZZl8mNAuigz9V1IcPvfCMbGqAEVE8Qk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edliaw.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=gysGch8L; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edliaw.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="gysGch8L" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6438cfe5af9so79720657b3.0 for ; Tue, 25 Jun 2024 15:35:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1719354905; x=1719959705; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=87Jin1neXman428FZaPVpz5vAZT4i6hdnDg6P39Dvmk=; b=gysGch8Lr+ZJ8ZK1ZKAjLss5CfsUDUxdga3ngMC9+qrw+gD0rZ48JCU4hceJu9FJDz 84yiSLkRkGlpchiV8Nix4CBJSWAvLb2rxB4tnVNo++7Ftz8rSEGUwrOPx6DTjAMxjjh2 9bmcyZMWIG+xG8YzDFvmp+kr3xORJzdP54pKgQ8hLFhSj37DsGmfH/SrSXxBOrKQemAA KAHntA4RXke433RupEuwlbUGe1Ovt3WhIEaoy6vpzJoeQB2/wZQhsmdCDWr/n0h6Ufqq nqL2DzL+XOjyTN43rcbRSXn8V4IQP9zMEFbiRTbb7XRocjs7EKTkpMO5kuVw86H/tezz dQ9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719354905; x=1719959705; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=87Jin1neXman428FZaPVpz5vAZT4i6hdnDg6P39Dvmk=; b=b83Z9XGzMYj9GOyaWZ6YFzihZjUQq+6dHHPj5iOVUXM7qYztFlJM+Ko4bcot9JftM4 EwoPk08DlPO7auz/e4dAvanw9+rA7diwwLL9lYhxvWlmeEEyXNnTvd+Z+piKV3t9x0nn 4spRLOzpMqQrvwJhmyY9sw9ZAoya+bkfHQ+8Js+OlBO90sGvh8EWge0ZG0+QyJgTLH5B 4V3YhKkuvzw7+ilyqrF80kzB2Pts9TTE356PTScYQfxFspz51D0gWTz9ucIjbtR14FOL pkGdQyaJJPAb6Ndv/ci/rVnT4GGjjJjYehJ3tDTgkEmsjKlcviPjBYkUrpn3OPJ6gng6 2Pqg== X-Gm-Message-State: AOJu0YypyHidKio7Yijo72zaMFEx2eaH1Zyku65RoAYC01yeHW+y/S62 Y659tWu+CeUeBwKZu+5ipGGhOcYhVwoLPFtwRK7555a1BNSpvWKtQwrv7hmXWwW7BPJLz6Iydsk 1lg== X-Google-Smtp-Source: AGHT+IEGuPw81A+vd3VK4UXWXuPsSlJshJybw2PugwKr4mE141Kgqb4D3k0bZmkq8unTm2UAe55tWdXFj6o= X-Received: from edliaw.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:305d]) (user=edliaw job=sendgmr) by 2002:a05:690c:6112:b0:61c:89a4:dd5f with SMTP id 00721157ae682-643a76e6dd7mr1219237b3.0.1719354904824; Tue, 25 Jun 2024 15:35:04 -0700 (PDT) Date: Tue, 25 Jun 2024 22:34:45 +0000 In-Reply-To: <20240625223454.1586259-1-edliaw@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240625223454.1586259-1-edliaw@google.com> X-Mailer: git-send-email 2.45.2.803.g4e1b14247a-goog Message-ID: <20240625223454.1586259-2-edliaw@google.com> Subject: [PATCH v7 1/1] selftests: Centralize -D_GNU_SOURCE= to CFLAGS in lib.mk From: Edward Liaw To: linux-kselftest@vger.kernel.org, Eric Biederman , Kees Cook , Shuah Khan , Thomas Gleixner , Ingo Molnar , Peter Zijlstra , Darren Hart , Davidlohr Bueso , "=?UTF-8?q?Andr=C3=A9=20Almeida?=" , Jason Gunthorpe , Kevin Tian , Paolo Bonzini , Andrew Morton , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Fenghua Yu , Reinette Chatre , Paul Walmsley , Palmer Dabbelt , Albert Ou , Jarkko Sakkinen , Dave Hansen Cc: linux-kernel@vger.kernel.org, usama.anjum@collabora.com, seanjc@google.com, kernel-team@android.com, Edward Liaw , linux-mm@kvack.org, iommu@lists.linux.dev, kvm@vger.kernel.org, netdev@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-riscv@lists.infradead.org, linux-sgx@vger.kernel.org, John Hubbard Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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=3D", which is equivalent to "#define _GNU_SOURCE". Otherwise using "-D_GNU_SOURCE" is equivalent to "-D_GNU_SOURCE=3D1" and "#define _GNU_SOURCE 1", which is less commonly seen in source code and would require many changes in selftests to avoid redefinition warnings. Suggested-by: John Hubbard Signed-off-by: Edward Liaw Acked-by: Shuah Khan Reviewed-by: Muhammad Usama Anjum --- tools/testing/selftests/exec/Makefile | 1 - tools/testing/selftests/futex/functional/Makefile | 2 +- tools/testing/selftests/intel_pstate/Makefile | 2 +- tools/testing/selftests/iommu/Makefile | 2 -- tools/testing/selftests/kvm/Makefile | 2 +- tools/testing/selftests/lib.mk | 3 +++ tools/testing/selftests/mm/thuge-gen.c | 2 +- tools/testing/selftests/net/Makefile | 2 +- tools/testing/selftests/net/tcp_ao/Makefile | 2 +- tools/testing/selftests/proc/Makefile | 1 - tools/testing/selftests/resctrl/Makefile | 2 +- tools/testing/selftests/ring-buffer/Makefile | 1 - tools/testing/selftests/riscv/mm/Makefile | 2 +- tools/testing/selftests/sgx/Makefile | 2 +- tools/testing/selftests/tmpfs/Makefile | 1 - 15 files changed, 12 insertions(+), 15 deletions(-) diff --git a/tools/testing/selftests/exec/Makefile b/tools/testing/selftest= s/exec/Makefile index ab67d58cfab7..ba012bc5aab9 100644 --- a/tools/testing/selftests/exec/Makefile +++ b/tools/testing/selftests/exec/Makefile @@ -1,7 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 CFLAGS =3D -Wall CFLAGS +=3D -Wno-nonnull -CFLAGS +=3D -D_GNU_SOURCE =20 ALIGNS :=3D 0x1000 0x200000 0x1000000 ALIGN_PIES :=3D $(patsubst %,load_address.%,$(ALIGNS)) diff --git a/tools/testing/selftests/futex/functional/Makefile b/tools/test= ing/selftests/futex/functional/Makefile index 994fa3468f17..f79f9bac7918 100644 --- a/tools/testing/selftests/futex/functional/Makefile +++ b/tools/testing/selftests/futex/functional/Makefile @@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 INCLUDES :=3D -I../include -I../../ $(KHDR_INCLUDES) -CFLAGS :=3D $(CFLAGS) -g -O2 -Wall -D_GNU_SOURCE=3D -pthread $(INCLUDES) $= (KHDR_INCLUDES) +CFLAGS :=3D $(CFLAGS) -g -O2 -Wall -pthread $(INCLUDES) $(KHDR_INCLUDES) LDLIBS :=3D -lpthread -lrt =20 LOCAL_HDRS :=3D \ diff --git a/tools/testing/selftests/intel_pstate/Makefile b/tools/testing/= selftests/intel_pstate/Makefile index 05d66ef50c97..f45372cb00fe 100644 --- a/tools/testing/selftests/intel_pstate/Makefile +++ b/tools/testing/selftests/intel_pstate/Makefile @@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 -CFLAGS :=3D $(CFLAGS) -Wall -D_GNU_SOURCE +CFLAGS :=3D $(CFLAGS) -Wall LDLIBS +=3D -lm =20 ARCH ?=3D $(shell uname -m 2>/dev/null || echo not) diff --git a/tools/testing/selftests/iommu/Makefile b/tools/testing/selftes= ts/iommu/Makefile index 32c5fdfd0eef..fd6477911f24 100644 --- a/tools/testing/selftests/iommu/Makefile +++ b/tools/testing/selftests/iommu/Makefile @@ -2,8 +2,6 @@ CFLAGS +=3D -Wall -O2 -Wno-unused-function CFLAGS +=3D $(KHDR_INCLUDES) =20 -CFLAGS +=3D -D_GNU_SOURCE - TEST_GEN_PROGS :=3D TEST_GEN_PROGS +=3D iommufd TEST_GEN_PROGS +=3D iommufd_fail_nth diff --git a/tools/testing/selftests/kvm/Makefile b/tools/testing/selftests= /kvm/Makefile index ac280dcba996..4ee37abf70ff 100644 --- a/tools/testing/selftests/kvm/Makefile +++ b/tools/testing/selftests/kvm/Makefile @@ -231,7 +231,7 @@ LINUX_TOOL_ARCH_INCLUDE =3D $(top_srcdir)/tools/arch/$(= ARCH)/include endif CFLAGS +=3D -Wall -Wstrict-prototypes -Wuninitialized -O2 -g -std=3Dgnu99 \ -Wno-gnu-variable-sized-type-not-at-end -MD -MP -DCONFIG_64BIT \ - -D_GNU_SOURCE -fno-builtin-memcmp -fno-builtin-memcpy \ + -fno-builtin-memcmp -fno-builtin-memcpy \ -fno-builtin-memset -fno-builtin-strnlen \ -fno-stack-protector -fno-PIE -I$(LINUX_TOOL_INCLUDE) \ -I$(LINUX_TOOL_ARCH_INCLUDE) -I$(LINUX_HDR_PATH) -Iinclude \ diff --git a/tools/testing/selftests/lib.mk b/tools/testing/selftests/lib.mk index 7b299ed5ff45..d6edcfcb5be8 100644 --- a/tools/testing/selftests/lib.mk +++ b/tools/testing/selftests/lib.mk @@ -196,6 +196,9 @@ endef clean: $(if $(TEST_GEN_MODS_DIR),clean_mods_dir) $(CLEAN) =20 +# Build with _GNU_SOURCE by default +CFLAGS +=3D -D_GNU_SOURCE=3D + # Enables to extend CFLAGS and LDFLAGS from command line, e.g. # make USERCFLAGS=3D-Werror USERLDFLAGS=3D-static CFLAGS +=3D $(USERCFLAGS) diff --git a/tools/testing/selftests/mm/thuge-gen.c b/tools/testing/selftes= ts/mm/thuge-gen.c index d50dc71cac32..e4370b79b62f 100644 --- a/tools/testing/selftests/mm/thuge-gen.c +++ b/tools/testing/selftests/mm/thuge-gen.c @@ -13,7 +13,7 @@ sudo ipcs | awk '$1 =3D=3D "0x00000000" {print $2}' | xargs -n1 sudo ip= crm -m (warning this will remove all if someone else uses them) */ =20 -#define _GNU_SOURCE 1 +#define _GNU_SOURCE #include #include #include diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests= /net/Makefile index bc3925200637..8eaffd7a641c 100644 --- a/tools/testing/selftests/net/Makefile +++ b/tools/testing/selftests/net/Makefile @@ -1,7 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 # Makefile for net selftests =20 -CFLAGS =3D -Wall -Wl,--no-as-needed -O2 -g +CFLAGS +=3D -Wall -Wl,--no-as-needed -O2 -g CFLAGS +=3D -I../../../../usr/include/ $(KHDR_INCLUDES) # Additional include paths needed by kselftest.h CFLAGS +=3D -I../ diff --git a/tools/testing/selftests/net/tcp_ao/Makefile b/tools/testing/se= lftests/net/tcp_ao/Makefile index 522d991e310e..bd88b90b902b 100644 --- a/tools/testing/selftests/net/tcp_ao/Makefile +++ b/tools/testing/selftests/net/tcp_ao/Makefile @@ -26,7 +26,7 @@ LIB :=3D $(LIBDIR)/libaotst.a LDLIBS +=3D $(LIB) -pthread LIBDEPS :=3D lib/aolib.h Makefile =20 -CFLAGS :=3D -Wall -O2 -g -D_GNU_SOURCE -fno-strict-aliasing +CFLAGS +=3D -Wall -O2 -g -fno-strict-aliasing CFLAGS +=3D $(KHDR_INCLUDES) CFLAGS +=3D -iquote ./lib/ -I ../../../../include/ =20 diff --git a/tools/testing/selftests/proc/Makefile b/tools/testing/selftest= s/proc/Makefile index 6066f607f758..ee424a9f075f 100644 --- a/tools/testing/selftests/proc/Makefile +++ b/tools/testing/selftests/proc/Makefile @@ -1,6 +1,5 @@ # SPDX-License-Identifier: GPL-2.0-only CFLAGS +=3D -Wall -O2 -Wno-unused-function -CFLAGS +=3D -D_GNU_SOURCE LDFLAGS +=3D -pthread =20 TEST_GEN_PROGS :=3D diff --git a/tools/testing/selftests/resctrl/Makefile b/tools/testing/selft= ests/resctrl/Makefile index 021863f86053..f408bd6bfc3d 100644 --- a/tools/testing/selftests/resctrl/Makefile +++ b/tools/testing/selftests/resctrl/Makefile @@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 =20 -CFLAGS =3D -g -Wall -O2 -D_FORTIFY_SOURCE=3D2 -D_GNU_SOURCE +CFLAGS =3D -g -Wall -O2 -D_FORTIFY_SOURCE=3D2 CFLAGS +=3D $(KHDR_INCLUDES) =20 TEST_GEN_PROGS :=3D resctrl_tests diff --git a/tools/testing/selftests/ring-buffer/Makefile b/tools/testing/s= elftests/ring-buffer/Makefile index 627c5fa6d1ab..23605782639e 100644 --- a/tools/testing/selftests/ring-buffer/Makefile +++ b/tools/testing/selftests/ring-buffer/Makefile @@ -1,7 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 CFLAGS +=3D -Wl,-no-as-needed -Wall CFLAGS +=3D $(KHDR_INCLUDES) -CFLAGS +=3D -D_GNU_SOURCE =20 TEST_GEN_PROGS =3D map_test =20 diff --git a/tools/testing/selftests/riscv/mm/Makefile b/tools/testing/self= tests/riscv/mm/Makefile index c333263f2b27..4664ed79e20b 100644 --- a/tools/testing/selftests/riscv/mm/Makefile +++ b/tools/testing/selftests/riscv/mm/Makefile @@ -3,7 +3,7 @@ # Originally tools/testing/arm64/abi/Makefile =20 # Additional include paths needed by kselftest.h and local headers -CFLAGS +=3D -D_GNU_SOURCE -std=3Dgnu99 -I. +CFLAGS +=3D -std=3Dgnu99 -I. =20 TEST_GEN_FILES :=3D mmap_default mmap_bottomup =20 diff --git a/tools/testing/selftests/sgx/Makefile b/tools/testing/selftests= /sgx/Makefile index 867f88ce2570..03b5e13b872b 100644 --- a/tools/testing/selftests/sgx/Makefile +++ b/tools/testing/selftests/sgx/Makefile @@ -12,7 +12,7 @@ OBJCOPY :=3D $(CROSS_COMPILE)objcopy endif =20 INCLUDES :=3D -I$(top_srcdir)/tools/include -HOST_CFLAGS :=3D -Wall -Werror -g $(INCLUDES) -fPIC +HOST_CFLAGS :=3D -Wall -Werror -g $(INCLUDES) -fPIC $(CFLAGS) HOST_LDFLAGS :=3D -z noexecstack -lcrypto ENCL_CFLAGS +=3D -Wall -Werror -static-pie -nostdlib -ffreestanding -fPIE \ -fno-stack-protector -mrdrnd $(INCLUDES) diff --git a/tools/testing/selftests/tmpfs/Makefile b/tools/testing/selftes= ts/tmpfs/Makefile index aa11ccc92e5b..3be931e1193f 100644 --- a/tools/testing/selftests/tmpfs/Makefile +++ b/tools/testing/selftests/tmpfs/Makefile @@ -1,6 +1,5 @@ # SPDX-License-Identifier: GPL-2.0-only CFLAGS +=3D -Wall -O2 -CFLAGS +=3D -D_GNU_SOURCE =20 TEST_GEN_PROGS :=3D TEST_GEN_PROGS +=3D bug-link-o-tmpfile --=20 2.45.2.803.g4e1b14247a-goog