package/gcc: add patch to fix glibc header conflict
PATCH 1/1 package/gcc: add patch to fix glibc header conflict
This commit backports the patch "fixinc: don't "fix" machine names in __has_include(...)" from upstream GCC, which is needed to resolve a header conflict between glibc headers and kernel headers, which has appeared since we bumped glibc to version 2.36 in commit 80c8c15c8534a24382b900a07082a289a368f736.
The problem comes from the "fixinc" logic used by gcc to fixup some headers files, generated inside an include-fixed/ folder. This logic ended up replacing "linux/mount.h" by "__linux__/mount.h" in __has_include() invocation, like this:
#ifdef __has_include
# if __has_include ("__linux__/mount.h")
# include "linux/mount.h"
# endif
#endifin build/host-gcc-final-11.3.0/build/gcc/include-fixed/sys/mount.h. With this fix in place, this "include-fixed" header is no longer generated, avoiding the problem.
This issue was visible in two different ways in glibc configurations:
- As a build failure during the gcc build itself, for architectures that support libsanitizer, as libsanitizer includes mount.h, and would therefore encounter the header conflict.
- As a build failure during another user-space package (such as sysvinit for example), on architectures when libsanitizer isn't used, and therefore for which the gcc build was successful, but the header conflict shows up when building some "random" user-space package.
The problem is already fixed in GCC 12.2.0, so no patch is required. The problem did not exist back in GCC 8.4.0, so this version does not need patching. Consequently, the patch is only needed for GCC 10.4.0, GCC 11.3.0 and the special ARC 2020.09-release version.
Fixes:
(gcc build issue, on architecture that supports libsanitizer)
http://autobuild.buildroot.net/results/90fe4c3b8b72a2c28555674383de9bbd9e8ae09a/
(sysvinit build issue, on architecture that does not support libsanitizer)
http://autobuild.buildroot.net/results/d7bf5795b7621a92be32f18794e3e67944fb96db/
(crun)
http://autobuild.buildroot.net/results/e3e8da4f797dced48aedf8c636db983d36849850/
(libarchive)
http://autobuild.buildroot.net/results/9fcbf0c036a97b2e9a4fcc6e173bcfa09e1b3dac/
Thanks a lot to Peter Seiderer for pointing the relevant GCC commit.
Fixes:
https://bugs.busybox.net/show_bug.cgi?id=15021
--- ...-machine-names-in-__has_include-.-PR.patch | 124 ++++++++++++++++++ ...-machine-names-in-__has_include-.-PR.patch | 124 ++++++++++++++++++ ...-machine-names-in-__has_include-.-PR.patch | 124 ++++++++++++++++++ 3 files changed, 372 insertions(+) create mode 100644 package/gcc/10.4.0/0006-fixinc-don-t-fix-machine-names-in-__has_include-.-PR.patch create mode 100644 package/gcc/11.3.0/0007-fixinc-don-t-fix-machine-names-in-__has_include-.-PR.patch create mode 100644 package/gcc/arc-2020.09-release/0003-fixinc-don-t-fix-machine-names-in-__has_include-.-PR.patch
package/gcc/10.4.0/0006-fixinc-don-t-fix-machine-names-in-__has_include-.-PR.patch new file +124 -0
@@ -0,0 +1,124 @@ +From a6eedb593ca068d0ad8655dbb97fcd6371cba682 Mon Sep 17 00:00:00 2001 +From: Xi Ruoyao <[email protected]> +Date: Mon, 28 Jun 2021 13:54:58 +0800 +Subject: [PATCH] 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. + +Upstream: 6bf383c37e6131a8e247e8a0997d55d65c830b6d +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + fixincludes/fixfixes.c | 45 ++++++++++++++++++++++++++++++-- + fixincludes/inclhack.def | 3 ++- + fixincludes/tests/base/testing.h | 2 +- + 3 files changed, 46 insertions(+), 4 deletions(-) + +diff --git a/fixincludes/fixfixes.c b/fixincludes/fixfixes.c +index 034e15d9985..3ff87812036 100644 +--- a/fixincludes/fixfixes.c ++++ b/fixincludes/fixfixes.c +@@ -477,6 +477,39 @@ FIX_PROC_HEAD( char_macro_def_fix ) + fputs (text, stdout); + } + ++/* Check if the pattern at pos is actually in a "__has_include(...)" ++ directive. Return the pointer to the ')' of this ++ "__has_include(...)" if it is, NULL otherwise. */ ++static const char * ++check_has_inc (const char *begin, const char *pos, const char *end) ++{ ++ static const char has_inc[] = "__has_include"; ++ const size_t has_inc_len = sizeof (has_inc) - 1; ++ const char *p; ++ ++ for (p = memmem (begin, pos - begin, has_inc, has_inc_len); ++ p != NULL; ++ p = memmem (p, pos - p, has_inc, has_inc_len)) ++ { ++ p += has_inc_len; ++ while (p < end && ISSPACE (*p)) ++ p++; ++ ++ /* "__has_include" may appear as "defined(__has_include)", ++ search for the next appearance then. */ ++ if (*p != '(') ++ continue; ++ ++ /* To avoid too much complexity, just hope there is never a ++ ')' in a header name. */ ++ p = memchr (p, ')', end - p); ++ if (p == NULL || p > pos) ++ return p; ++ } ++ ++ return NULL; ++} ++ + /* Fix for machine name #ifdefs that are not in the namespace reserved + by the C standard. They won't be defined if compiling with -ansi, + and the headers will break. We go to some trouble to only change +@@ -524,7 +557,7 @@ FIX_PROC_HEAD( machine_name_fix ) + /* If the 'name_pat' matches in between base and limit, we have + a bogon. It is not worth the hassle of excluding comments + because comments on #if/#ifdef lines are rare, and strings on +- such lines are illegal. ++ such lines are only legal in a "__has_include" directive. + + REG_NOTBOL means 'base' is not at the beginning of a line, which + shouldn't matter since the name_re has no ^ anchor, but let's +@@ -544,8 +577,16 @@ FIX_PROC_HEAD( machine_name_fix ) + break; + + p = base + match[0].rm_so; +- base += match[0].rm_eo; + ++ /* Check if the match is in __has_include(...) (PR 91085). */ ++ q = check_has_inc (base, p, limit); ++ if (q) ++ { ++ base = q + 1; ++ goto again; ++ } ++ ++ base += match[0].rm_eo; + /* One more test: if on the same line we have the same string + with the appropriate underscores, then leave it alone. + We want exactly two leading and trailing underscores. */ +diff --git a/fixincludes/inclhack.def b/fixincludes/inclhack.def +index f58e7771e1c..71bd717c233 100644 +--- a/fixincludes/inclhack.def ++++ b/fixincludes/inclhack.def +@@ -3114,7 +3114,8 @@ fix = { + c_fix = machine_name; + + test_text = "/* MACH_DIFF: */\n" +- "#if defined( i386 ) || defined( sparc ) || defined( vax )" ++ "#if defined( i386 ) || defined( sparc ) || defined( vax ) || " ++ "defined( linux ) || __has_include ( <linux.h> )" + "\n/* no uniform test, so be careful :-) */"; + }; + +diff --git a/fixincludes/tests/base/testing.h b/fixincludes/tests/base/testing.h +index cf95321fb86..8b3accaf04e 100644 +--- a/fixincludes/tests/base/testing.h ++++ b/fixincludes/tests/base/testing.h +@@ -64,7 +64,7 @@ BSD43__IOWR('T', 1) /* Some are multi-line */ + + #if defined( MACHINE_NAME_CHECK ) + /* MACH_DIFF: */ +-#if defined( i386 ) || defined( sparc ) || defined( vax ) ++#if defined( i386 ) || defined( sparc ) || defined( vax ) || defined( linux ) || __has_include ( <linux.h> ) + /* no uniform test, so be careful :-) */ + #endif /* MACHINE_NAME_CHECK */ + +-- +2.37.3 +
package/gcc/11.3.0/0007-fixinc-don-t-fix-machine-names-in-__has_include-.-PR.patch new file +124 -0
124 lines not on this page · raw message
package/gcc/arc-2020.09-release/0003-fixinc-don-t-fix-machine-names-in-__has_include-.-PR.patch new file +124 -0
124 lines not on this page · raw message
Signature · 6 lines
2.37.3 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
Hello Thomas,
Le 25/10/2022 à 22:13, Thomas Petazzoni via buildroot a écrit :
Quoted 22 lines
This commit backports the patch "fixinc: don't "fix" machine names in
__has_include(...)" from upstream GCC, which is needed to resolve a header conflict between glibc headers and kernel headers, which has appeared since we bumped glibc to version 2.36 in commit80c8c15c8534a24382b900a07082a289a368f736.The problem comes from the "fixinc" logic used by gcc to fixup some headers files, generated inside an include-fixed/ folder. This logic ended up replacing "
linux/mount.h" by "__linux__/mount.h" in__has_include()invocation, like this:#ifdef
__has_include# if __has_include ("__linux__/mount.h") # include "linux/mount.h" # endif #endifin
build/host-gcc-final-11.3.0/build/gcc/include-fixed/sys/mount.h. With this fix in place, this "include-fixed" header is no longer generated, avoiding the problem.
Quoted 5 lines
This issue was visible in two different ways in glibc configurations:
- As a build failure during the gcc build itself, for architectures that support libsanitizer, as libsanitizer includes
mount.h, and would therefore encounter the header conflict.
It seems glibc 2.36 was not used last time the toolchain-builder was used (indeed it was glibc 2.35-134...)
Maybe building all qemu defconfig would trigger the issue since now glibc is used by default.
Quoted 6 lines
- As a build failure during another user-space package (such as sysvinit for example), on architectures when libsanitizer isn't used, and therefore for which the gcc build was successful, but the header conflict shows up when building some "random" user-space package.
Anyway, our toolchain testing with toolchain-builder or qemu defconfig would not dectect such issue.
Quoted 17 lines
The problem is already fixed in GCC 12.2.0, so no patch is required. The problem did not exist back in GCC 8.4.0, so this version does not need patching. Consequently, the patch is only needed for GCC 10.4.0, GCC 11.3.0 and the special ARC 2020.09-release version.
Fixes:
(gcc build issue, on architecture that supports libsanitizer)
http://autobuild.buildroot.net/results/90fe4c3b8b72a2c28555674383de9bbd9e8ae09a/(sysvinit build issue, on architecture that does not support libsanitizer)
http://autobuild.buildroot.net/results/d7bf5795b7621a92be32f18794e3e67944fb96db/(crun)
http://autobuild.buildroot.net/results/e3e8da4f797dced48aedf8c636db983d36849850/
Quoted 8 lines
(libarchive)
http://autobuild.buildroot.net/results/9fcbf0c036a97b2e9a4fcc6e173bcfa09e1b3dac/Thanks a lot to Peter Seiderer for pointing the relevant GCC commit.
Fixes:
Best regards,
Romain
Quoted 11 lines
Signed-off-by Thomas Petazzoni <[email protected]>--- ...-machine-names-in-__has_include-.-PR.patch | 124 ++++++++++++++++++ ...-machine-names-in-__has_include-.-PR.patch | 124 ++++++++++++++++++ ...-machine-names-in-__has_include-.-PR.patch | 124 ++++++++++++++++++ 3 files changed, 372 insertions(+) create mode 100644 package/gcc/10.4.0/0006-fixinc-don-t-fix-machine-names-in-__has_include-.-PR.patch create mode 100644 package/gcc/11.3.0/0007-fixinc-don-t-fix-machine-names-in-__has_include-.-PR.patch create mode 100644 package/gcc/arc-2020.09-release/0003-fixinc-don-t-fix-machine-names-in-__has_include-.-PR.patch
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
Quoted 53 lines · Thomas Petazzoni via buildroot
This commit backports the patch "fixinc: don't "fix" machine names in
__has_include(...)" from upstream GCC, which is needed to resolve a header conflict between glibc headers and kernel headers, which has appeared since we bumped glibc to version 2.36 in commit80c8c15c8534a24382b900a07082a289a368f736.The problem comes from the "fixinc" logic used by gcc to fixup some headers files, generated inside an include-fixed/ folder. This logic ended up replacing "
linux/mount.h" by "__linux__/mount.h" in__has_include()invocation, like this:#ifdef __has_include # if __has_include ("__linux__/mount.h") # include "linux/mount.h" # endif #endifin
build/host-gcc-final-11.3.0/build/gcc/include-fixed/sys/mount.h. With this fix in place, this "include-fixed" header is no longer generated, avoiding the problem.This issue was visible in two different ways in glibc configurations:
- As a build failure during the gcc build itself, for architectures that support libsanitizer, as libsanitizer includes
mount.h, and would therefore encounter the header conflict.- As a build failure during another user-space package (such as sysvinit for example), on architectures when libsanitizer isn't used, and therefore for which the gcc build was successful, but the header conflict shows up when building some "random" user-space package.
The problem is already fixed in GCC 12.2.0, so no patch is required. The problem did not exist back in GCC 8.4.0, so this version does not need patching. Consequently, the patch is only needed for GCC 10.4.0, GCC 11.3.0 and the special ARC 2020.09-release version.
Fixes:
(gcc build issue, on architecture that supports libsanitizer) http://autobuild.buildroot.net/results/90fe4c3b8b72a2c28555674383de9bbd9e8ae09a/ (sysvinit build issue, on architecture that does not support libsanitizer) http://autobuild.buildroot.net/results/d7bf5795b7621a92be32f18794e3e67944fb96db/ (crun) http://autobuild.buildroot.net/results/e3e8da4f797dced48aedf8c636db983d36849850/ (libarchive) http://autobuild.buildroot.net/results/9fcbf0c036a97b2e9a4fcc6e173bcfa09e1b3dac/
Quoted 7 lines
Thanks a lot to Peter Seiderer for pointing the relevant GCC commit.
Fixes:
https://bugs.busybox.net/show_bug.cgi?id=15021Signed-off-by Thomas Petazzoni <[email protected]>
Regards,
Arnout
Quoted 389 lines
--- ...-machine-names-in-__has_include-.-PR.patch | 124 ++++++++++++++++++ ...-machine-names-in-__has_include-.-PR.patch | 124 ++++++++++++++++++ ...-machine-names-in-__has_include-.-PR.patch | 124 ++++++++++++++++++ 3 files changed, 372 insertions(+)create mode 100644
package/gcc/10.4.0/0006-fixinc-don-t-fix-machine-names-in-__has_include-.-PR.patchcreate mode 100644package/gcc/11.3.0/0007-fixinc-don-t-fix-machine-names-in-__has_include-.-PR.patchcreate mode 100644package/gcc/arc-2020.09-release/0003-fixinc-don-t-fix-machine-names-in-__has_include-.-PR.patchpackage/gcc/10.4.0/0006-fixinc-don-t-fix-machine-names-in-__has_include-.-PR.patch new file +124
-0@@ -0,0 +1,124 @@ +From a6eedb593ca068d0ad8655dbb97fcd6371cba682 Mon Sep 17 00:00:00 2001 +From: Xi Ruoyao <[email protected]> +Date: Mon, 28 Jun 2021 13:54:58 +0800 +Subject: [PATCH] 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. + +Upstream: 6bf383c37e6131a8e247e8a0997d55d65c830b6d +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + fixincludes/fixfixes.c | 45 ++++++++++++++++++++++++++++++-- + fixincludes/inclhack.def | 3 ++- + fixincludes/tests/base/testing.h | 2 +- + 3 files changed, 46 insertions(+), 4 deletions(-) + +diff --git a/fixincludes/fixfixes.c b/fixincludes/fixfixes.c +index 034e15d9985..3ff87812036 100644 +--- a/fixincludes/fixfixes.c ++++ b/fixincludes/fixfixes.c +@@ -477,6 +477,39 @@ FIX_PROC_HEAD( char_macro_def_fix ) + fputs (text, stdout); + } + ++/* Check if the pattern at pos is actually in a "__has_include(...)" ++ directive. Return the pointer to the ')' of this ++ "__has_include(...)" if it is, NULL otherwise. */ ++static const char * ++check_has_inc (const char *begin, const char *pos, const char *end) ++{ ++ static const char has_inc[] = "__has_include"; ++ const size_t has_inc_len = sizeof (has_inc) - 1; ++ const char *p; ++ ++ for (p = memmem (begin, pos - begin, has_inc, has_inc_len); ++ p != NULL; ++ p = memmem (p, pos - p, has_inc, has_inc_len)) ++ { ++ p += has_inc_len; ++ while (p < end && ISSPACE (*p)) ++ p++; ++ ++ /* "__has_include" may appear as "defined(__has_include)", ++ search for the next appearance then. */ ++ if (*p != '(') ++ continue; ++ ++ /* To avoid too much complexity, just hope there is never a ++ ')' in a header name. */ ++ p = memchr (p, ')', end - p); ++ if (p == NULL || p > pos) ++ return p; ++ } ++ ++ return NULL; ++} ++ + /* Fix for machine name #ifdefs that are not in the namespace reserved + by the C standard. They won't be defined if compiling with -ansi, + and the headers will break. We go to some trouble to only change +@@ -524,7 +557,7 @@ FIX_PROC_HEAD( machine_name_fix ) + /* If the 'name_pat' matches in between base and limit, we have + a bogon. It is not worth the hassle of excluding comments + because comments on #if/#ifdef lines are rare, and strings on +- such lines are illegal. ++ such lines are only legal in a "__has_include" directive. + + REG_NOTBOL means 'base' is not at the beginning of a line, which + shouldn't matter since the name_re has no ^ anchor, but let's +@@ -544,8 +577,16 @@ FIX_PROC_HEAD( machine_name_fix ) + break; + + p = base + match[0].rm_so; +- base += match[0].rm_eo; + ++ /* Check if the match is in __has_include(...) (PR 91085). */ ++ q = check_has_inc (base, p, limit); ++ if (q) ++ { ++ base = q + 1; ++ goto again; ++ } ++ ++ base += match[0].rm_eo; + /* One more test: if on the same line we have the same string + with the appropriate underscores, then leave it alone. + We want exactly two leading and trailing underscores. */ +diff --git a/fixincludes/inclhack.def b/fixincludes/inclhack.def +index f58e7771e1c..71bd717c233 100644 +--- a/fixincludes/inclhack.def ++++ b/fixincludes/inclhack.def +@@ -3114,7 +3114,8 @@ fix = { + c_fix = machine_name; + + test_text = "/* MACH_DIFF: */\n" +- "#if defined( i386 ) || defined( sparc ) || defined( vax )" ++ "#if defined( i386 ) || defined( sparc ) || defined( vax ) || " ++ "defined( linux ) || __has_include ( <linux.h> )" + "\n/* no uniform test, so be careful :-) */"; + }; + +diff --git a/fixincludes/tests/base/testing.h b/fixincludes/tests/base/testing.h +index cf95321fb86..8b3accaf04e 100644 +--- a/fixincludes/tests/base/testing.h ++++ b/fixincludes/tests/base/testing.h +@@ -64,7 +64,7 @@ BSD43__IOWR('T', 1) /* Some are multi-line */ + + #if defined( MACHINE_NAME_CHECK ) + /* MACH_DIFF: */ +-#if defined( i386 ) || defined( sparc ) || defined( vax ) ++#if defined( i386 ) || defined( sparc ) || defined( vax ) || defined( linux ) || __has_include ( <linux.h> ) + /* no uniform test, so be careful :-) */ + #endif /* MACHINE_NAME_CHECK */ + +-- +2.37.3 +package/gcc/11.3.0/0007-fixinc-don-t-fix-machine-names-in-__has_include-.-PR.patch new file +124
-0@@ -0,0 +1,124 @@ +From de3f4ee9a5bd2adcb5ff2e1690db2567fda1473c Mon Sep 17 00:00:00 2001 +From: Xi Ruoyao <[email protected]> +Date: Mon, 28 Jun 2021 13:54:58 +0800 +Subject: [PATCH] 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. + +Upstream: 6bf383c37e6131a8e247e8a0997d55d65c830b6d +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + fixincludes/fixfixes.c | 45 ++++++++++++++++++++++++++++++-- + fixincludes/inclhack.def | 3 ++- + fixincludes/tests/base/testing.h | 2 +- + 3 files changed, 46 insertions(+), 4 deletions(-) + +diff --git a/fixincludes/fixfixes.c b/fixincludes/fixfixes.c +index 5b23a8b640d..404b420f302 100644 +--- a/fixincludes/fixfixes.c ++++ b/fixincludes/fixfixes.c +@@ -477,6 +477,39 @@ FIX_PROC_HEAD( char_macro_def_fix ) + fputs (text, stdout); + } + ++/* Check if the pattern at pos is actually in a "__has_include(...)" ++ directive. Return the pointer to the ')' of this ++ "__has_include(...)" if it is, NULL otherwise. */ ++static const char * ++check_has_inc (const char *begin, const char *pos, const char *end) ++{ ++ static const char has_inc[] = "__has_include"; ++ const size_t has_inc_len = sizeof (has_inc) - 1; ++ const char *p; ++ ++ for (p = memmem (begin, pos - begin, has_inc, has_inc_len); ++ p != NULL; ++ p = memmem (p, pos - p, has_inc, has_inc_len)) ++ { ++ p += has_inc_len; ++ while (p < end && ISSPACE (*p)) ++ p++; ++ ++ /* "__has_include" may appear as "defined(__has_include)", ++ search for the next appearance then. */ ++ if (*p != '(') ++ continue; ++ ++ /* To avoid too much complexity, just hope there is never a ++ ')' in a header name. */ ++ p = memchr (p, ')', end - p); ++ if (p == NULL || p > pos) ++ return p; ++ } ++ ++ return NULL; ++} ++ + /* Fix for machine name #ifdefs that are not in the namespace reserved + by the C standard. They won't be defined if compiling with -ansi, + and the headers will break. We go to some trouble to only change +@@ -524,7 +557,7 @@ FIX_PROC_HEAD( machine_name_fix ) + /* If the 'name_pat' matches in between base and limit, we have + a bogon. It is not worth the hassle of excluding comments + because comments on #if/#ifdef lines are rare, and strings on +- such lines are illegal. ++ such lines are only legal in a "__has_include" directive. + + REG_NOTBOL means 'base' is not at the beginning of a line, which + shouldn't matter since the name_re has no ^ anchor, but let's +@@ -544,8 +577,16 @@ FIX_PROC_HEAD( machine_name_fix ) + break; + + p = base + match[0].rm_so; +- base += match[0].rm_eo; + ++ /* Check if the match is in __has_include(...) (PR 91085). */ ++ q = check_has_inc (base, p, limit); ++ if (q) ++ { ++ base = q + 1; ++ goto again; ++ } ++ ++ base += match[0].rm_eo; + /* One more test: if on the same line we have the same string + with the appropriate underscores, then leave it alone. + We want exactly two leading and trailing underscores. */ +diff --git a/fixincludes/inclhack.def b/fixincludes/inclhack.def +index 066bef99162..b7ad6982e96 100644 +--- a/fixincludes/inclhack.def ++++ b/fixincludes/inclhack.def +@@ -3154,7 +3154,8 @@ fix = { + c_fix = machine_name; + + test_text = "/* MACH_DIFF: */\n" +- "#if defined( i386 ) || defined( sparc ) || defined( vax )" ++ "#if defined( i386 ) || defined( sparc ) || defined( vax ) || " ++ "defined( linux ) || __has_include ( <linux.h> )" + "\n/* no uniform test, so be careful :-) */"; + }; + +diff --git a/fixincludes/tests/base/testing.h b/fixincludes/tests/base/testing.h +index cf95321fb86..8b3accaf04e 100644 +--- a/fixincludes/tests/base/testing.h ++++ b/fixincludes/tests/base/testing.h +@@ -64,7 +64,7 @@ BSD43__IOWR('T', 1) /* Some are multi-line */ + + #if defined( MACHINE_NAME_CHECK ) + /* MACH_DIFF: */ +-#if defined( i386 ) || defined( sparc ) || defined( vax ) ++#if defined( i386 ) || defined( sparc ) || defined( vax ) || defined( linux ) || __has_include ( <linux.h> ) + /* no uniform test, so be careful :-) */ + #endif /* MACHINE_NAME_CHECK */ + +-- +2.37.3 +package/gcc/arc-2020.09-release/0003-fixinc-don-t-fix-machine-names-in-__has_include-.-PR.patch new file +114
-0@@ -0,0 +1,124 @@ +From 65754c50a57e5a891cee75bb744eb93fdb3c443e Mon Sep 17 00:00:00 2001 +From: Xi Ruoyao <[email protected]> +Date: Mon, 28 Jun 2021 13:54:58 +0800 +Subject: [PATCH] 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. + +Upstream: 6bf383c37e6131a8e247e8a0997d55d65c830b6d +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + fixincludes/fixfixes.c | 45 ++++++++++++++++++++++++++++++-- + fixincludes/inclhack.def | 3 ++- + fixincludes/tests/base/testing.h | 2 +- + 3 files changed, 46 insertions(+), 4 deletions(-) + +diff --git a/fixincludes/fixfixes.c b/fixincludes/fixfixes.c +index 034e15d9985..3ff87812036 100644 +--- a/fixincludes/fixfixes.c ++++ b/fixincludes/fixfixes.c +@@ -477,6 +477,39 @@ FIX_PROC_HEAD( char_macro_def_fix ) + fputs (text, stdout); + } + ++/* Check if the pattern at pos is actually in a "__has_include(...)" ++ directive. Return the pointer to the ')' of this ++ "__has_include(...)" if it is, NULL otherwise. */ ++static const char * ++check_has_inc (const char *begin, const char *pos, const char *end) ++{ ++ static const char has_inc[] = "__has_include"; ++ const size_t has_inc_len = sizeof (has_inc) - 1; ++ const char *p; ++ ++ for (p = memmem (begin, pos - begin, has_inc, has_inc_len); ++ p != NULL; ++ p = memmem (p, pos - p, has_inc, has_inc_len)) ++ { ++ p += has_inc_len; ++ while (p < end && ISSPACE (*p)) ++ p++; ++ ++ /* "__has_include" may appear as "defined(__has_include)", ++ search for the next appearance then. */ ++ if (*p != '(') ++ continue; ++ ++ /* To avoid too much complexity, just hope there is never a ++ ')' in a header name. */ ++ p = memchr (p, ')', end - p); ++ if (p == NULL || p > pos) ++ return p; ++ } ++ ++ return NULL; ++} ++ + /* Fix for machine name #ifdefs that are not in the namespace reserved + by the C standard. They won't be defined if compiling with -ansi, + and the headers will break. We go to some trouble to only change +@@ -524,7 +557,7 @@ FIX_PROC_HEAD( machine_name_fix ) + /* If the 'name_pat' matches in between base and limit, we have + a bogon. It is not worth the hassle of excluding comments + because comments on #if/#ifdef lines are rare, and strings on +- such lines are illegal. ++ such lines are only legal in a "__has_include" directive. + + REG_NOTBOL means 'base' is not at the beginning of a line, which + shouldn't matter since the name_re has no ^ anchor, but let's +@@ -544,8 +577,16 @@ FIX_PROC_HEAD( machine_name_fix ) + break; + + p = base + match[0].rm_so; +- base += match[0].rm_eo; + ++ /* Check if the match is in __has_include(...) (PR 91085). */ ++ q = check_has_inc (base, p, limit); ++ if (q) ++ { ++ base = q + 1; ++ goto again; ++ } ++ ++ base += match[0].rm_eo; + /* One more test: if on the same line we have the same string + with the appropriate underscores, then leave it alone. + We want exactly two leading and trailing underscores. */ +diff --git a/fixincludes/inclhack.def b/fixincludes/inclhack.def +index f58e7771e1c..71bd717c233 100644 +--- a/fixincludes/inclhack.def ++++ b/fixincludes/inclhack.def +@@ -3114,7 +3114,8 @@ fix = { + c_fix = machine_name; + + test_text = "/* MACH_DIFF: */\n" +- "#if defined( i386 ) || defined( sparc ) || defined( vax )" ++ "#if defined( i386 ) || defined( sparc ) || defined( vax ) || " ++ "defined( linux ) || __has_include ( <linux.h> )" + "\n/* no uniform test, so be careful :-) */"; + }; + +diff --git a/fixincludes/tests/base/testing.h b/fixincludes/tests/base/testing.h +index cf95321fb86..8b3accaf04e 100644 +--- a/fixincludes/tests/base/testing.h ++++ b/fixincludes/tests/base/testing.h +@@ -64,7 +64,7 @@ BSD43__IOWR('T', 1) /* Some are multi-line */ +
package/gcc/arc-2020.09-release/0003-fixinc-don-t-fix-machine-names-in-__has_include-.-PR.patch line 124
Quoted 10 lines
package/gcc/arc-2020.09-release/0003-fixinc-don-t-fix-machine-names-in-__has_include-.-PR.patch new file +10
-0+ #if defined( MACHINE_NAME_CHECK ) + /* MACH_DIFF: */ +-#if defined( i386 ) || defined( sparc ) || defined( vax ) ++#if defined( i386 ) || defined( sparc ) || defined( vax ) || defined( linux ) || __has_include ( <linux.h> ) + /* no uniform test, so be careful :-) */ + #endif /* MACHINE_NAME_CHECK */ + +-- +2.37.3 +
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
Thomas Petazzoni via buildroot
AppliedQuoted 60 lines · On Tue, 25 Oct 2022 22:13:59 +0200 Thomas Petazzoni via buildroot…
This commit backports the patch "fixinc: don't "fix" machine names in
__has_include(...)" from upstream GCC, which is needed to resolve a header conflict between glibc headers and kernel headers, which has appeared since we bumped glibc to version 2.36 in commit80c8c15c8534a24382b900a07082a289a368f736.The problem comes from the "fixinc" logic used by gcc to fixup some headers files, generated inside an include-fixed/ folder. This logic ended up replacing "
linux/mount.h" by "__linux__/mount.h" in__has_include()invocation, like this:#ifdef
__has_include# if __has_include ("__linux__/mount.h") # include "linux/mount.h" # endif #endifin
build/host-gcc-final-11.3.0/build/gcc/include-fixed/sys/mount.h. With this fix in place, this "include-fixed" header is no longer generated, avoiding the problem.This issue was visible in two different ways in glibc configurations:
- As a build failure during the gcc build itself, for architectures that support libsanitizer, as libsanitizer includes
mount.h, and would therefore encounter the header conflict.- As a build failure during another user-space package (such as sysvinit for example), on architectures when libsanitizer isn't used, and therefore for which the gcc build was successful, but the header conflict shows up when building some "random" user-space package.
The problem is already fixed in GCC 12.2.0, so no patch is required. The problem did not exist back in GCC 8.4.0, so this version does not need patching. Consequently, the patch is only needed for GCC 10.4.0, GCC 11.3.0 and the special ARC 2020.09-release version.
Fixes:
(gcc build issue, on architecture that supports libsanitizer)
http://autobuild.buildroot.net/results/90fe4c3b8b72a2c28555674383de9bbd9e8ae09a/(sysvinit build issue, on architecture that does not support libsanitizer)
http://autobuild.buildroot.net/results/d7bf5795b7621a92be32f18794e3e67944fb96db/(crun)
http://autobuild.buildroot.net/results/e3e8da4f797dced48aedf8c636db983d36849850/(libarchive)
http://autobuild.buildroot.net/results/9fcbf0c036a97b2e9a4fcc6e173bcfa09e1b3dac/Thanks a lot to Peter Seiderer for pointing the relevant GCC commit.
Fixes:
https://bugs.busybox.net/show_bug.cgi?id=15021
Signed-off-by Thomas Petazzoni <[email protected]>
Quoted 8 lines
--- ...-machine-names-in-__has_include-.-PR.patch | 124 ++++++++++++++++++ ...-machine-names-in-__has_include-.-PR.patch | 124 ++++++++++++++++++ ...-machine-names-in-__has_include-.-PR.patch | 124 ++++++++++++++++++ 3 files changed, 372 insertions(+) create mode 100644 package/gcc/10.4.0/0006-fixinc-don-t-fix-machine-names-in-__has_include-.-PR.patch create mode 100644 package/gcc/11.3.0/0007-fixinc-don-t-fix-machine-names-in-__has_include-.-PR.patch create mode 100644 package/gcc/arc-2020.09-release/0003-fixinc-don-t-fix-machine-names-in-__has_include-.-PR.patch
Applied to master, thanks.
Thomas
Signature · 7 lines
Thomas Petazzoni, CTO, Bootlin Embedded Linux and Kernel engineering https://bootlin.com _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot