summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergei Trofimovich <slyfox@gentoo.org>2020-01-28 08:36:43 +0000
committerSergei Trofimovich <slyfox@gentoo.org>2020-01-28 08:37:01 +0000
commit6f70a8ffce550175305d9e208168af3aed1ae523 (patch)
tree7dbb4e674b8ceedab055a09bacd12d8353b6dd79
parentnet-analyzer/nagios-check_multiple: fix VariableInHomepage CI issue (diff)
downloadgentoo-6f70a8ff.tar.gz
gentoo-6f70a8ff.tar.bz2
gentoo-6f70a8ff.zip
dev-util/mingw64-runtime: avoid libssp references without -fstack-protector
mingw64-runtime-7.0.0 added basic support of _FORTIFY_SOURCE to harden strcpy() and memcpy() via __strcpy_chk() __memcpy_chk() similar to glibc. Unfortunately that imposes a new dependency on every caller that defines _FORTIFY_SOURCE to link against libssp as minw64-runtime does not provide __strcpy_chk() and friends. For comparison glibc does provide __strcpy_chk. To avoid widespread breakage (including build failure of USE=ssp gcc itself) we enable __strcpy_chk() checks only when -fstack-protector* options are set. Package-Manager: Portage-2.3.85, Repoman-2.3.20 Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
-rw-r--r--dev-util/mingw64-runtime/files/mingw64-runtime-7.0.0-fortify-only-ssp.patch16
-rw-r--r--dev-util/mingw64-runtime/mingw64-runtime-7.0.0-r1.ebuild118
2 files changed, 134 insertions, 0 deletions
diff --git a/dev-util/mingw64-runtime/files/mingw64-runtime-7.0.0-fortify-only-ssp.patch b/dev-util/mingw64-runtime/files/mingw64-runtime-7.0.0-fortify-only-ssp.patch
new file mode 100644
index 000000000000..72ddd775a2ea
--- /dev/null
+++ b/dev-util/mingw64-runtime/files/mingw64-runtime-7.0.0-fortify-only-ssp.patch
@@ -0,0 +1,16 @@
+--- a/mingw-w64-headers/crt/_mingw_mac.h
++++ b/mingw-w64-headers/crt/_mingw_mac.h
+@@ -301,7 +301,12 @@
+ # define __mingw_attribute_artificial
+ #endif
+
+-#if _FORTIFY_SOURCE > 0 && __OPTIMIZE__ > 0 && __MINGW_GNUC_PREREQ(4, 1)
++/* __SSP__ is a workaround to avoid reference to libssp when user did not request it:
++ * https://sourceforge.net/p/mingw-w64/bugs/818/
++ * Otherwise it breaks both USE=ssp gcc bootstrap and projects that happen to use
++ * strcpy/memcpy.
++ */
++#if _FORTIFY_SOURCE > 0 && __OPTIMIZE__ > 0 && __MINGW_GNUC_PREREQ(4, 1) && __SSP__ > 0
+ # if _FORTIFY_SOURCE > 1
+ # define __MINGW_FORTIFY_LEVEL 2
+ # else
diff --git a/dev-util/mingw64-runtime/mingw64-runtime-7.0.0-r1.ebuild b/dev-util/mingw64-runtime/mingw64-runtime-7.0.0-r1.ebuild
new file mode 100644
index 000000000000..82f85e2e5435
--- /dev/null
+++ b/dev-util/mingw64-runtime/mingw64-runtime-7.0.0-r1.ebuild
@@ -0,0 +1,118 @@
+# Copyright 1999-2020 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=7
+
+export CBUILD=${CBUILD:-${CHOST}}
+export CTARGET=${CTARGET:-${CHOST}}
+if [[ ${CTARGET} == ${CHOST} ]] ; then
+ if [[ ${CATEGORY} == cross-* ]] ; then
+ export CTARGET=${CATEGORY#cross-}
+ fi
+fi
+
+inherit autotools flag-o-matic eutils
+
+DESCRIPTION="Free Win64 runtime and import library definitions"
+HOMEPAGE="http://mingw-w64.sourceforge.net/"
+SRC_URI="mirror://sourceforge/mingw-w64/mingw-w64/mingw-w64-release/mingw-w64-v${PV}.tar.bz2"
+
+LICENSE="BSD"
+SLOT="0"
+KEYWORDS="~amd64 ~x86"
+# USE=libraries needs working stage2 compiler: bug #665512
+IUSE="headers-only idl libraries tools"
+RESTRICT="strip"
+
+S="${WORKDIR}/mingw-w64-v${PV}"
+
+PATCHES=(
+ "${FILESDIR}"/${P}-fortify-only-ssp.patch
+)
+
+is_crosscompile() {
+ [[ ${CHOST} != ${CTARGET} ]]
+}
+just_headers() {
+ use headers-only
+}
+alt_prefix() {
+ is_crosscompile && echo /usr/${CTARGET}
+}
+crt_with() {
+ just_headers && echo --without-$1 || echo --with-$1
+}
+crt_use_enable() {
+ just_headers && echo --without-$2 || use_enable "$@"
+}
+crt_use_with() {
+ just_headers && echo --without-$2 || use_with "$@"
+}
+
+pkg_setup() {
+ if [[ ${CBUILD} == ${CHOST} ]] && [[ ${CHOST} == ${CTARGET} ]] ; then
+ die "Invalid configuration"
+ fi
+}
+
+src_configure() {
+ CHOST=${CTARGET} strip-unsupported-flags
+ # Normally mingw-64 does not use dynamic linker.
+ # But at configure time it uses $LDFLAGS.
+ # When default -Wl,--hash-style=gnu is passed
+ # __CTORS_LIST__ / __DTORS_LIST__ is mis-detected
+ # for target ld and binaries crash at shutdown.
+ filter-ldflags '-Wl,--hash-style=*'
+
+ if ! just_headers; then
+ mkdir "${WORKDIR}/headers"
+ pushd "${WORKDIR}/headers" > /dev/null
+ CHOST=${CTARGET} "${S}/configure" \
+ --prefix="${T}/tmproot" \
+ --with-headers \
+ --without-crt \
+ || die
+ popd > /dev/null
+ append-cppflags "-I${T}/tmproot/include"
+ fi
+
+ # By default configure tries to set --sysroot=${prefix}. We disable
+ # this behaviour with --with-sysroot=no to use gcc's sysroot default.
+ # That way we can cross-build mingw64-runtime with cross-emerge.
+ local prefix="${EPREFIX}"$(alt_prefix)/usr
+ CHOST=${CTARGET} econf \
+ --with-sysroot=no \
+ --prefix="${prefix}" \
+ --libdir="${prefix}"/lib \
+ --with-headers \
+ --enable-sdk \
+ $(crt_with crt) \
+ $(crt_use_enable idl idl) \
+ $(crt_use_with libraries libraries) \
+ $(crt_use_with tools tools) \
+ $(
+ $(tc-getCPP ${CTARGET}) ${CPPFLAGS} -dM - < /dev/null | grep -q __MINGW64__ \
+ && echo --disable-lib32 --enable-lib64 \
+ || echo --enable-lib32 --disable-lib64
+ )
+}
+
+src_compile() {
+ if ! just_headers; then
+ emake -C "${WORKDIR}/headers" install
+ fi
+ default
+}
+
+src_install() {
+ default
+
+ if is_crosscompile ; then
+ # gcc is configured to look at specific hard-coded paths for mingw #419601
+ dosym usr /usr/${CTARGET}/mingw
+ dosym usr /usr/${CTARGET}/${CTARGET}
+ dosym usr/include /usr/${CTARGET}/sys-include
+ fi
+
+ rm -rf "${ED}/usr/share"
+}