Commit 730cfa45 authored by Sean Christopherson's avatar Sean Christopherson
Browse files

KVM: selftests: Define _GNU_SOURCE for all selftests code



Define _GNU_SOURCE is the base CFLAGS instead of relying on selftests to
manually #define _GNU_SOURCE, which is repetitive and error prone.  E.g.
kselftest_harness.h requires _GNU_SOURCE for asprintf(), but if a selftest
includes kvm_test_harness.h after stdio.h, the include guards result in
the effective version of stdio.h consumed by kvm_test_harness.h not
defining asprintf():

  In file included from x86_64/fix_hypercall_test.c:12:
  In file included from include/kvm_test_harness.h:11:
 ../kselftest_harness.h:1169:2: error: call to undeclared function
  'asprintf'; ISO C99 and later do not support implicit function declarations
  [-Wimplicit-function-declaration]
   1169 |         asprintf(&test_name, "%s%s%s.%s", f->name,
        |         ^

When including the rseq selftest's "library" code, #undef _GNU_SOURCE so
that rseq.c controls whether or not it wants to build with _GNU_SOURCE.

Reported-by: default avatarMuhammad Usama Anjum <usama.anjum@collabora.com>
Acked-by: default avatarClaudio Imbrenda <imbrenda@linux.ibm.com>
Acked-by: default avatarOliver Upton <oliver.upton@linux.dev>
Acked-by: default avatarAnup Patel <anup@brainfault.org>
Reviewed-by: default avatarMuhammad Usama Anjum <usama.anjum@collabora.com>
Link: https://lore.kernel.org/r/20240423190308.2883084-1-seanjc@google.com


Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
parent a96cb3bf
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -226,8 +226,8 @@ LINUX_TOOL_ARCH_INCLUDE = $(top_srcdir)/tools/arch/$(ARCH)/include
endif
CFLAGS += -Wall -Wstrict-prototypes -Wuninitialized -O2 -g -std=gnu99 \
	-Wno-gnu-variable-sized-type-not-at-end -MD -MP -DCONFIG_64BIT \
	-fno-builtin-memcmp -fno-builtin-memcpy -fno-builtin-memset \
	-fno-builtin-strnlen \
	-D_GNU_SOURCE -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 \
	-I$(<D) -Iinclude/$(ARCH_DIR) -I ../rseq -I.. $(EXTRA_CFLAGS) \
+0 −2
Original line number Diff line number Diff line
@@ -5,8 +5,6 @@
 *
 * Copyright (c) 2021, Google LLC.
 */
#define _GNU_SOURCE

#include "arch_timer.h"
#include "delay.h"
#include "gic.h"
+0 −1
Original line number Diff line number Diff line
@@ -7,7 +7,6 @@
 * hugetlbfs with a hole). It checks that the expected handling method is
 * called (e.g., uffd faults with the right address and write/read flag).
 */
#define _GNU_SOURCE
#include <linux/bitmap.h>
#include <fcntl.h>
#include <test_util.h>
+0 −3
Original line number Diff line number Diff line
@@ -10,9 +10,6 @@
 *  - A test for KVM's handling of PSCI SYSTEM_SUSPEND and the associated
 *    KVM_SYSTEM_EVENT_SUSPEND UAPI.
 */

#define _GNU_SOURCE

#include <linux/psci.h>

#include "kvm_util.h"
+0 −1
Original line number Diff line number Diff line
@@ -4,7 +4,6 @@
 *
 * Copyright (C) 2020, Red Hat, Inc.
 */
#define _GNU_SOURCE
#include <linux/kernel.h>
#include <sys/syscall.h>
#include <asm/kvm.h>
Loading