commit:     e1648aa7703597e93e73cbaf801eddbfc3784b6d
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Sun Oct 16 20:51:48 2022 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Sun Oct 16 21:47:22 2022 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=e1648aa7

dev-libs/apr: fix miscompilation w/ Clang 16

I've not sent these upstream unfortunately, for a few reasons:
- a bunch of it is already there;
- we have a huge backlog of patches we need to rebase/upstream;
- upstream are way overdue a release in the 1.7.x branch (and it's a mess
atm)

Let's revisit this on the next release when it should be much easier.

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

 dev-libs/apr/apr-1.7.0-r6.ebuild            | 163 ++++++++++++++++++++++++++
 dev-libs/apr/files/apr-1.7.0-clang-16.patch | 174 ++++++++++++++++++++++++++++
 2 files changed, 337 insertions(+)

diff --git a/dev-libs/apr/apr-1.7.0-r6.ebuild b/dev-libs/apr/apr-1.7.0-r6.ebuild
new file mode 100644
index 000000000000..4ba3505bd8f8
--- /dev/null
+++ b/dev-libs/apr/apr-1.7.0-r6.ebuild
@@ -0,0 +1,163 @@
+# Copyright 1999-2022 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=7
+
+inherit autotools libtool toolchain-funcs
+
+DESCRIPTION="Apache Portable Runtime Library"
+HOMEPAGE="https://apr.apache.org/";
+SRC_URI="mirror://apache/apr/${P}.tar.bz2"
+
+LICENSE="Apache-2.0"
+SLOT="1/${PV%.*}"
+KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~loong ~mips ~ppc ~ppc64 
~riscv ~s390 ~sparc ~x86 ~x64-cygwin ~amd64-linux ~x86-linux ~ppc-macos 
~x64-macos ~sparc-solaris ~sparc64-solaris ~x64-solaris ~x86-solaris"
+IUSE="doc older-kernels-compatibility selinux static-libs +urandom"
+
+# See bug #815265 for libcrypt dependency
+CDEPEND="virtual/libcrypt:=
+       elibc_glibc? ( >=sys-apps/util-linux-2.16 )"
+RDEPEND="${CDEPEND}
+       selinux? ( sec-policy/selinux-base-policy )"
+DEPEND="${CDEPEND}
+       >=sys-devel/libtool-2.4.2
+       doc? ( app-doc/doxygen )"
+
+DOCS=( CHANGES NOTICE README )
+
+PATCHES=(
+       "${FILESDIR}"/${PN}-1.5.0-mint.patch
+       "${FILESDIR}"/${PN}-1.5.0-libtool.patch
+       "${FILESDIR}"/${PN}-1.5.0-cross-types.patch
+       "${FILESDIR}"/${PN}-1.5.0-sysroot.patch #385775
+       "${FILESDIR}"/${PN}-1.6.3-skip-known-failing-tests.patch
+       "${FILESDIR}"/${PN}-1.7.0-autoconf-2.70.patch #750353
+       "${FILESDIR}"/${PN}-1.7.0-CVE-2021-35940.patch #828545
+       "${FILESDIR}"/${PN}-1.7.0-clang-16.patch #870004
+)
+
+src_prepare() {
+       default
+
+       mv configure.in configure.ac || die
+       AT_M4DIR="build" eautoreconf
+       elibtoolize
+
+       eapply "${FILESDIR}/config.layout.patch"
+}
+
+src_configure() {
+       local myconf=(
+               --enable-layout=gentoo
+               --enable-nonportable-atomics
+               --enable-posix-shm
+               --enable-threads
+               $(use_enable static-libs static)
+               --with-installbuilddir="${EPREFIX}"/usr/share/${PN}/build
+       )
+
+       if use older-kernels-compatibility; then
+               local apr_cv_accept4 apr_cv_dup3 apr_cv_epoll_create1 
apr_cv_sock_cloexec
+               export apr_cv_accept4="no"
+               export apr_cv_dup3="no"
+               export apr_cv_epoll_create1="no"
+               export apr_cv_sock_cloexec="no"
+       fi
+       if tc-is-cross-compiler; then
+               # The apache project relies heavily on AC_TRY_RUN and doesn't
+               # have any sane cross-compiling fallback logic.
+               export \
+                       ac_cv_file__dev_zero="yes" \
+                       ac_cv_func_sem_open="yes" \
+                       ac_cv_negative_eai="yes" \
+                       ac_cv_o_nonblock_inherited="no" \
+                       ac_cv_struct_rlimit="yes" \
+                       ap_cv_atomic_builtins="yes" \
+                       apr_cv_accept4="yes" \
+                       apr_cv_dup3="yes" \
+                       apr_cv_epoll="yes" \
+                       apr_cv_epoll_create1="yes" \
+                       apr_cv_gai_addrconfig="yes" \
+                       apr_cv_mutex_recursive="yes" \
+                       apr_cv_mutex_robust_shared="yes" \
+                       apr_cv_process_shared_works="yes" \
+                       apr_cv_pthreads_lib="-pthread" \
+                       apr_cv_sock_cloexec="yes" \
+                       apr_cv_tcp_nodelay_with_cork="yes"
+       fi
+
+       if use urandom; then
+               myconf+=( --with-devrandom=/dev/urandom )
+       elif (( ${CHOST#*-hpux11.} <= 11 )); then
+               : # no /dev/*random on hpux11.11 and before, ${PN} detects this.
+       else
+               myconf+=( --with-devrandom=/dev/random )
+       fi
+
+       tc-is-static-only && myconf+=( --disable-dso )
+
+       # shl_load does not search runpath, but hpux11 supports dlopen
+       [[ ${CHOST} == *-hpux11* ]] && myconf+=( --enable-dso=dlfcn )
+
+       if [[ ${CHOST} == *-solaris2.10 ]]; then
+               case $(<$([[ ${CHOST} != ${CBUILD} ]] && echo 
"${EPREFIX}/usr/${CHOST}")/usr/include/atomic.h) in
+               *atomic_cas_ptr*) ;;
+               *)
+                       elog "You do not have Solaris Patch ID "$(
+                               [[ ${CHOST} == sparc* ]] && echo 118884 || echo 
118885
+                       )" (Problem 4954703) installed on your host 
($(hostname)),"
+                       elog "using generic atomic operations instead."
+                       myconf+=( --disable-nonportable-atomics )
+                       ;;
+               esac
+       else
+               if use ppc || use sparc || use mips; then
+                       # Avoid libapr containing undefined references 
(underlinked)
+                       # undefined reference to `__sync_val_compare_and_swap_8'
+                       # (May be possible to fix via libatomic linkage in 
future?)
+                       # bug #740464
+                       myconf+=( --disable-nonportable-atomics )
+               fi
+       fi
+
+       econf "${myconf[@]}"
+}
+
+src_compile() {
+       if tc-is-cross-compiler; then
+               # This header is the same across targets, so use the build 
compiler.
+               emake tools/gen_test_char
+               tc-export_build_env BUILD_CC
+               ${BUILD_CC} ${BUILD_CFLAGS} ${BUILD_CPPFLAGS} ${BUILD_LDFLAGS} \
+                       tools/gen_test_char.c -o tools/gen_test_char || die
+       fi
+
+       emake
+
+       if use doc; then
+               emake dox
+       fi
+}
+
+src_test() {
+       # Building tests in parallel is broken
+       emake -j1 check
+}
+
+src_install() {
+       default
+
+       if ! use static-libs; then
+               find "${ED}" -name '*.la' -delete || die
+       fi
+
+       if use doc; then
+               docinto html
+               dodoc -r docs/dox/html/*
+       fi
+
+       # This file is only used on AIX systems, which Gentoo is not,
+       # and causes collisions between the SLOTs, so remove it.
+       # Even in Prefix, we don't need this on AIX.
+       rm "${ED}/usr/$(get_libdir)/apr.exp" || die
+}

diff --git a/dev-libs/apr/files/apr-1.7.0-clang-16.patch 
b/dev-libs/apr/files/apr-1.7.0-clang-16.patch
new file mode 100644
index 000000000000..2244b07a14ff
--- /dev/null
+++ b/dev-libs/apr/files/apr-1.7.0-clang-16.patch
@@ -0,0 +1,174 @@
+https://bugs.gentoo.org/870004
+
+Fixed upstream, hopefully (it's hard to keep track of 1.7.x branch churn):
+- https://bz.apache.org/bugzilla/show_bug.cgi?id=64753
+- https://bz.apache.org/bugzilla/show_bug.cgi?id=65087
+--- a/build/apr_common.m4
++++ b/build/apr_common.m4
+@@ -467,6 +467,7 @@ changequote([, ])dnl
+ AC_MSG_CHECKING(size of $2)
+ AC_CACHE_VAL(AC_CV_NAME,
+ [AC_TRY_RUN([#include <stdio.h>
++#include <stdlib.h>
+ $1
+ #ifdef WIN32
+ #define binmode "b"
+@@ -531,7 +532,8 @@ AC_TRY_RUN([
+ #include <errno.h>
+ #include <string.h>
+ #include <stdio.h>
+-main()
++#include <stdlib.h>
++int main()
+ {
+   char buf[1024];
+   if (strerror_r(ERANGE, buf, sizeof buf) < 1) {
+--- a/build/apr_network.m4
++++ b/build/apr_network.m4
+@@ -63,6 +63,10 @@ AC_DEFUN([APR_CHECK_WORKING_GETADDRINFO], [
+ #ifdef HAVE_SYS_SOCKET_H
+ #include <sys/socket.h>
+ #endif
++#include <stdlib.h>
++
++#include <netinet/in.h>
++#include <arpa/inet.h>
+ 
+ int main(void) {
+     struct addrinfo hints, *ai;
+@@ -136,6 +140,11 @@ dnl
+ AC_DEFUN([APR_CHECK_WORKING_GETNAMEINFO], [
+   AC_CACHE_CHECK(for working getnameinfo, ac_cv_working_getnameinfo,[
+   AC_TRY_RUN( [
++#include <sys/socket.h>
++#include <netinet/in.h>
++#include <arpa/inet.h>
++#include <stdlib.h>
++
+ #ifdef HAVE_NETDB_H
+ #include <netdb.h>
+ #endif
+@@ -195,6 +204,8 @@ AC_DEFUN([APR_CHECK_NEGATIVE_EAI], [
+ #include <netdb.h>
+ #endif
+ 
++#include <stdlib.h>
++
+ int main(void) {
+     if (EAI_ADDRFAMILY < 0) {
+         exit(0);
+@@ -388,9 +399,14 @@ AC_DEFUN([APR_CHECK_TCP_NODELAY_INHERITED], [
+   AC_CACHE_CHECK(if TCP_NODELAY setting is inherited from listening sockets, 
ac_cv_tcp_nodelay_inherited,[
+   AC_TRY_RUN( [
+ #include <stdio.h>
++#include <stdlib.h>
++
+ #ifdef HAVE_SYS_TYPES_H
+ #include <sys/types.h>
+-#endif
++#end
++#ifdef HAVE_STRING_H
++#include <string.h>
++#endifif
+ #ifdef HAVE_SYS_SOCKET_H
+ #include <sys/socket.h>
+ #endif
+@@ -734,6 +750,9 @@ AC_TRY_COMPILE([
+ #ifdef HAVE_ARPA_INET_H
+ #include <arpa/inet.h>
+ #endif
++
++#include <sys/socket.h>
++#include <netinet/in.h>
+ ],[
+ inet_addr("127.0.0.1");
+ ],[
+@@ -754,6 +773,9 @@ fi
+ AC_DEFUN([APR_CHECK_INET_NETWORK], [
+ AC_CACHE_CHECK(for inet_network, ac_cv_func_inet_network,[
+ AC_TRY_COMPILE([
++#include <sys/socket.h>
++#include <netinet/in.h>
++
+ #ifdef HAVE_SYS_TYPES_H
+ #include <sys/types.h>
+ #endif
+--- a/configure.in
++++ b/configure.in
+@@ -1440,8 +1440,6 @@ AC_CHECK_FUNCS(sigaction, [ have_sigaction="1" ], [ 
have_sigaction="0" ])
+ AC_DECL_SYS_SIGLIST
+ 
+ AC_CHECK_FUNCS(fork, [ fork="1" ], [ fork="0" ])
+-APR_CHECK_INET_ADDR
+-APR_CHECK_INET_NETWORK
+ AC_SUBST(apr_inaddr_none)
+ AC_CHECK_FUNC(_getch)
+ AC_CHECK_FUNCS(strerror_r, [ strerror_r="1" ], [ strerror_r="0" ])
+@@ -1547,6 +1545,9 @@ APR_FLAG_HEADERS(
+     sys/un.h          \
+     sys/wait.h)
+ 
++APR_CHECK_INET_ADDR
++APR_CHECK_INET_NETWORK
++
+ # IRIX 6.5 has a problem in <netinet/tcp.h> which prevents it from
+ # being included by itself.  Check for <netinet/tcp.h> manually,
+ # including another header file first.
+@@ -2208,7 +2209,8 @@ AC_TRY_RUN([
+ #include <sys/types.h>
+ #include <sys/time.h>
+ #include <sys/resource.h>
+-main()
++#include <stdlib.h>
++int main()
+ {
+     struct rlimit limit;
+     limit.rlim_cur = 0;
+@@ -2247,7 +2249,7 @@ AC_TRY_RUN([
+ #ifndef SEM_FAILED
+ #define SEM_FAILED (-1)
+ #endif
+-main()
++int main()
+ {
+     sem_t *psem;
+     const char *sem_name = "/apr_autoconf";
+@@ -2307,6 +2309,7 @@ if test "$threads" = "1"; then
+       AC_TRY_RUN([
+ #include <sys/types.h>
+ #include <pthread.h>
++#include <stdlib.h>
+         int main()
+         {
+             pthread_mutex_t mutex;
+@@ -2435,6 +2438,8 @@ int fd;
+ struct flock proc_mutex_lock_it = {0};
+ const char *fname = "conftest.fcntl";
+ 
++int lockit();
++
+ int main()
+ {
+     int rc, status;;
+--- a/poll/os2/pollset.c
++++ b/poll/os2/pollset.c
+@@ -308,7 +308,7 @@ APR_DECLARE(apr_status_t) apr_pollset_wakeup(apr_pollset_t 
*pollset)
+ 
+ 
+ 
+-APR_DECLARE(const char *) apr_poll_method_defname()
++APR_DECLARE(const char *) apr_poll_method_defname(void)
+ {
+     return "select";
+ }
+--- a/poll/unix/pollset.c
++++ b/poll/unix/pollset.c
+@@ -188,7 +188,7 @@ APR_DECLARE(const char *) 
apr_pollset_method_name(apr_pollset_t *pollset)
+     return pollset->provider->name;
+ }
+ 
+-APR_DECLARE(const char *) apr_poll_method_defname()
++APR_DECLARE(const char *) apr_poll_method_defname(void)
+ {
+     const apr_pollset_provider_t *provider = NULL;
+ 

Reply via email to