Bug 1721129 - glibc: Address conflict between <sys/stat.h> and <linux/stat.h>
Summary: glibc: Address conflict between <sys/stat.h> and <linux/stat.h>
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: glibc
Version: 30
Hardware: All
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Florian Weimer
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks: 1699194
TreeView+ depends on / blocked
 
Reported: 2019-06-17 12:34 UTC by Florian Weimer
Modified: 2019-09-21 05:47 UTC (History)
10 users (show)

Fixed In Version: glibc-2.29.9000-28.fc31 glibc-2.29-16.fc30 glibc-2.28-34.fc29
Clone Of: 1699194
Environment:
Last Closed: 2019-09-21 05:47:16 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)

Description Florian Weimer 2019-06-17 12:34:47 UTC
+++ This bug was initially created as a clone of Bug #1699194 +++

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):
glibc-headers-2.28-42.el8.x86_64
kernel-headers-4.18.0-80.el8.x86_64

How reproducible:
100%

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.

[1]
--- /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.
-#endif
 
 struct statx_timestamp
 {
@@ -81,6 +80,8 @@ struct statx
 #define STATX_ATTR_ENCRYPTED 0x0800
 #define STATX_ATTR_AUTOMOUNT 0x1000
 
+#endif
+
 __BEGIN_DECLS
 
 /* Fill *BUF with information about PATH in DIRFD.  */


[2]
/* 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.)  */

[…]

--- Additional comment from Florian Weimer on 2019-06-15 00:29:19 CEST ---

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 1 Fedora Update System 2019-09-05 09:20:18 UTC
FEDORA-2019-2e9a65b50a has been submitted as an update to Fedora 30. https://bodhi.fedoraproject.org/updates/FEDORA-2019-2e9a65b50a

Comment 2 Fedora Update System 2019-09-05 12:53:26 UTC
glibc-2.29-22.fc30 has been pushed to the Fedora 30 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2019-2e9a65b50a

Comment 3 Fedora Update System 2019-09-06 09:44:25 UTC
FEDORA-2019-8532718f88 has been submitted as an update to Fedora 29. https://bodhi.fedoraproject.org/updates/FEDORA-2019-8532718f88

Comment 4 Fedora Update System 2019-09-06 12:34:00 UTC
glibc-2.29-22.fc30 has been pushed to the Fedora 30 stable repository. If problems still persist, please make note of it in this bug report.

Comment 5 Fedora Update System 2019-09-06 13:21:52 UTC
glibc-2.28-39.fc29 has been pushed to the Fedora 29 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2019-8532718f88

Comment 6 Fedora Update System 2019-09-21 01:42:22 UTC
glibc-2.28-39.fc29 has been pushed to the Fedora 29 stable repository. If problems still persist, please make note of it in this bug report.


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