Bug 91085 - [11 only] fixincludes breaks <bits/statx.h>
Summary: [11 only] fixincludes breaks <bits/statx.h>
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: other (show other bugs)
Version: 9.1.1
: P3 normal
Target Milestone: 11.5
Assignee: Not yet assigned to anyone
URL:
Keywords: build
Depends on:
Blocks:
 
Reported: 2019-07-04 09:55 UTC by Andreas Schwab
Modified: 2023-07-07 08:30 UTC (History)
8 users (show)

See Also:
Host:
Target: *-*-linux*
Build:
Known to work: 12.1.0
Known to fail: 10.5.0
Last reconfirmed: 2020-01-27 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andreas Schwab 2019-07-04 09:55:27 UTC
fixincludes applies a bad change to <bits/statx.h> from glibc 2.30.

@@ -26,7 +35,7 @@
 
 /* Use "" to work around incorrect macro expansion of the
    __has_include argument (GCC PR 80005).  */
-#if __glibc_has_include ("linux/stat.h")
+#if __glibc_has_include ("__linux__/stat.h")
 # include "linux/stat.h"
 # ifdef STATX_TYPE
 #  define __statx_timestamp_defined 1
Comment 1 Richard Biener 2019-08-05 12:45:25 UTC
Hrm, may want to fix this for 9.2?
Comment 2 Jakub Jelinek 2019-08-05 13:03:58 UTC
IMHO not needed for 9.2, glibc will just behave as it used to be ever before with this header.  I'd say let's fix it in on the trunk, let's fix PR80005 and then we can talk about backporting.
Comment 3 Martin Liška 2020-01-27 13:14:49 UTC
Is this still an issue?
Comment 4 Andreas Schwab 2020-01-27 14:33:25 UTC
Yes, nothing has changed.
Comment 5 Jakub Jelinek 2020-02-03 17:05:03 UTC
Well, at least PR80005 has been fixed...
Comment 6 Andreas Schwab 2020-02-03 17:12:51 UTC
PR80005 is not relevant here.
Comment 7 Jakub Jelinek 2020-02-07 10:24:42 UTC
Current glibc uses
#ifdef __has_include
# if __has_include ("linux/stat.h")
#  include "linux/stat.h"
#  ifdef STATX_TYPE
#   define __statx_timestamp_defined 1
#   define __statx_defined 1
#  endif
# endif
#endif
instead, is that also broken by fixincludes?
Comment 8 Andreas Schwab 2020-02-11 16:57:45 UTC
Yes, nothing has changed.
Comment 9 Tendel10 2020-06-30 06:12:15 UTC
I am having this issue as well, any updates on this bug?
Comment 10 Tendel10 2020-06-30 06:12:50 UTC
I am having this issue as well, any updates on this bug?
Comment 11 martingalvan 2020-08-19 17:45:23 UTC
This bug is still happening on gcc 9.2.1.
Comment 12 Bruce Korb 2020-08-21 04:51:12 UTC
I'll put it on my to-do list, but I might be participating in a fire evacuation tonight or tomorrow and I haven't built GCC in several years now. I'm going to guess that you have to not do the substitution when the line contains something like:

    #[ \t]*if[ \t]+__glibc_has
Comment 14 Bruce Korb 2021-06-27 21:04:27 UTC
Reworking fixfixes.c seems pretty heavy duty.
I'm downloading the GCC sources now. I'll take a peek tomorrow.
Comment 15 Bruce Korb 2021-06-27 23:43:17 UTC
Obviously, "print_quote()" was needed early on (1999) and then saved for prosperity :). Your patch is inadequate because it will have to not expand 'linux' in a line such as:

    #if __has_include(<linux/foo.h>)

In other words, it will have to skip over three flavors of quote. Or just two, if you omit apostrophe quotes. In any event, the '<' character will have to be matched with '>', which is a tiny change to the logic.

Don't forget to add tests in the final result.
Comment 16 Xi Ruoyao 2021-06-28 04:14:51 UTC
(In reply to Bruce Korb from comment #15)
> Obviously, "print_quote()" was needed early on (1999) and then saved for
> prosperity :). Your patch is inadequate because it will have to not expand
> 'linux' in a line such as:
> 
>     #if __has_include(<linux/foo.h>)
> 
> In other words, it will have to skip over three flavors of quote. Or just
> two, if you omit apostrophe quotes. In any event, the '<' character will
> have to be matched with '>', which is a tiny change to the logic.
> 
> Don't forget to add tests in the final result.

Simply skipping <...> can be problematic for something like:

#if A < B && i386 && C > D
#define USE_I386_WORKAROUND
#endif
Comment 17 Xi Ruoyao 2021-06-28 07:37:23 UTC
Revised patch, matching __has_include(...):

https://gcc.gnu.org/pipermail/gcc-patches/2021-June/573789.html
Comment 18 GCC Commits 2021-06-30 02:44:37 UTC
The master branch has been updated by Xi Ruoyao <xry111@gcc.gnu.org>:

https://gcc.gnu.org/g:6bf383c37e6131a8e247e8a0997d55d65c830b6d

commit r12-1924-g6bf383c37e6131a8e247e8a0997d55d65c830b6d
Author: Xi Ruoyao <xry111@mengyan1223.wang>
Date:   Mon Jun 28 13:54:58 2021 +0800

    fixinc: don't "fix" machine names in __has_include(...) [PR91085]
    
    fixincludes/
    
            PR other/91085
            * fixfixes.c (check_has_inc): New static function.
              (machine_name_fix): Don't replace header names in
              __has_include(...).
            * inclhack.def (machine_name): Adjust test.
            * tests/base/testing.h: Update.