commit:     14dd0724ad00c2968202e46b4fc11f6f18cb440f
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Tue May 16 23:11:59 2023 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Tue May 16 23:11:59 2023 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=14dd0724

sys-devel/clang-common: add maybe-stddefs.h helper

This is needed for musl (and any non-glibc target actually) with Clang, as
GCC adds it by itself (but glibc covers for the compiler even if it doesn't),
but neither Clang nor musl include it by themselves.

See also:
- https://www.openwall.com/lists/musl/2021/04/16/8
- https://reviews.llvm.org/D34158
- https://reviews.llvm.org/D106577
- https://reviews.llvm.org/D137043

Closes: https://bugs.gentoo.org/870001
Signed-off-by: Sam James <sam <AT> gentoo.org>

 ...mmon-16.0.4.9999.ebuild => clang-common-16.0.3-r1.ebuild} | 12 +++++++++++-
 sys-devel/clang-common/clang-common-16.0.4.9999.ebuild       | 10 ++++++++++
 sys-devel/clang-common/clang-common-17.0.0.9999.ebuild       | 10 ++++++++++
 .../clang-common/clang-common-17.0.0_pre20230502.ebuild      | 10 ++++++++++
 .../clang-common/clang-common-17.0.0_pre20230512.ebuild      | 10 ++++++++++
 5 files changed, 51 insertions(+), 1 deletion(-)

diff --git a/sys-devel/clang-common/clang-common-16.0.4.9999.ebuild 
b/sys-devel/clang-common/clang-common-16.0.3-r1.ebuild
similarity index 92%
copy from sys-devel/clang-common/clang-common-16.0.4.9999.ebuild
copy to sys-devel/clang-common/clang-common-16.0.3-r1.ebuild
index 5b4a6647f3ca..0d894d8b4232 100644
--- a/sys-devel/clang-common/clang-common-16.0.4.9999.ebuild
+++ b/sys-devel/clang-common/clang-common-16.0.3-r1.ebuild
@@ -10,7 +10,7 @@ HOMEPAGE="https://llvm.org/";
 
 LICENSE="Apache-2.0-with-LLVM-exceptions UoI-NCSA"
 SLOT="0"
-KEYWORDS=""
+KEYWORDS="~amd64 ~arm ~arm64 ~loong ~ppc ~ppc64 ~riscv ~sparc ~x86 
~amd64-linux ~ppc-macos ~x64-macos"
 IUSE="
        default-compiler-rt default-libcxx default-lld llvm-libunwind
        hardened stricter
@@ -87,6 +87,8 @@ src_install() {
                @gentoo-runtimes.cfg
                @gentoo-gcc-install.cfg
                @gentoo-hardened.cfg
+               # bug #870001
+               -include "${EPREFIX}/usr/include/gentoo/maybe-stddefs.h"
        EOF
 
        # Baseline hardening (bug #851111)
@@ -101,6 +103,14 @@ src_install() {
 
        dodir /usr/include/gentoo
 
+       cat >> "${ED}/usr/include/gentoo/maybe-stddefs.h" <<-EOF || die
+       /* __has_include is an extension, but it's fine, because this is only
+       for Clang anyway. */
+       #if defined __has_include && __has_include (<stdc-predef.h>)
+       # include <stdc-predef.h>
+       #endif
+       EOF
+
        local fortify_level=$(usex hardened 3 2)
        # We have to do this because glibc's headers warn if F_S is set
        # without optimization and that would at the very least be very noisy

diff --git a/sys-devel/clang-common/clang-common-16.0.4.9999.ebuild 
b/sys-devel/clang-common/clang-common-16.0.4.9999.ebuild
index 5b4a6647f3ca..ffae670e7202 100644
--- a/sys-devel/clang-common/clang-common-16.0.4.9999.ebuild
+++ b/sys-devel/clang-common/clang-common-16.0.4.9999.ebuild
@@ -87,6 +87,8 @@ src_install() {
                @gentoo-runtimes.cfg
                @gentoo-gcc-install.cfg
                @gentoo-hardened.cfg
+               # bug #870001
+               -include "${EPREFIX}/usr/include/gentoo/maybe-stddefs.h"
        EOF
 
        # Baseline hardening (bug #851111)
@@ -101,6 +103,14 @@ src_install() {
 
        dodir /usr/include/gentoo
 
+       cat >> "${ED}/usr/include/gentoo/maybe-stddefs.h" <<-EOF || die
+       /* __has_include is an extension, but it's fine, because this is only
+       for Clang anyway. */
+       #if defined __has_include && __has_include (<stdc-predef.h>)
+       # include <stdc-predef.h>
+       #endif
+       EOF
+
        local fortify_level=$(usex hardened 3 2)
        # We have to do this because glibc's headers warn if F_S is set
        # without optimization and that would at the very least be very noisy

diff --git a/sys-devel/clang-common/clang-common-17.0.0.9999.ebuild 
b/sys-devel/clang-common/clang-common-17.0.0.9999.ebuild
index 5b4a6647f3ca..ffae670e7202 100644
--- a/sys-devel/clang-common/clang-common-17.0.0.9999.ebuild
+++ b/sys-devel/clang-common/clang-common-17.0.0.9999.ebuild
@@ -87,6 +87,8 @@ src_install() {
                @gentoo-runtimes.cfg
                @gentoo-gcc-install.cfg
                @gentoo-hardened.cfg
+               # bug #870001
+               -include "${EPREFIX}/usr/include/gentoo/maybe-stddefs.h"
        EOF
 
        # Baseline hardening (bug #851111)
@@ -101,6 +103,14 @@ src_install() {
 
        dodir /usr/include/gentoo
 
+       cat >> "${ED}/usr/include/gentoo/maybe-stddefs.h" <<-EOF || die
+       /* __has_include is an extension, but it's fine, because this is only
+       for Clang anyway. */
+       #if defined __has_include && __has_include (<stdc-predef.h>)
+       # include <stdc-predef.h>
+       #endif
+       EOF
+
        local fortify_level=$(usex hardened 3 2)
        # We have to do this because glibc's headers warn if F_S is set
        # without optimization and that would at the very least be very noisy

diff --git a/sys-devel/clang-common/clang-common-17.0.0_pre20230502.ebuild 
b/sys-devel/clang-common/clang-common-17.0.0_pre20230502.ebuild
index 5b4a6647f3ca..ffae670e7202 100644
--- a/sys-devel/clang-common/clang-common-17.0.0_pre20230502.ebuild
+++ b/sys-devel/clang-common/clang-common-17.0.0_pre20230502.ebuild
@@ -87,6 +87,8 @@ src_install() {
                @gentoo-runtimes.cfg
                @gentoo-gcc-install.cfg
                @gentoo-hardened.cfg
+               # bug #870001
+               -include "${EPREFIX}/usr/include/gentoo/maybe-stddefs.h"
        EOF
 
        # Baseline hardening (bug #851111)
@@ -101,6 +103,14 @@ src_install() {
 
        dodir /usr/include/gentoo
 
+       cat >> "${ED}/usr/include/gentoo/maybe-stddefs.h" <<-EOF || die
+       /* __has_include is an extension, but it's fine, because this is only
+       for Clang anyway. */
+       #if defined __has_include && __has_include (<stdc-predef.h>)
+       # include <stdc-predef.h>
+       #endif
+       EOF
+
        local fortify_level=$(usex hardened 3 2)
        # We have to do this because glibc's headers warn if F_S is set
        # without optimization and that would at the very least be very noisy

diff --git a/sys-devel/clang-common/clang-common-17.0.0_pre20230512.ebuild 
b/sys-devel/clang-common/clang-common-17.0.0_pre20230512.ebuild
index 5b4a6647f3ca..ffae670e7202 100644
--- a/sys-devel/clang-common/clang-common-17.0.0_pre20230512.ebuild
+++ b/sys-devel/clang-common/clang-common-17.0.0_pre20230512.ebuild
@@ -87,6 +87,8 @@ src_install() {
                @gentoo-runtimes.cfg
                @gentoo-gcc-install.cfg
                @gentoo-hardened.cfg
+               # bug #870001
+               -include "${EPREFIX}/usr/include/gentoo/maybe-stddefs.h"
        EOF
 
        # Baseline hardening (bug #851111)
@@ -101,6 +103,14 @@ src_install() {
 
        dodir /usr/include/gentoo
 
+       cat >> "${ED}/usr/include/gentoo/maybe-stddefs.h" <<-EOF || die
+       /* __has_include is an extension, but it's fine, because this is only
+       for Clang anyway. */
+       #if defined __has_include && __has_include (<stdc-predef.h>)
+       # include <stdc-predef.h>
+       #endif
+       EOF
+
        local fortify_level=$(usex hardened 3 2)
        # We have to do this because glibc's headers warn if F_S is set
        # without optimization and that would at the very least be very noisy

Reply via email to