ubmitted by: Xi Ruoyao Date: 2026-03-18 Initial Package Version: 2.43 Upstream Status: Committed for master (2.44 development branch) but not the 2.43 release branch. Origin: Upstream repository (see the "cherry picked from" notes for revision) Description: Fix redefinition of OPEN_TREE_* macros in the header with the API header from Linux >= 7.0 that causes build failure of glibc itself (and maybe other packages using the header). From 761783a86f651ac21530346e0287f364e4751796 Mon Sep 17 00:00:00 2001 From: DJ Delorie Date: Mon, 26 Jan 2026 22:24:42 -0500 Subject: [PATCH 1/2] include: isolate __O_CLOEXEC flag for sys/mount.h and fcntl.h Including sys/mount.h should not implicitly include fcntl.h as that causes namespace pollution and conflicts with kernel headers. It only needs O_CLOEXEC for OPEN_TREE_CLOEXEC (although it shouldn't need that, but it's defined that way) so we provide that define (via a private version) separately. Reviewed-by: Adhemerval Zanella Tested-by: Florian Weimer (cherry picked from commit 419245719ccbc7dad6a97f24465e7f09c090327a) --- io/fcntl.c | 4 ++++ sysdeps/unix/sysv/linux/Makefile | 1 + sysdeps/unix/sysv/linux/alpha/bits/cloexec.h | 1 + sysdeps/unix/sysv/linux/bits/cloexec.h | 1 + sysdeps/unix/sysv/linux/bits/fcntl-linux.h | 4 +--- sysdeps/unix/sysv/linux/hppa/bits/cloexec.h | 1 + sysdeps/unix/sysv/linux/sparc/bits/cloexec.h | 1 + sysdeps/unix/sysv/linux/sys/mount.h | 6 +++++- sysdeps/unix/sysv/linux/tst-mount.c | 1 + 9 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 sysdeps/unix/sysv/linux/alpha/bits/cloexec.h create mode 100644 sysdeps/unix/sysv/linux/bits/cloexec.h create mode 100644 sysdeps/unix/sysv/linux/hppa/bits/cloexec.h create mode 100644 sysdeps/unix/sysv/linux/sparc/bits/cloexec.h diff --git a/io/fcntl.c b/io/fcntl.c index c13546e4fd..4fbc522624 100644 --- a/io/fcntl.c +++ b/io/fcntl.c @@ -18,6 +18,10 @@ #include #include +#ifndef __O_CLOEXEC +# error __O_CLOEXEC not defined by fcntl.h/cloexec.h +#endif + /* Perform file control operations on FD. */ int __fcntl (int fd, int cmd, ...) diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile index 955d316362..c6bd97abf1 100644 --- a/sysdeps/unix/sysv/linux/Makefile +++ b/sysdeps/unix/sysv/linux/Makefile @@ -129,6 +129,7 @@ CFLAGS-test-errno-linux.c += $(no-fortify-source) sysdep_headers += \ bits/a.out.h \ + bits/cloexec.h \ bits/epoll.h \ bits/eventfd.h \ bits/inotify.h \ diff --git a/sysdeps/unix/sysv/linux/alpha/bits/cloexec.h b/sysdeps/unix/sysv/linux/alpha/bits/cloexec.h new file mode 100644 index 0000000000..f381f28a53 --- /dev/null +++ b/sysdeps/unix/sysv/linux/alpha/bits/cloexec.h @@ -0,0 +1 @@ +#define __O_CLOEXEC 010000000 diff --git a/sysdeps/unix/sysv/linux/bits/cloexec.h b/sysdeps/unix/sysv/linux/bits/cloexec.h new file mode 100644 index 0000000000..3059fb6473 --- /dev/null +++ b/sysdeps/unix/sysv/linux/bits/cloexec.h @@ -0,0 +1 @@ +#define __O_CLOEXEC 02000000 diff --git a/sysdeps/unix/sysv/linux/bits/fcntl-linux.h b/sysdeps/unix/sysv/linux/bits/fcntl-linux.h index ad7f7c98c6..221a71aa62 100644 --- a/sysdeps/unix/sysv/linux/bits/fcntl-linux.h +++ b/sysdeps/unix/sysv/linux/bits/fcntl-linux.h @@ -81,9 +81,7 @@ #ifndef __O_NOFOLLOW # define __O_NOFOLLOW 0400000 #endif -#ifndef __O_CLOEXEC -# define __O_CLOEXEC 02000000 -#endif +#include #ifndef __O_DIRECT # define __O_DIRECT 040000 #endif diff --git a/sysdeps/unix/sysv/linux/hppa/bits/cloexec.h b/sysdeps/unix/sysv/linux/hppa/bits/cloexec.h new file mode 100644 index 0000000000..f381f28a53 --- /dev/null +++ b/sysdeps/unix/sysv/linux/hppa/bits/cloexec.h @@ -0,0 +1 @@ +#define __O_CLOEXEC 010000000 diff --git a/sysdeps/unix/sysv/linux/sparc/bits/cloexec.h b/sysdeps/unix/sysv/linux/sparc/bits/cloexec.h new file mode 100644 index 0000000000..6706eaa7d5 --- /dev/null +++ b/sysdeps/unix/sysv/linux/sparc/bits/cloexec.h @@ -0,0 +1 @@ +#define __O_CLOEXEC 0x400000 diff --git a/sysdeps/unix/sysv/linux/sys/mount.h b/sysdeps/unix/sysv/linux/sys/mount.h index 457d8dcff2..5e496caf2f 100644 --- a/sysdeps/unix/sysv/linux/sys/mount.h +++ b/sysdeps/unix/sysv/linux/sys/mount.h @@ -21,7 +21,6 @@ #ifndef _SYS_MOUNT_H #define _SYS_MOUNT_H 1 -#include #include #include #include @@ -266,6 +265,11 @@ enum fsconfig_command /* open_tree flags. */ #define OPEN_TREE_CLONE 1 /* Clone the target tree and attach the clone */ +#ifndef O_CLOEXEC +# include +# define O_CLOEXEC __O_CLOEXEC +#endif +#undef OPEN_TREE_CLOEXEC #define OPEN_TREE_CLOEXEC O_CLOEXEC /* Close the file on execve() */ diff --git a/sysdeps/unix/sysv/linux/tst-mount.c b/sysdeps/unix/sysv/linux/tst-mount.c index 8e3ffbd56f..84dcd448d4 100644 --- a/sysdeps/unix/sysv/linux/tst-mount.c +++ b/sysdeps/unix/sysv/linux/tst-mount.c @@ -20,6 +20,7 @@ #include #include #include +#include /* For AT_ constants. */ #include _Static_assert (sizeof (struct mount_attr) == MOUNT_ATTR_SIZE_VER0, -- 2.53.0 From e7b85e31c2125e16f5ad6174d9ae87ee27e8968b Mon Sep 17 00:00:00 2001 From: Florian Weimer Date: Wed, 4 Mar 2026 18:32:36 +0100 Subject: [PATCH 2/2] Linux: Only define OPEN_TREE_* macros in if undefined (bug 33921) There is a conditional inclusion of earlier in the file. If that defines the macros, do not redefine them. This addresses build problems as the token sequence used by the UAPI macro definitions changes between Linux versions. Reviewed-by: Adhemerval Zanella (cherry picked from commit d12b017cddfeb9fe9920ba054ae3dfcb8e9238b8) --- sysdeps/unix/sysv/linux/sys/mount.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/sysdeps/unix/sysv/linux/sys/mount.h b/sysdeps/unix/sysv/linux/sys/mount.h index 5e496caf2f..0c5ebed33a 100644 --- a/sysdeps/unix/sysv/linux/sys/mount.h +++ b/sysdeps/unix/sysv/linux/sys/mount.h @@ -264,14 +264,16 @@ enum fsconfig_command #define FSOPEN_CLOEXEC 0x00000001 /* open_tree flags. */ -#define OPEN_TREE_CLONE 1 /* Clone the target tree and attach the clone */ +#ifndef OPEN_TREE_CLONE +# define OPEN_TREE_CLONE 1 /* Clone the target tree and attach the clone */ +#endif #ifndef O_CLOEXEC # include # define O_CLOEXEC __O_CLOEXEC #endif -#undef OPEN_TREE_CLOEXEC -#define OPEN_TREE_CLOEXEC O_CLOEXEC /* Close the file on execve() */ - +#ifndef OPEN_TREE_CLOEXEC +# define OPEN_TREE_CLOEXEC O_CLOEXEC /* Close the file on execve() */ +#endif __BEGIN_DECLS -- 2.53.0