Skip to content

Commit 730cfa4

Browse files
committed
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: Muhammad Usama Anjum <usama.anjum@collabora.com> Acked-by: Claudio Imbrenda <imbrenda@linux.ibm.com> Acked-by: Oliver Upton <oliver.upton@linux.dev> Acked-by: Anup Patel <anup@brainfault.org> Reviewed-by: Muhammad Usama Anjum <usama.anjum@collabora.com> Link: https://lore.kernel.org/r/20240423190308.2883084-1-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent a96cb3b commit 730cfa4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+17
-120
lines changed

tools/testing/selftests/kvm/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,8 @@ LINUX_TOOL_ARCH_INCLUDE = $(top_srcdir)/tools/arch/$(ARCH)/include
226226
endif
227227
CFLAGS += -Wall -Wstrict-prototypes -Wuninitialized -O2 -g -std=gnu99 \
228228
-Wno-gnu-variable-sized-type-not-at-end -MD -MP -DCONFIG_64BIT \
229-
-fno-builtin-memcmp -fno-builtin-memcpy -fno-builtin-memset \
230-
-fno-builtin-strnlen \
229+
-D_GNU_SOURCE -fno-builtin-memcmp -fno-builtin-memcpy \
230+
-fno-builtin-memset -fno-builtin-strnlen \
231231
-fno-stack-protector -fno-PIE -I$(LINUX_TOOL_INCLUDE) \
232232
-I$(LINUX_TOOL_ARCH_INCLUDE) -I$(LINUX_HDR_PATH) -Iinclude \
233233
-I$(<D) -Iinclude/$(ARCH_DIR) -I ../rseq -I.. $(EXTRA_CFLAGS) \

tools/testing/selftests/kvm/aarch64/arch_timer.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
*
66
* Copyright (c) 2021, Google LLC.
77
*/
8-
#define _GNU_SOURCE
9-
108
#include "arch_timer.h"
119
#include "delay.h"
1210
#include "gic.h"

tools/testing/selftests/kvm/aarch64/page_fault_test.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
* hugetlbfs with a hole). It checks that the expected handling method is
88
* called (e.g., uffd faults with the right address and write/read flag).
99
*/
10-
#define _GNU_SOURCE
1110
#include <linux/bitmap.h>
1211
#include <fcntl.h>
1312
#include <test_util.h>

tools/testing/selftests/kvm/aarch64/psci_test.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
* - A test for KVM's handling of PSCI SYSTEM_SUSPEND and the associated
1111
* KVM_SYSTEM_EVENT_SUSPEND UAPI.
1212
*/
13-
14-
#define _GNU_SOURCE
15-
1613
#include <linux/psci.h>
1714

1815
#include "kvm_util.h"

tools/testing/selftests/kvm/aarch64/vgic_init.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*
55
* Copyright (C) 2020, Red Hat, Inc.
66
*/
7-
#define _GNU_SOURCE
87
#include <linux/kernel.h>
98
#include <sys/syscall.h>
109
#include <asm/kvm.h>

tools/testing/selftests/kvm/arch_timer.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
*
2020
* Copyright (c) 2021, Google LLC.
2121
*/
22-
23-
#define _GNU_SOURCE
24-
2522
#include <stdlib.h>
2623
#include <pthread.h>
2724
#include <linux/sizes.h>

tools/testing/selftests/kvm/demand_paging_test.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
* Copyright (C) 2018, Red Hat, Inc.
77
* Copyright (C) 2019, Google, Inc.
88
*/
9-
10-
#define _GNU_SOURCE /* for pipe2 */
11-
129
#include <inttypes.h>
1310
#include <stdio.h>
1411
#include <stdlib.h>

tools/testing/selftests/kvm/dirty_log_test.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
*
55
* Copyright (C) 2018, Red Hat, Inc.
66
*/
7-
8-
#define _GNU_SOURCE /* for program_invocation_name */
9-
107
#include <stdio.h>
118
#include <stdlib.h>
129
#include <pthread.h>

tools/testing/selftests/kvm/guest_memfd_test.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
*
55
* Author: Chao Peng <chao.p.peng@linux.intel.com>
66
*/
7-
8-
#define _GNU_SOURCE
97
#include <stdlib.h>
108
#include <string.h>
119
#include <unistd.h>

tools/testing/selftests/kvm/hardware_disable_test.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
* kvm_arch_hardware_disable is called and it attempts to unregister the user
55
* return notifiers.
66
*/
7-
8-
#define _GNU_SOURCE
9-
107
#include <fcntl.h>
118
#include <pthread.h>
129
#include <semaphore.h>

0 commit comments

Comments
 (0)