commit:     eb84c4b6a972b074bc60f64d3348e93602795df1
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Tue May 24 22:27:45 2022 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Tue May 24 22:35:50 2022 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=eb84c4b6

sys-apps/systemd: add 251.1

- Revert FORTIFY_SOURCE=3 patch for now as it breaks Clang (even without
setting F_S=3, or seemingly F_S at all, as we don't patch Clang to add that
in the way we do with GCC)

- Turn off F_S=3 accordingly given we've had to revert the patch which
fixes support for it.

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

 sys-apps/systemd/Manifest                          |  1 +
 .../files/251-revert-fortify-source-3-fix.patch    | 40 ++++++++++++++++++++++
 .../{systemd-9999.ebuild => systemd-251.1.ebuild}  | 21 +++++++++++-
 sys-apps/systemd/systemd-9999.ebuild               | 20 ++++++++++-
 4 files changed, 80 insertions(+), 2 deletions(-)

diff --git a/sys-apps/systemd/Manifest b/sys-apps/systemd/Manifest
index 9b589c708f7e..a12a4d846fc0 100644
--- a/sys-apps/systemd/Manifest
+++ b/sys-apps/systemd/Manifest
@@ -1,3 +1,4 @@
 DIST systemd-251.tar.gz 11431104 BLAKE2B 
da783d815adf244defc3c1ec8a788fffdff45215f5c2449c457e872ad89b8270caa3e48ecb696fa79eb1d79578ded3d098802fed0fc69a191ba2d7d6b120e068
 SHA512 
5a7116cfd99f7875334a1ce55a76ba1840a28b6500b02de82b879629768e10457efd8278024aa1ffefd43defe657284c4d51ab502ed3c7e6b63d5b6e0cc1f642
 DIST systemd-stable-250.4.tar.gz 11132786 BLAKE2B 
8fdfe1bad76e572dc1be0955f3d1c4080f2beb81a2f9670f80827899f5406ab8ed8675400c2f5e8ccef44cf1bceff42ceae12a42e1b67d46c0deb523e6495f25
 SHA512 
307ed0920da660b6c45d909fea66864fb98db8b2f6905d629fb2012fc4bf64dd25fd61168c22bf4098200be541be9b0e815fbde98806a99c85cb33d49d8b63d0
 DIST systemd-stable-250.5.tar.gz 11212059 BLAKE2B 
b7dbcb9e82c51e966db20a92ccd59ac19309702c481dd575c4e6367ca5ade10fe4b689925416ce1169682380cbf22d7d692b2378ef091f3007c16891992e3f92
 SHA512 
ad864b67bd5e2f5fd5705b636467827e4735142cefba150d24bb8e51ac0263650b2b0e53d4426eb509d1db59b83dc3b4c4bf157cc355fc2b7524db6bc4a9b5cd
+DIST systemd-stable-251.1.tar.gz 11431880 BLAKE2B 
0442489242b2fbfb316f207c7c8c718322a1ea2af8176378fb39bea441fdd8bbb36ea840af9bdec257b714f5f3099daa1139bc6df6ca6f0c2f467c59013fba92
 SHA512 
6fc72197b684abc343480acb66b8f749c186bd7a031ddd757c4a0e5fd8fdeda0cde9c9e634fd3d9e2b2d1ed96019c5f8e7119ad10a7f51d5dc13fac2571c6c70

diff --git a/sys-apps/systemd/files/251-revert-fortify-source-3-fix.patch 
b/sys-apps/systemd/files/251-revert-fortify-source-3-fix.patch
new file mode 100644
index 000000000000..bbe45f85dcf2
--- /dev/null
+++ b/sys-apps/systemd/files/251-revert-fortify-source-3-fix.patch
@@ -0,0 +1,40 @@
+From: Sam James <[email protected]>
+Date: Tue, 24 May 2022 23:21:50 +0100
+Subject: [PATCH] Revert "Support -D_FORTIFY_SOURCE=3 by using
+ __builtin_dynamic_object_size."
+
+Breaks Clang (even without F_S=3).
+
+This reverts commit 0bd292567a543d124cd303f7dd61169a209cae64.
+
+Bug: https://bugs.gentoo.org/841770
+Bug: https://github.com/systemd/systemd/issues/23150
+--- a/src/basic/alloc-util.h
++++ b/src/basic/alloc-util.h
+@@ -174,23 +174,13 @@ void* greedy_realloc0(void **p, size_t need, size_t 
size);
+  * is compatible with _FORTIFY_SOURCES. If _FORTIFY_SOURCES is used many 
memory operations will take the
+  * object size as returned by __builtin_object_size() into account. Hence, 
let's return the smaller size of
+  * malloc_usable_size() and __builtin_object_size() here, so that we 
definitely operate in safe territory by
+- * both the compiler's and libc's standards. Note that _FORTIFY_SOURCES=3 
handles also dynamically allocated
+- * objects and thus it's safer using __builtin_dynamic_object_size if 
_FORTIFY_SOURCES=3 is used (#22801).
+- * Moreover, when NULL is passed malloc_usable_size() is documented to return 
zero, and
++ * both the compiler's and libc's standards. Note that 
__builtin_object_size() evaluates to SIZE_MAX if the
++ * size cannot be determined, hence the MIN() expression should be safe with 
dynamically sized memory,
++ * too. Moreover, when NULL is passed malloc_usable_size() is documented to 
return zero, and
+  * __builtin_object_size() returns SIZE_MAX too, hence we also return a 
sensible value of 0 in this corner
+  * case. */
+-
+-#if defined __has_builtin
+-#  if __has_builtin(__builtin_dynamic_object_size)
+-#    define MALLOC_SIZEOF_SAFE(x) \
+-        MIN(malloc_usable_size(x), __builtin_dynamic_object_size(x, 0))
+-#  endif
+-#endif
+-
+-#ifndef MALLOC_SIZEOF_SAFE
+ #define MALLOC_SIZEOF_SAFE(x) \
+         MIN(malloc_usable_size(x), __builtin_object_size(x, 0))
+-#endif
+ 
+ /* Inspired by ELEMENTSOF() but operates on malloc()'ed memory areas: 
typesafely returns the number of items
+  * that fit into the specified memory block */

diff --git a/sys-apps/systemd/systemd-9999.ebuild 
b/sys-apps/systemd/systemd-251.1.ebuild
similarity index 94%
copy from sys-apps/systemd/systemd-9999.ebuild
copy to sys-apps/systemd/systemd-251.1.ebuild
index 8d12de0b47a7..9381570446ab 100644
--- a/sys-apps/systemd/systemd-9999.ebuild
+++ b/sys-apps/systemd/systemd-251.1.ebuild
@@ -23,7 +23,7 @@ else
        KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~loong ~mips ~ppc 
~ppc64 ~riscv ~s390 ~sparc ~x86"
 fi
 
-inherit bash-completion-r1 linux-info meson-multilib pam python-any-r1 systemd 
toolchain-funcs udev usr-ldscript
+inherit bash-completion-r1 flag-o-matic linux-info meson-multilib pam 
python-any-r1 systemd toolchain-funcs udev usr-ldscript
 
 DESCRIPTION="System and service manager for Linux"
 HOMEPAGE="https://www.freedesktop.org/wiki/Software/systemd";
@@ -235,6 +235,10 @@ src_prepare() {
 
        # Add local patches here
        PATCHES+=(
+               "${FILESDIR}/251-format-string.patch"
+               # Breaks Clang. Revert the commit for now and force off F_S=3.
+               # bug #841770.
+               "${FILESDIR}/251-revert-fortify-source-3-fix.patch"
        )
 
        if ! use vanilla; then
@@ -255,6 +259,21 @@ src_configure() {
        # Prevent conflicts with i686 cross toolchain, bug 559726
        tc-export AR CC NM OBJCOPY RANLIB
 
+       # Broken with FORTIFY_SOURCE=3 without a patch. We have to revert
+       # the upstream patch for it because it breaks Clang: bug #841770.
+       #
+       # Our toolchain sets F_S=2 by default w/ >= -O2, so we need
+       # to unset F_S first, then explicitly set 2, to negate any default
+       # and anything set by the user if they're choosing 3 (or if they've
+       # modified GCC to set 3).
+       #
+       if is-flagq '-O[23]' || is-flagq '-Ofast' ; then
+               # We can't unconditionally do this b/c we fortify needs
+               # some level of optimisation.
+               filter-flags -D_FORTIFY_SOURCE=3
+               append-cppflags -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2
+       fi
+
        python_setup
 
        multilib-minimal_src_configure

diff --git a/sys-apps/systemd/systemd-9999.ebuild 
b/sys-apps/systemd/systemd-9999.ebuild
index 8d12de0b47a7..efeb0fe26832 100644
--- a/sys-apps/systemd/systemd-9999.ebuild
+++ b/sys-apps/systemd/systemd-9999.ebuild
@@ -23,7 +23,7 @@ else
        KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~loong ~mips ~ppc 
~ppc64 ~riscv ~s390 ~sparc ~x86"
 fi
 
-inherit bash-completion-r1 linux-info meson-multilib pam python-any-r1 systemd 
toolchain-funcs udev usr-ldscript
+inherit bash-completion-r1 flag-o-matic linux-info meson-multilib pam 
python-any-r1 systemd toolchain-funcs udev usr-ldscript
 
 DESCRIPTION="System and service manager for Linux"
 HOMEPAGE="https://www.freedesktop.org/wiki/Software/systemd";
@@ -235,6 +235,9 @@ src_prepare() {
 
        # Add local patches here
        PATCHES+=(
+               # Breaks Clang. Revert the commit for now and force off F_S=3.
+               # bug #841770.
+               "${FILESDIR}/251-revert-fortify-source-3-fix.patch"
        )
 
        if ! use vanilla; then
@@ -255,6 +258,21 @@ src_configure() {
        # Prevent conflicts with i686 cross toolchain, bug 559726
        tc-export AR CC NM OBJCOPY RANLIB
 
+       # Broken with FORTIFY_SOURCE=3 without a patch. We have to revert
+       # the upstream patch for it because it breaks Clang: bug #841770.
+       #
+       # Our toolchain sets F_S=2 by default w/ >= -O2, so we need
+       # to unset F_S first, then explicitly set 2, to negate any default
+       # and anything set by the user if they're choosing 3 (or if they've
+       # modified GCC to set 3).
+       #
+       if is-flagq '-O[23]' || is-flagq '-Ofast' ; then
+               # We can't unconditionally do this b/c we fortify needs
+               # some level of optimisation.
+               filter-flags -D_FORTIFY_SOURCE=3
+               append-cppflags -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2
+       fi
+
        python_setup
 
        multilib-minimal_src_configure

Reply via email to