public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH] openat2: Move includes to lapi, remove _GNU_SOURCE
@ 2026-02-04 12:43 Petr Vorel
  2026-02-05  6:08 ` Li Wang via ltp
  0 siblings, 1 reply; 6+ messages in thread
From: Petr Vorel @ 2026-02-04 12:43 UTC (permalink / raw)
  To: ltp

Improve 767b3e519e. struct open_how is also used in lapi/openat2.h,
which is used by all openat2*.c tests.  Therefore move <fcntl.h> to the
lapi header (and use lapi/fcntl.h instead).

Also remove _GNU_SOURCE which should not be needed.

While at it, move include "config.h" to the top.

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
Hi Li,

my points from the original patchset why not use _GNU_SOURCE:

glibc test tst-openat2.c [1] which includes <fcntl.h>, uses struct
open_how and test openat2() does not define it. Neither openat2() nor
struct open_how [2] are guarded by #ifdef __USE_GNU.

O_DIRECTORY is guarded by #ifdef __USE_XOPEN2K8 but this should be safe as we
compile with -std=gnu99.

Kind regards,
Petr

[1] https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/tst-openat2.c
[2] https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/bits/openat2.h

 include/lapi/openat2.h                        | 4 ++--
 testcases/kernel/syscalls/openat2/openat201.c | 3 ---
 testcases/kernel/syscalls/openat2/openat202.c | 3 ---
 testcases/kernel/syscalls/openat2/openat203.c | 3 ---
 4 files changed, 2 insertions(+), 11 deletions(-)

diff --git a/include/lapi/openat2.h b/include/lapi/openat2.h
index 03327bdb77..b7e7eadb94 100644
--- a/include/lapi/openat2.h
+++ b/include/lapi/openat2.h
@@ -7,12 +7,12 @@
 #ifndef LAPI_OPENAT2_H__
 #define LAPI_OPENAT2_H__
 
+#include "config.h"
 #include <sys/syscall.h>
 #include <linux/types.h>
 
 #include "lapi/syscalls.h"
-
-#include "config.h"
+#include "lapi/fcntl.h"
 
 #ifndef HAVE_OPENAT2
 /*
diff --git a/testcases/kernel/syscalls/openat2/openat201.c b/testcases/kernel/syscalls/openat2/openat201.c
index f4c80bde7b..7cee58930f 100644
--- a/testcases/kernel/syscalls/openat2/openat201.c
+++ b/testcases/kernel/syscalls/openat2/openat201.c
@@ -7,9 +7,6 @@
  * Basic :manpage:`openat2(2)` test.
  */
 
-#define _GNU_SOURCE
-#include <fcntl.h>
-
 #include "tst_test.h"
 #include "lapi/openat2.h"
 
diff --git a/testcases/kernel/syscalls/openat2/openat202.c b/testcases/kernel/syscalls/openat2/openat202.c
index 7fa047da67..d0e8fe3b6e 100644
--- a/testcases/kernel/syscalls/openat2/openat202.c
+++ b/testcases/kernel/syscalls/openat2/openat202.c
@@ -7,9 +7,6 @@
  * :manpage:`openat2(2)` tests with various resolve flags.
  */
 
-#define _GNU_SOURCE
-#include <fcntl.h>
-
 #include "tst_test.h"
 #include "lapi/openat2.h"
 
diff --git a/testcases/kernel/syscalls/openat2/openat203.c b/testcases/kernel/syscalls/openat2/openat203.c
index 904194334b..9695faa337 100644
--- a/testcases/kernel/syscalls/openat2/openat203.c
+++ b/testcases/kernel/syscalls/openat2/openat203.c
@@ -7,9 +7,6 @@
  * Basic :manpage:`openat2(2)` test to check various failures.
  */
 
-#define _GNU_SOURCE
-#include <fcntl.h>
-
 #include "tst_test.h"
 #include "lapi/openat2.h"
 
-- 
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [LTP] [PATCH] openat2: Move includes to lapi, remove _GNU_SOURCE
  2026-02-04 12:43 [LTP] [PATCH] openat2: Move includes to lapi, remove _GNU_SOURCE Petr Vorel
@ 2026-02-05  6:08 ` Li Wang via ltp
  2026-02-05  9:41   ` Li Wang via ltp
  2026-02-05  9:44   ` Petr Vorel
  0 siblings, 2 replies; 6+ messages in thread
From: Li Wang via ltp @ 2026-02-05  6:08 UTC (permalink / raw)
  To: Petr Vorel; +Cc: ltp

On Wed, Feb 04, 2026 at 01:43:23PM +0100, Petr Vorel wrote:
> Improve 767b3e519e. struct open_how is also used in lapi/openat2.h,
> which is used by all openat2*.c tests.  Therefore move <fcntl.h> to the
> lapi header (and use lapi/fcntl.h instead).
> 
> Also remove _GNU_SOURCE which should not be needed.
> 
> While at it, move include "config.h" to the top.
> 
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
> Hi Li,
> 
> my points from the original patchset why not use _GNU_SOURCE:
> 
> glibc test tst-openat2.c [1] which includes <fcntl.h>, uses struct

Interesting, I haven't figure out why it can be built within glibc itself.

> open_how and test openat2() does not define it. Neither openat2() nor
> struct open_how [2] are guarded by #ifdef __USE_GNU.
>  
> O_DIRECTORY is guarded by #ifdef __USE_XOPEN2K8 but this should be safe as we
> compile with -std=gnu99.

In glibc-2.43, things have changed, only define __USE_GNU can contain the
<bits/openat2.h> header file, that's why after applying this patch still
fails to complie on Fedora-Rawhide.

<fcntl.h> -> <bits/fcntl.h> -> <bits/fcntl-linux.h> -> <bits/openat2.h>

 # cat bits/fcntl-linux.h

 396 #ifdef __USE_GNU
     ...
 473 #include <bits/openat2.h>
  
 489 #endif	/* use GNU */

See: https://github.com/bminor/glibc/commit/0f0a5cd338998f4b603f52f3ce2163df0db7b814#diff-a4fc1e1b56b60a2598e320a232e6f631d08e0dafcfe3dd9607dde4bc8ee31eb8R473

-- 
Regards,
Li Wang


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [LTP] [PATCH] openat2: Move includes to lapi, remove _GNU_SOURCE
  2026-02-05  6:08 ` Li Wang via ltp
@ 2026-02-05  9:41   ` Li Wang via ltp
  2026-02-05 10:25     ` Petr Vorel
  2026-02-05  9:44   ` Petr Vorel
  1 sibling, 1 reply; 6+ messages in thread
From: Li Wang via ltp @ 2026-02-05  9:41 UTC (permalink / raw)
  To: Petr Vorel; +Cc: ltp

On Thu, Feb 05, 2026 at 02:08:42PM +0800, Li Wang wrote:
> On Wed, Feb 04, 2026 at 01:43:23PM +0100, Petr Vorel wrote:
> > Improve 767b3e519e. struct open_how is also used in lapi/openat2.h,
> > which is used by all openat2*.c tests.  Therefore move <fcntl.h> to the
> > lapi header (and use lapi/fcntl.h instead).
> > 
> > Also remove _GNU_SOURCE which should not be needed.
> > 
> > While at it, move include "config.h" to the top.
> > 
> > Signed-off-by: Petr Vorel <pvorel@suse.cz>
> > ---
> > Hi Li,
> > 
> > my points from the original patchset why not use _GNU_SOURCE:
> > 
> > glibc test tst-openat2.c [1] which includes <fcntl.h>, uses struct
> 
> Interesting, I haven't figure out why it can be built within glibc itself.

I think that becuase it uses '-D_GNU_SOURCE' cflags has already globally
enabled the GNU extension (equivalent to '#define _GNU_SOURCE'), which is
done uniformly by glibc's build system.

 glibc/Makerules: ALL_BUILD_CFLAGS = $(BUILD_CFLAGS) $(BUILD_CPPFLAGS) -D_GNU_SOURCE \
			-DIS_IN_build -include $(common-objpfx)config.h

To verify this, when I add the '-D_GNU_SOURCE' cflgs in the LTP/openat20*.c
compliation, it build succeed as well:

 # gcc -I../../../../include -I../../../../include \
   -I../../../../include/old/ -Wformat -Werror=format-security \
   -Werror=implicit-function-declaration -Werror=return-type -fno-common \
   -g -O2 -fno-strict-aliasing -pipe -Wall -W -Wold-style-definition \
   -D_GNU_SOURCE \
   -std=gnu99 -L../../../../lib openat202.c  -lltp -o openat202

So, to this patch, we need to add the _GNU_SOURCE definition.

-- 
Regards,
Li Wang


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [LTP] [PATCH] openat2: Move includes to lapi, remove _GNU_SOURCE
  2026-02-05  6:08 ` Li Wang via ltp
  2026-02-05  9:41   ` Li Wang via ltp
@ 2026-02-05  9:44   ` Petr Vorel
  2026-02-05 10:17     ` Li Wang via ltp
  1 sibling, 1 reply; 6+ messages in thread
From: Petr Vorel @ 2026-02-05  9:44 UTC (permalink / raw)
  To: Li Wang; +Cc: ltp

> On Wed, Feb 04, 2026 at 01:43:23PM +0100, Petr Vorel wrote:
> > Improve 767b3e519e. struct open_how is also used in lapi/openat2.h,
> > which is used by all openat2*.c tests.  Therefore move <fcntl.h> to the
> > lapi header (and use lapi/fcntl.h instead).

> > Also remove _GNU_SOURCE which should not be needed.

> > While at it, move include "config.h" to the top.

> > Signed-off-by: Petr Vorel <pvorel@suse.cz>
> > ---
> > Hi Li,

> > my points from the original patchset why not use _GNU_SOURCE:

> > glibc test tst-openat2.c [1] which includes <fcntl.h>, uses struct

> Interesting, I haven't figure out why it can be built within glibc itself.

I also checked Makefile, but haven't found that. Never mind, I was wrong, it's
obviously needed.

> > open_how and test openat2() does not define it. Neither openat2() nor
> > struct open_how [2] are guarded by #ifdef __USE_GNU.

> > O_DIRECTORY is guarded by #ifdef __USE_XOPEN2K8 but this should be safe as we
> > compile with -std=gnu99.

> In glibc-2.43, things have changed, only define __USE_GNU can contain the
> <bits/openat2.h> header file, that's why after applying this patch still
> fails to complie on Fedora-Rawhide.

> <fcntl.h> -> <bits/fcntl.h> -> <bits/fcntl-linux.h> -> <bits/openat2.h>

Yeah, I saw this...

>  # cat bits/fcntl-linux.h

>  396 #ifdef __USE_GNU
...but did not check that whole section is guarded by __USE_GNU (=> _GNU_SOURCE).

Kind regards,
Petr

>      ...
>  473 #include <bits/openat2.h>

>  489 #endif	/* use GNU */

> See: https://github.com/bminor/glibc/commit/0f0a5cd338998f4b603f52f3ce2163df0db7b814#diff-a4fc1e1b56b60a2598e320a232e6f631d08e0dafcfe3dd9607dde4bc8ee31eb8R473

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [LTP] [PATCH] openat2: Move includes to lapi, remove _GNU_SOURCE
  2026-02-05  9:44   ` Petr Vorel
@ 2026-02-05 10:17     ` Li Wang via ltp
  0 siblings, 0 replies; 6+ messages in thread
From: Li Wang via ltp @ 2026-02-05 10:17 UTC (permalink / raw)
  To: Petr Vorel; +Cc: ltp

On Thu, Feb 05, 2026 at 10:44:58AM +0100, Petr Vorel wrote:
> > On Wed, Feb 04, 2026 at 01:43:23PM +0100, Petr Vorel wrote:
> > > Improve 767b3e519e. struct open_how is also used in lapi/openat2.h,
> > > which is used by all openat2*.c tests.  Therefore move <fcntl.h> to the
> > > lapi header (and use lapi/fcntl.h instead).
> 
> > > Also remove _GNU_SOURCE which should not be needed.
> 
> > > While at it, move include "config.h" to the top.
> 
> > > Signed-off-by: Petr Vorel <pvorel@suse.cz>
> > > ---
> > > Hi Li,
> 
> > > my points from the original patchset why not use _GNU_SOURCE:
> 
> > > glibc test tst-openat2.c [1] which includes <fcntl.h>, uses struct
> 
> > Interesting, I haven't figure out why it can be built within glibc itself.
> 
> I also checked Makefile, but haven't found that. Never mind, I was wrong, it's
> obviously needed.

It's becuase of -D_GNU_SOURCE cflag in Makerules(which included in Makefile):
https://sourceware.org/git/?p=glibc.git;a=blob;f=Makerules;h=30c3559a285e5bc0571358ab785bf9b5d5a8f449;hb=HEAD#l1182

In case of you miss my last reply thread:
https://lists.linux.it/pipermail/ltp/2026-February/046438.html

-- 
Regards,
Li Wang


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [LTP] [PATCH] openat2: Move includes to lapi, remove _GNU_SOURCE
  2026-02-05  9:41   ` Li Wang via ltp
@ 2026-02-05 10:25     ` Petr Vorel
  0 siblings, 0 replies; 6+ messages in thread
From: Petr Vorel @ 2026-02-05 10:25 UTC (permalink / raw)
  To: Li Wang; +Cc: ltp

> On Thu, Feb 05, 2026 at 02:08:42PM +0800, Li Wang wrote:
> > On Wed, Feb 04, 2026 at 01:43:23PM +0100, Petr Vorel wrote:
> > > Improve 767b3e519e. struct open_how is also used in lapi/openat2.h,
> > > which is used by all openat2*.c tests.  Therefore move <fcntl.h> to the
> > > lapi header (and use lapi/fcntl.h instead).

> > > Also remove _GNU_SOURCE which should not be needed.

> > > While at it, move include "config.h" to the top.

> > > Signed-off-by: Petr Vorel <pvorel@suse.cz>
> > > ---
> > > Hi Li,

> > > my points from the original patchset why not use _GNU_SOURCE:

> > > glibc test tst-openat2.c [1] which includes <fcntl.h>, uses struct

> > Interesting, I haven't figure out why it can be built within glibc itself.

> I think that becuase it uses '-D_GNU_SOURCE' cflags has already globally
> enabled the GNU extension (equivalent to '#define _GNU_SOURCE'), which is
> done uniformly by glibc's build system.

Interesting, I did not know they compile tree with _GNU_SOURCE.

>  glibc/Makerules: ALL_BUILD_CFLAGS = $(BUILD_CFLAGS) $(BUILD_CPPFLAGS) -D_GNU_SOURCE \
> 			-DIS_IN_build -include $(common-objpfx)config.h

Yes, -D is equivalent to #define.  IMHO it's better to use #define _GNU_SOURCE
(more obvious than command line switch).

> To verify this, when I add the '-D_GNU_SOURCE' cflgs in the LTP/openat20*.c
> compliation, it build succeed as well:

>  # gcc -I../../../../include -I../../../../include \
>    -I../../../../include/old/ -Wformat -Werror=format-security \
>    -Werror=implicit-function-declaration -Werror=return-type -fno-common \
>    -g -O2 -fno-strict-aliasing -pipe -Wall -W -Wold-style-definition \
>    -D_GNU_SOURCE \
>    -std=gnu99 -L../../../../lib openat202.c  -lltp -o openat202

> So, to this patch, we need to add the _GNU_SOURCE definition.

Thanks for investigating, I'm sorry for bothering with it.

Kind regards,
Petr

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-02-05 10:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-04 12:43 [LTP] [PATCH] openat2: Move includes to lapi, remove _GNU_SOURCE Petr Vorel
2026-02-05  6:08 ` Li Wang via ltp
2026-02-05  9:41   ` Li Wang via ltp
2026-02-05 10:25     ` Petr Vorel
2026-02-05  9:44   ` Petr Vorel
2026-02-05 10:17     ` Li Wang via ltp

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox