Bug 1699194 - glibc: Address conflict between <sys/stat.h> and <linux/stat.h>
Summary: glibc: Address conflict between <sys/stat.h> and <linux/stat.h>
Alias: None
Product: Red Hat Enterprise Linux 8
Classification: Red Hat
Component: glibc
Version: 8.0
Hardware: All
OS: Linux
Target Milestone: rc
: 8.1
Assignee: Florian Weimer
QA Contact: qe-baseos-tools-bugs
Depends On: 1721129
Blocks: 1684559
TreeView+ depends on / blocked
Reported: 2019-04-12 04:22 UTC by Zorro Lang
Modified: 2021-09-17 12:17 UTC (History)
10 users (show)

Fixed In Version: glibc-2.28-66.el8
Doc Type: No Doc Update
Doc Text:
Clone Of:
: 1721129 (view as bug list)
Last Closed: 2019-11-05 21:29:04 UTC
Type: Bug
Target Upstream Version:

Attachments (Terms of Use)

System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHSA-2019:3513 0 None None None 2019-11-05 21:29:24 UTC

Description Zorro Lang 2019-04-12 04:22:54 UTC
Description of problem:
When I built latest upstream xfsprogs(HEAD=28bbc15a60d7ffb5fc9e28bbc16c67916a831ece) on RHEL-8, I got below error:

Building io
    [CC]     stat.o
In file included from /usr/include/sys/stat.h:446,
                 from ../include/xfs/linux.h:13,
                 from ../include/xfs.h:9,
                 from ../include/project.h:10,
                 from ../include/input.h:12,
                 from stat.c:13:
/usr/include/bits/statx.h:25:8: error: redefinition of ‘struct statx_timestamp’
 struct statx_timestamp
In file included from stat.c:10:
/usr/include/linux/stat.h:56:8: note: originally defined here
 struct statx_timestamp {
In file included from /usr/include/sys/stat.h:446,
                 from ../include/xfs/linux.h:13,
                 from ../include/xfs.h:9,
                 from ../include/project.h:10,
                 from ../include/input.h:12,
                 from stat.c:13:
/usr/include/bits/statx.h:36:8: error: redefinition of ‘struct statx’
 struct statx
In file included from stat.c:10:
/usr/include/linux/stat.h:99:8: note: originally defined here
 struct statx {
gmake[2]: *** [../include/buildrules:81: stat.o] Error 1
gmake[1]: *** [include/buildrules:36: io] Error 2
make: *** [Makefile:92: default] Error 2

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:
# git clone git://git.kernel.org/pub/scm/fs/xfs/xfsprogs-dev.git
# git checkout -b for-next origin/for-next
# make

Actual results:
As above

Expected results:

Additional info:
A trick[1] as below can avoid this issue. But bits/statx.h already metioned[2] the kernel may add additional fields to struct statx in the future. So I suppose glibc might already has a proper strategy to deal with this conflict.

--- /usr/include/bits/statx.h.old       2019-04-12 00:16:43.028623409 -0400
+++ /usr/include/bits/statx.h   2019-04-12 00:09:12.318449804 -0400
@@ -20,7 +20,6 @@
 #ifndef _SYS_STAT_H
 # error Never include <bits/stat.x.h> directly, include <sys/stat.h> instead.
 struct statx_timestamp
@@ -81,6 +80,8 @@ struct statx
 #define STATX_ATTR_ENCRYPTED 0x0800
 #define STATX_ATTR_AUTOMOUNT 0x1000
 /* Fill *BUF with information about PATH in DIRFD.  */

/* Warning: The kernel may add additional fields to this struct in the
   future.  Only use this struct for calling the statx function, not
   for storing data.  (Expansion will be controlled by the mask
   argument of the statx function.)  */

Comment 3 Eric Sandeen 2019-05-21 03:30:02 UTC
Just FWIW, we worked around this upstream in xfsprogs:

commit 868d0cce41645d5a240a7728cdf33b074b3d01f0
Author: Eric Sandeen <sandeen>
Date:   Fri May 3 11:51:37 2019 -0500

    xfs_io: rework includes for statx structures
    Only include the kernel's linux/stat.h headers if we haven't
    already picked up statx bits from glibc, to avoid redefinition.
    Suggested-by: Darrick J. Wong <darrick.wong>
    Signed-off-by: Eric Sandeen <sandeen>
    Tested-by: Bill O'Donnell <billodo>
    Reviewed-by: Darrick J. Wong <darrick.wong>
    Reviewed-by: Bill O'Donnell <billodo>
    Signed-off-by: Eric Sandeen <sandeen>

Comment 4 Eric Sandeen 2019-05-21 03:35:07 UTC
(TBH I thought this was a problem unique to xfsprogs)

Comment 5 Florian Weimer 2019-06-05 14:54:35 UTC
I proposed a patch upstream:


Comment 7 Florian Weimer 2019-06-14 22:29:19 UTC
I backported the following upstream commits:

commit 4e75c2a43bb3208f32556a2b19c939cfe1f54ba6
Author: Florian Weimer <fweimer>
Date:   Wed Jun 12 10:41:19 2019 +0200

    <sys/cdefs.h>: Add __glibc_has_include macro

commit 5dad6ffbb2b76215cfcd38c3001778536ada8e8a
Author: Florian Weimer <fweimer>
Date:   Wed Jun 12 12:04:09 2019 +0200

    <sys/stat.h>: Use Linux UAPI header for statx if available and useful
    This will automatically import new STATX_* constants.  It also avoids
    a conflict between <sys/stat.h> and <linux/stat.h>.

commit 8d141877e07cc594e9fefc3795b8ba729288093c
Author: Florian Weimer <fweimer>
Date:   Fri Jun 14 15:46:02 2019 +0200

    <sys/cdefs.h>: Inhibit macro expansion for __glibc_has_include
    This is currently ineffective with GCC because of GCC PR 80005, but
    it makes sense to anticipate a fix for this defect.

commit 48c3c1238925410b4e777dc94e2fde4cc9132d44
Author: Florian Weimer <fweimer>
Date:   Fri Jun 14 16:28:41 2019 +0200

    Linux: Fix __glibc_has_include use for <sys/stat.h> and statx
    The identifier linux is used as a predefined macro, so the actually
    used path is 1/stat.h or 1/stat64.h.  Using the quote-based version
    triggers a file lookup for /usr/include/bits/linux/stat.h (or whatever
    directory is used to store bits/statx.h), but since bits/ is pretty
    much reserved by glibc, this appears to be acceptable.
    This is related to GCC PR 80005: incorrect macro expansion of the
    argument of __has_include.

Comment 11 Sergey Kolosov 2019-08-22 08:12:11 UTC
Verified with xfsprogs-5.0.0 without https://bugzilla.redhat.com/show_bug.cgi?id=1699194#c3 commit. Added sanity check that there is no conflict in case of both linux/stat.h and sys/stat.h headers are included.

Comment 13 errata-xmlrpc 2019-11-05 21:29:04 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.


Note You need to log in before you can comment on or make changes to this bug.