2024-04-30 23:51:42

by Edward Liaw

[permalink] [raw]
Subject: [PATCH v1 00/10] Define _GNU_SOURCE for sources using

809216233555 ("selftests/harness: remove use of LINE_MAX") introduced
asprintf into kselftest_harness.h, which is a GNU extension and needs
_GNU_SOURCE to either be defined prior to including headers or with the
-D_GNU_SOURCE flag passed to the compiler.

Edward Liaw (10):
selftests/sgx: Compile with -D_GNU_SOURCE
selftests/alsa: Compile with -D_GNU_SOURCE
selftests/hid: Compile with -D_GNU_SOURCE
selftests/kvm: Define _GNU_SOURCE
selftests/nci: Compile with -D_GNU_SOURCE
selftests/net: Define _GNU_SOURCE
selftests/prctl: Compile with -D_GNU_SOURCE
selftests/rtc: Compile with -D_GNU_SOURCE
selftests/tdx: Compile with -D_GNU_SOURCE
selftests/user_events: Compiled with -D_GNU_SOURCE

tools/testing/selftests/alsa/Makefile | 1 +
tools/testing/selftests/hid/Makefile | 2 +-
tools/testing/selftests/kvm/x86_64/fix_hypercall_test.c | 2 ++
tools/testing/selftests/nci/Makefile | 2 +-
tools/testing/selftests/net/bind_wildcard.c | 1 +
tools/testing/selftests/net/ip_local_port_range.c | 1 +
tools/testing/selftests/net/reuseaddr_ports_exhausted.c | 2 ++
tools/testing/selftests/prctl/Makefile | 1 +
tools/testing/selftests/rtc/Makefile | 2 +-
tools/testing/selftests/sgx/Makefile | 2 +-
tools/testing/selftests/sgx/sigstruct.c | 2 --
tools/testing/selftests/tdx/Makefile | 2 +-
tools/testing/selftests/user_events/Makefile | 2 +-
tools/testing/selftests/user_events/abi_test.c | 1 -
14 files changed, 14 insertions(+), 9 deletions(-)

--
2.45.0.rc0.197.gbae5840b3b-goog



2024-04-30 23:52:18

by Edward Liaw

[permalink] [raw]
Subject: [PATCH v1 01/10] selftests/sgx: Compile with -D_GNU_SOURCE

809216233555 ("selftests/harness: remove use of LINE_MAX") introduced
asprintf into kselftest_harness.h, which is a GNU extension and needs
_GNU_SOURCE to either be defined prior to including headers or with the
-D_GNU_SOURCE flag passed to the compiler.

Fixes: 809216233555 ("selftests/harness: remove use of LINE_MAX")
Reported-by: kernel test robot <[email protected]>
Closes: https://lore.kernel.org/oe-lkp/[email protected]
Signed-off-by: Edward Liaw <[email protected]>
---
tools/testing/selftests/sgx/Makefile | 2 +-
tools/testing/selftests/sgx/sigstruct.c | 2 --
2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/tools/testing/selftests/sgx/Makefile b/tools/testing/selftests/sgx/Makefile
index 867f88ce2570..272da790d9ae 100644
--- a/tools/testing/selftests/sgx/Makefile
+++ b/tools/testing/selftests/sgx/Makefile
@@ -12,7 +12,7 @@ OBJCOPY := $(CROSS_COMPILE)objcopy
endif

INCLUDES := -I$(top_srcdir)/tools/include
-HOST_CFLAGS := -Wall -Werror -g $(INCLUDES) -fPIC
+HOST_CFLAGS := -Wall -Werror -g $(INCLUDES) -fPIC -D_GNU_SOURCE
HOST_LDFLAGS := -z noexecstack -lcrypto
ENCL_CFLAGS += -Wall -Werror -static-pie -nostdlib -ffreestanding -fPIE \
-fno-stack-protector -mrdrnd $(INCLUDES)
diff --git a/tools/testing/selftests/sgx/sigstruct.c b/tools/testing/selftests/sgx/sigstruct.c
index d73b29becf5b..a0c2de7c5302 100644
--- a/tools/testing/selftests/sgx/sigstruct.c
+++ b/tools/testing/selftests/sgx/sigstruct.c
@@ -1,7 +1,5 @@
// SPDX-License-Identifier: GPL-2.0
/* Copyright(c) 2016-20 Intel Corporation. */
-
-#define _GNU_SOURCE
#include <assert.h>
#include <getopt.h>
#include <stdbool.h>
--
2.45.0.rc0.197.gbae5840b3b-goog


2024-04-30 23:53:24

by Edward Liaw

[permalink] [raw]
Subject: [PATCH v1 03/10] selftests/hid: Compile with -D_GNU_SOURCE

809216233555 ("selftests/harness: remove use of LINE_MAX") introduced
asprintf into kselftest_harness.h, which is a GNU extension and needs
_GNU_SOURCE to either be defined prior to including headers or with the
-D_GNU_SOURCE flag passed to the compiler.

Fixes: 809216233555 ("selftests/harness: remove use of LINE_MAX")
Signed-off-by: Edward Liaw <[email protected]>
---
tools/testing/selftests/hid/Makefile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/hid/Makefile b/tools/testing/selftests/hid/Makefile
index 2b5ea18bde38..33170d23315b 100644
--- a/tools/testing/selftests/hid/Makefile
+++ b/tools/testing/selftests/hid/Makefile
@@ -21,7 +21,7 @@ CXX ?= $(CROSS_COMPILE)g++

HOSTPKG_CONFIG := pkg-config

-CFLAGS += -g -O0 -rdynamic -Wall -Werror -I$(OUTPUT)
+CFLAGS += -g -O0 -rdynamic -Wall -Werror -D_GNU_SOURCE -I$(OUTPUT)
CFLAGS += -I$(OUTPUT)/tools/include

LDLIBS += -lelf -lz -lrt -lpthread
--
2.45.0.rc0.197.gbae5840b3b-goog


2024-04-30 23:53:52

by Edward Liaw

[permalink] [raw]
Subject: [PATCH v1 04/10] selftests/kvm: Define _GNU_SOURCE

809216233555 ("selftests/harness: remove use of LINE_MAX") introduced
asprintf into kselftest_harness.h, which is a GNU extension and needs
_GNU_SOURCE to either be defined prior to including headers or with the
-D_GNU_SOURCE flag passed to the compiler.

Fixes: 809216233555 ("selftests/harness: remove use of LINE_MAX")
Signed-off-by: Edward Liaw <[email protected]>
---
tools/testing/selftests/kvm/x86_64/fix_hypercall_test.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/tools/testing/selftests/kvm/x86_64/fix_hypercall_test.c b/tools/testing/selftests/kvm/x86_64/fix_hypercall_test.c
index f3c2239228b1..7422e8ff6bd3 100644
--- a/tools/testing/selftests/kvm/x86_64/fix_hypercall_test.c
+++ b/tools/testing/selftests/kvm/x86_64/fix_hypercall_test.c
@@ -4,6 +4,8 @@
*
* Tests for KVM paravirtual feature disablement
*/
+#define _GNU_SOURCE
+
#include <asm/kvm_para.h>
#include <linux/kvm_para.h>
#include <linux/stringify.h>
--
2.45.0.rc0.197.gbae5840b3b-goog


2024-04-30 23:54:57

by Edward Liaw

[permalink] [raw]
Subject: [PATCH v1 06/10] selftests/net: Define _GNU_SOURCE

809216233555 ("selftests/harness: remove use of LINE_MAX") introduced
asprintf into kselftest_harness.h, which is a GNU extension and needs
_GNU_SOURCE to either be defined prior to including headers or with the
-D_GNU_SOURCE flag passed to the compiler.

Fixes: 809216233555 ("selftests/harness: remove use of LINE_MAX")
Signed-off-by: Edward Liaw <[email protected]>
---
tools/testing/selftests/net/bind_wildcard.c | 1 +
tools/testing/selftests/net/ip_local_port_range.c | 1 +
tools/testing/selftests/net/reuseaddr_ports_exhausted.c | 2 ++
3 files changed, 4 insertions(+)

diff --git a/tools/testing/selftests/net/bind_wildcard.c b/tools/testing/selftests/net/bind_wildcard.c
index b7b54d646b93..be0773cbc15b 100644
--- a/tools/testing/selftests/net/bind_wildcard.c
+++ b/tools/testing/selftests/net/bind_wildcard.c
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: GPL-2.0
/* Copyright Amazon.com Inc. or its affiliates. */
+#define _GNU_SOURCE

#include <sys/socket.h>
#include <netinet/in.h>
diff --git a/tools/testing/selftests/net/ip_local_port_range.c b/tools/testing/selftests/net/ip_local_port_range.c
index 193b82745fd8..08fbd3449ffa 100644
--- a/tools/testing/selftests/net/ip_local_port_range.c
+++ b/tools/testing/selftests/net/ip_local_port_range.c
@@ -6,6 +6,7 @@
* Tests assume that net.ipv4.ip_local_port_range is [40000, 49999].
* Don't run these directly but with ip_local_port_range.sh script.
*/
+#define _GNU_SOURCE

#include <fcntl.h>
#include <netinet/ip.h>
diff --git a/tools/testing/selftests/net/reuseaddr_ports_exhausted.c b/tools/testing/selftests/net/reuseaddr_ports_exhausted.c
index 066efd30e294..a5c40528837f 100644
--- a/tools/testing/selftests/net/reuseaddr_ports_exhausted.c
+++ b/tools/testing/selftests/net/reuseaddr_ports_exhausted.c
@@ -17,6 +17,8 @@
*
* Author: Kuniyuki Iwashima <[email protected]>
*/
+#define _GNU_SOURCE
+
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/socket.h>
--
2.45.0.rc0.197.gbae5840b3b-goog


2024-04-30 23:56:41

by Edward Liaw

[permalink] [raw]
Subject: [PATCH v1 09/10] selftests/tdx: Compile with -D_GNU_SOURCE

809216233555 ("selftests/harness: remove use of LINE_MAX") introduced
asprintf into kselftest_harness.h, which is a GNU extension and needs
_GNU_SOURCE to either be defined prior to including headers or with the
-D_GNU_SOURCE flag passed to the compiler.

Fixes: 809216233555 ("selftests/harness: remove use of LINE_MAX")
Signed-off-by: Edward Liaw <[email protected]>
---
tools/testing/selftests/tdx/Makefile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/tdx/Makefile b/tools/testing/selftests/tdx/Makefile
index 306e9c4d5ef7..5a084a792a21 100644
--- a/tools/testing/selftests/tdx/Makefile
+++ b/tools/testing/selftests/tdx/Makefile
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: GPL-2.0

-CFLAGS += -O3 -Wl,-no-as-needed -Wall $(KHDR_INCLUDES) -static
+CFLAGS += -O3 -Wl,-no-as-needed -Wall -D_GNU_SOURCE $(KHDR_INCLUDES) -static

TEST_GEN_PROGS := tdx_guest_test

--
2.45.0.rc0.197.gbae5840b3b-goog


2024-04-30 23:58:33

by Edward Liaw

[permalink] [raw]
Subject: [PATCH v1 08/10] selftests/rtc: Compile with -D_GNU_SOURCE

809216233555 ("selftests/harness: remove use of LINE_MAX") introduced
asprintf into kselftest_harness.h, which is a GNU extension and needs
_GNU_SOURCE to either be defined prior to including headers or with the
-D_GNU_SOURCE flag passed to the compiler.

Fixes: 809216233555 ("selftests/harness: remove use of LINE_MAX")
Signed-off-by: Edward Liaw <[email protected]>
---
tools/testing/selftests/rtc/Makefile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/rtc/Makefile b/tools/testing/selftests/rtc/Makefile
index 55198ecc04db..4ef7ee969003 100644
--- a/tools/testing/selftests/rtc/Makefile
+++ b/tools/testing/selftests/rtc/Makefile
@@ -1,5 +1,5 @@
# SPDX-License-Identifier: GPL-2.0
-CFLAGS += -O3 -Wl,-no-as-needed -Wall
+CFLAGS += -O3 -Wl,-no-as-needed -Wall -D_GNU_SOURCE
LDLIBS += -lrt -lpthread -lm

TEST_GEN_PROGS = rtctest
--
2.45.0.rc0.197.gbae5840b3b-goog


2024-05-01 00:04:08

by Edward Liaw

[permalink] [raw]
Subject: [PATCH v1 05/10] selftests/nci: Compile with -D_GNU_SOURCE

809216233555 ("selftests/harness: remove use of LINE_MAX") introduced
asprintf into kselftest_harness.h, which is a GNU extension and needs
_GNU_SOURCE to either be defined prior to including headers or with the
-D_GNU_SOURCE flag passed to the compiler.

Fixes: 809216233555 ("selftests/harness: remove use of LINE_MAX")
Signed-off-by: Edward Liaw <[email protected]>
---
tools/testing/selftests/nci/Makefile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/nci/Makefile b/tools/testing/selftests/nci/Makefile
index 47669a1d6a59..f615f5d71f7f 100644
--- a/tools/testing/selftests/nci/Makefile
+++ b/tools/testing/selftests/nci/Makefile
@@ -1,5 +1,5 @@
# SPDX-License-Identifier: GPL-2.0
-CFLAGS += -Wl,-no-as-needed -Wall
+CFLAGS += -Wl,-no-as-needed -Wall -D_GNU_SOURCE
LDFLAGS += -lpthread

TEST_GEN_PROGS := nci_dev
--
2.45.0.rc0.197.gbae5840b3b-goog


2024-05-01 00:04:40

by Edward Liaw

[permalink] [raw]
Subject: [PATCH v1 07/10] selftests/prctl: Compile with -D_GNU_SOURCE

809216233555 ("selftests/harness: remove use of LINE_MAX") introduced
asprintf into kselftest_harness.h, which is a GNU extension and needs
_GNU_SOURCE to either be defined prior to including headers or with the
-D_GNU_SOURCE flag passed to the compiler.

Fixes: 809216233555 ("selftests/harness: remove use of LINE_MAX")
Signed-off-by: Edward Liaw <[email protected]>
---
tools/testing/selftests/prctl/Makefile | 1 +
1 file changed, 1 insertion(+)

diff --git a/tools/testing/selftests/prctl/Makefile b/tools/testing/selftests/prctl/Makefile
index 01dc90fbb509..23d319a7a322 100644
--- a/tools/testing/selftests/prctl/Makefile
+++ b/tools/testing/selftests/prctl/Makefile
@@ -1,4 +1,5 @@
# SPDX-License-Identifier: GPL-2.0
+CFLAGS += -D_GNU_SOURCE
ifndef CROSS_COMPILE
uname_M := $(shell uname -m 2>/dev/null || echo not)
ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/x86/ -e s/x86_64/x86/)
--
2.45.0.rc0.197.gbae5840b3b-goog


2024-05-01 00:04:45

by Edward Liaw

[permalink] [raw]
Subject: [PATCH v1 02/10] selftests/alsa: Compile with -D_GNU_SOURCE

809216233555 ("selftests/harness: remove use of LINE_MAX") introduced
asprintf into kselftest_harness.h, which is a GNU extension and needs
_GNU_SOURCE to either be defined prior to including headers or with the
-D_GNU_SOURCE flag passed to the compiler.

Fixes: 809216233555 ("selftests/harness: remove use of LINE_MAX")
Signed-off-by: Edward Liaw <[email protected]>
---
tools/testing/selftests/alsa/Makefile | 1 +
1 file changed, 1 insertion(+)

diff --git a/tools/testing/selftests/alsa/Makefile b/tools/testing/selftests/alsa/Makefile
index 5af9ba8a4645..3a0fae2bea39 100644
--- a/tools/testing/selftests/alsa/Makefile
+++ b/tools/testing/selftests/alsa/Makefile
@@ -6,6 +6,7 @@ LDLIBS += $(shell pkg-config --libs alsa)
ifeq ($(LDLIBS),)
LDLIBS += -lasound
endif
+CFLAGS += -D_GNU_SOURCE
CFLAGS += -L$(OUTPUT) -Wl,-rpath=./

LDLIBS+=-lpthread
--
2.45.0.rc0.197.gbae5840b3b-goog


2024-05-01 00:07:17

by Edward Liaw

[permalink] [raw]
Subject: [PATCH v1 10/10] selftests/user_events: Compiled with -D_GNU_SOURCE

809216233555 ("selftests/harness: remove use of LINE_MAX") introduced
asprintf into kselftest_harness.h, which is a GNU extension and needs
_GNU_SOURCE to either be defined prior to including headers or with the
-D_GNU_SOURCE flag passed to the compiler.

Fixes: 809216233555 ("selftests/harness: remove use of LINE_MAX")
Signed-off-by: Edward Liaw <[email protected]>
---
tools/testing/selftests/user_events/Makefile | 2 +-
tools/testing/selftests/user_events/abi_test.c | 1 -
2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/tools/testing/selftests/user_events/Makefile b/tools/testing/selftests/user_events/Makefile
index 10fcd0066203..344a71769113 100644
--- a/tools/testing/selftests/user_events/Makefile
+++ b/tools/testing/selftests/user_events/Makefile
@@ -1,5 +1,5 @@
# SPDX-License-Identifier: GPL-2.0
-CFLAGS += -Wl,-no-as-needed -Wall $(KHDR_INCLUDES)
+CFLAGS += -Wl,-no-as-needed -Wall -D_GNU_SOURCE $(KHDR_INCLUDES)
LDLIBS += -lrt -lpthread -lm

TEST_GEN_PROGS = ftrace_test dyn_test perf_test abi_test
diff --git a/tools/testing/selftests/user_events/abi_test.c b/tools/testing/selftests/user_events/abi_test.c
index 7288a05136ba..3e3a0327afdc 100644
--- a/tools/testing/selftests/user_events/abi_test.c
+++ b/tools/testing/selftests/user_events/abi_test.c
@@ -5,7 +5,6 @@
* Copyright (c) 2022 Beau Belgrave <[email protected]>
*/

-#define _GNU_SOURCE
#include <sched.h>

#include <errno.h>
--
2.45.0.rc0.197.gbae5840b3b-goog


2024-05-01 02:00:18

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH v1 00/10] Define _GNU_SOURCE for sources using

On Tue, Apr 30, 2024 at 11:50:09PM +0000, Edward Liaw wrote:
> 809216233555 ("selftests/harness: remove use of LINE_MAX") introduced
> asprintf into kselftest_harness.h, which is a GNU extension and needs
> _GNU_SOURCE to either be defined prior to including headers or with the
> -D_GNU_SOURCE flag passed to the compiler.

This seems like something that should be handled centrally rather than
having to go round and audit the users every time some update is made.


Attachments:
(No filename) (475.00 B)
signature.asc (499.00 B)
Download all attachments

2024-05-01 05:41:43

by Muhammad Usama Anjum

[permalink] [raw]
Subject: Re: [PATCH v1 00/10] Define _GNU_SOURCE for sources using

Thanks for the fixes.

On 5/1/24 6:59 AM, Mark Brown wrote:
> On Tue, Apr 30, 2024 at 11:50:09PM +0000, Edward Liaw wrote:
>> 809216233555 ("selftests/harness: remove use of LINE_MAX") introduced
>> asprintf into kselftest_harness.h, which is a GNU extension and needs
>> _GNU_SOURCE to either be defined prior to including headers or with the
>> -D_GNU_SOURCE flag passed to the compiler.
>
> This seems like something that should be handled centrally rather than
> having to go round and audit the users every time some update is made.
The easiest way I could think of is to add -D_GNU_SOURCE to KHDR_HEADERS
definition in tools/testing/selftests/Makefile. It wouldn't be obvious from
KHDR_HEADERS name that there could be other flags in it as well though.


--
BR,
Muhammad Usama Anjum

2024-05-01 13:24:58

by Sean Christopherson

[permalink] [raw]
Subject: Re: [PATCH v1 00/10] Define _GNU_SOURCE for sources using

On Wed, May 01, 2024, Mark Brown wrote:
> On Tue, Apr 30, 2024 at 11:50:09PM +0000, Edward Liaw wrote:
> > 809216233555 ("selftests/harness: remove use of LINE_MAX") introduced
> > asprintf into kselftest_harness.h, which is a GNU extension and needs
> > _GNU_SOURCE to either be defined prior to including headers or with the
> > -D_GNU_SOURCE flag passed to the compiler.
>
> This seems like something that should be handled centrally rather than
> having to go round and audit the users every time some update is made.

+1.

And if for some reason unilaterally defining _GNU_SOURCE in
tools/testing/selftests/lib.mk isn't an option, we should at least have
kselftest_harness.h assert instead of making a futile attempt to provide its own
definition, e.g.

diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h
index 4fd735e48ee7..6741b4f20f25 100644
--- a/tools/testing/selftests/kselftest_harness.h
+++ b/tools/testing/selftests/kselftest_harness.h
@@ -51,7 +51,7 @@
#define __KSELFTEST_HARNESS_H

#ifndef _GNU_SOURCE
-#define _GNU_SOURCE
+static_assert(0, "Using the kselftests harness requires building with _GNU_SOURCE");
#endif
#include <asm/types.h>
#include <ctype.h>

2024-05-01 13:27:18

by Sean Christopherson

[permalink] [raw]
Subject: Re: [PATCH v1 04/10] selftests/kvm: Define _GNU_SOURCE

On Tue, Apr 30, 2024, Edward Liaw wrote:
> 809216233555 ("selftests/harness: remove use of LINE_MAX") introduced
> asprintf into kselftest_harness.h, which is a GNU extension and needs
> _GNU_SOURCE to either be defined prior to including headers or with the
> -D_GNU_SOURCE flag passed to the compiler.
>
> Fixes: 809216233555 ("selftests/harness: remove use of LINE_MAX")
> Signed-off-by: Edward Liaw <[email protected]>
> ---
> tools/testing/selftests/kvm/x86_64/fix_hypercall_test.c | 2 ++
> 1 file changed, 2 insertions(+)

Regardless of where this series ends up going, this patch can be dropped as I
already have a fix applied for all KVM selftests[*].

Thanks!

[*] https://lore.kernel.org/all/[email protected]

2024-05-02 22:41:18

by Kees Cook

[permalink] [raw]
Subject: Re: [PATCH v1 00/10] Define _GNU_SOURCE for sources using

On Wed, May 01, 2024 at 06:24:36AM -0700, Sean Christopherson wrote:
> On Wed, May 01, 2024, Mark Brown wrote:
> > On Tue, Apr 30, 2024 at 11:50:09PM +0000, Edward Liaw wrote:
> > > 809216233555 ("selftests/harness: remove use of LINE_MAX") introduced
> > > asprintf into kselftest_harness.h, which is a GNU extension and needs
> > > _GNU_SOURCE to either be defined prior to including headers or with the
> > > -D_GNU_SOURCE flag passed to the compiler.
> >
> > This seems like something that should be handled centrally rather than
> > having to go round and audit the users every time some update is made.
>
> +1.
>
> And if for some reason unilaterally defining _GNU_SOURCE in
> tools/testing/selftests/lib.mk isn't an option, we should at least have
> kselftest_harness.h assert instead of making a futile attempt to provide its own
> definition, e.g.
>
> diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h
> index 4fd735e48ee7..6741b4f20f25 100644
> --- a/tools/testing/selftests/kselftest_harness.h
> +++ b/tools/testing/selftests/kselftest_harness.h
> @@ -51,7 +51,7 @@
> #define __KSELFTEST_HARNESS_H
>
> #ifndef _GNU_SOURCE
> -#define _GNU_SOURCE
> +static_assert(0, "Using the kselftests harness requires building with _GNU_SOURCE");
> #endif
> #include <asm/types.h>
> #include <ctype.h>

Yeah, let's fix centrally. I like this approach.

--
Kees Cook

2024-05-03 01:47:06

by Jarkko Sakkinen

[permalink] [raw]
Subject: Re: [PATCH v1 01/10] selftests/sgx: Compile with -D_GNU_SOURCE

On Wed May 1, 2024 at 2:50 AM EEST, Edward Liaw wrote:
> 809216233555 ("selftests/harness: remove use of LINE_MAX") introduced
> asprintf into kselftest_harness.h, which is a GNU extension and needs
> _GNU_SOURCE to either be defined prior to including headers or with the
> -D_GNU_SOURCE flag passed to the compiler.
>
> Fixes: 809216233555 ("selftests/harness: remove use of LINE_MAX")
> Reported-by: kernel test robot <[email protected]>
> Closes: https://lore.kernel.org/oe-lkp/[email protected]
> Signed-off-by: Edward Liaw <[email protected]>
> ---
> tools/testing/selftests/sgx/Makefile | 2 +-
> tools/testing/selftests/sgx/sigstruct.c | 2 --
> 2 files changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/tools/testing/selftests/sgx/Makefile b/tools/testing/selftests/sgx/Makefile
> index 867f88ce2570..272da790d9ae 100644
> --- a/tools/testing/selftests/sgx/Makefile
> +++ b/tools/testing/selftests/sgx/Makefile
> @@ -12,7 +12,7 @@ OBJCOPY := $(CROSS_COMPILE)objcopy
> endif
>
> INCLUDES := -I$(top_srcdir)/tools/include
> -HOST_CFLAGS := -Wall -Werror -g $(INCLUDES) -fPIC
> +HOST_CFLAGS := -Wall -Werror -g $(INCLUDES) -fPIC -D_GNU_SOURCE
> HOST_LDFLAGS := -z noexecstack -lcrypto
> ENCL_CFLAGS += -Wall -Werror -static-pie -nostdlib -ffreestanding -fPIE \
> -fno-stack-protector -mrdrnd $(INCLUDES)
> diff --git a/tools/testing/selftests/sgx/sigstruct.c b/tools/testing/selftests/sgx/sigstruct.c
> index d73b29becf5b..a0c2de7c5302 100644
> --- a/tools/testing/selftests/sgx/sigstruct.c
> +++ b/tools/testing/selftests/sgx/sigstruct.c
> @@ -1,7 +1,5 @@
> // SPDX-License-Identifier: GPL-2.0
> /* Copyright(c) 2016-20 Intel Corporation. */
> -
> -#define _GNU_SOURCE
> #include <assert.h>
> #include <getopt.h>
> #include <stdbool.h>
> --
> 2.45.0.rc0.197.gbae5840b3b-goog

Reviewed-by: Jarkko Sakkinen <[email protected]>

BR, Jarkko

2024-05-07 17:54:15

by Edward Liaw

[permalink] [raw]
Subject: Re: [PATCH v1 00/10] Define _GNU_SOURCE for sources using

On Tue, Apr 30, 2024 at 10:41 PM Muhammad Usama Anjum
<[email protected]> wrote:
>
> Thanks for the fixes.
>
> On 5/1/24 6:59 AM, Mark Brown wrote:
> > On Tue, Apr 30, 2024 at 11:50:09PM +0000, Edward Liaw wrote:
> >> 809216233555 ("selftests/harness: remove use of LINE_MAX") introduced
> >> asprintf into kselftest_harness.h, which is a GNU extension and needs
> >> _GNU_SOURCE to either be defined prior to including headers or with the
> >> -D_GNU_SOURCE flag passed to the compiler.
> >
> > This seems like something that should be handled centrally rather than
> > having to go round and audit the users every time some update is made.
> The easiest way I could think of is to add -D_GNU_SOURCE to KHDR_HEADERS
> definition in tools/testing/selftests/Makefile. It wouldn't be obvious from
> KHDR_HEADERS name that there could be other flags in it as well though.

I'll try this approach and see. It looks like there are also some
Makefiles that don't currently include KHDR_INCLUDES.

Also, this will cause _GNU_SOURCE redefined warnings wherever #define
_GNU_SOURCE is present. Should I also delete them or wrap them with
#ifndef?

>
>
> --
> BR,
> Muhammad Usama Anjum