1 |
commit: 6f70a8ffce550175305d9e208168af3aed1ae523 |
2 |
Author: Sergei Trofimovich <slyfox <AT> gentoo <DOT> org> |
3 |
AuthorDate: Tue Jan 28 08:36:43 2020 +0000 |
4 |
Commit: Sergei Trofimovich <slyfox <AT> gentoo <DOT> org> |
5 |
CommitDate: Tue Jan 28 08:37:01 2020 +0000 |
6 |
URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=6f70a8ff |
7 |
|
8 |
dev-util/mingw64-runtime: avoid libssp references without -fstack-protector |
9 |
|
10 |
mingw64-runtime-7.0.0 added basic support of _FORTIFY_SOURCE to harden |
11 |
strcpy() and memcpy() via __strcpy_chk() __memcpy_chk() similar to glibc. |
12 |
|
13 |
Unfortunately that imposes a new dependency on every caller that defines |
14 |
_FORTIFY_SOURCE to link against libssp as minw64-runtime does not provide |
15 |
__strcpy_chk() and friends. For comparison glibc does provide __strcpy_chk. |
16 |
|
17 |
To avoid widespread breakage (including build failure of USE=ssp gcc itself) |
18 |
we enable __strcpy_chk() checks only when -fstack-protector* options are set. |
19 |
|
20 |
Package-Manager: Portage-2.3.85, Repoman-2.3.20 |
21 |
Signed-off-by: Sergei Trofimovich <slyfox <AT> gentoo.org> |
22 |
|
23 |
.../mingw64-runtime-7.0.0-fortify-only-ssp.patch | 16 +++ |
24 |
.../mingw64-runtime-7.0.0-r1.ebuild | 118 +++++++++++++++++++++ |
25 |
2 files changed, 134 insertions(+) |
26 |
|
27 |
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 |
28 |
new file mode 100644 |
29 |
index 00000000000..72ddd775a2e |
30 |
--- /dev/null |
31 |
+++ b/dev-util/mingw64-runtime/files/mingw64-runtime-7.0.0-fortify-only-ssp.patch |
32 |
@@ -0,0 +1,16 @@ |
33 |
+--- a/mingw-w64-headers/crt/_mingw_mac.h |
34 |
++++ b/mingw-w64-headers/crt/_mingw_mac.h |
35 |
+@@ -301,7 +301,12 @@ |
36 |
+ # define __mingw_attribute_artificial |
37 |
+ #endif |
38 |
+ |
39 |
+-#if _FORTIFY_SOURCE > 0 && __OPTIMIZE__ > 0 && __MINGW_GNUC_PREREQ(4, 1) |
40 |
++/* __SSP__ is a workaround to avoid reference to libssp when user did not request it: |
41 |
++ * https://sourceforge.net/p/mingw-w64/bugs/818/ |
42 |
++ * Otherwise it breaks both USE=ssp gcc bootstrap and projects that happen to use |
43 |
++ * strcpy/memcpy. |
44 |
++ */ |
45 |
++#if _FORTIFY_SOURCE > 0 && __OPTIMIZE__ > 0 && __MINGW_GNUC_PREREQ(4, 1) && __SSP__ > 0 |
46 |
+ # if _FORTIFY_SOURCE > 1 |
47 |
+ # define __MINGW_FORTIFY_LEVEL 2 |
48 |
+ # else |
49 |
|
50 |
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 |
51 |
new file mode 100644 |
52 |
index 00000000000..82f85e2e543 |
53 |
--- /dev/null |
54 |
+++ b/dev-util/mingw64-runtime/mingw64-runtime-7.0.0-r1.ebuild |
55 |
@@ -0,0 +1,118 @@ |
56 |
+# Copyright 1999-2020 Gentoo Authors |
57 |
+# Distributed under the terms of the GNU General Public License v2 |
58 |
+ |
59 |
+EAPI=7 |
60 |
+ |
61 |
+export CBUILD=${CBUILD:-${CHOST}} |
62 |
+export CTARGET=${CTARGET:-${CHOST}} |
63 |
+if [[ ${CTARGET} == ${CHOST} ]] ; then |
64 |
+ if [[ ${CATEGORY} == cross-* ]] ; then |
65 |
+ export CTARGET=${CATEGORY#cross-} |
66 |
+ fi |
67 |
+fi |
68 |
+ |
69 |
+inherit autotools flag-o-matic eutils |
70 |
+ |
71 |
+DESCRIPTION="Free Win64 runtime and import library definitions" |
72 |
+HOMEPAGE="http://mingw-w64.sourceforge.net/" |
73 |
+SRC_URI="mirror://sourceforge/mingw-w64/mingw-w64/mingw-w64-release/mingw-w64-v${PV}.tar.bz2" |
74 |
+ |
75 |
+LICENSE="BSD" |
76 |
+SLOT="0" |
77 |
+KEYWORDS="~amd64 ~x86" |
78 |
+# USE=libraries needs working stage2 compiler: bug #665512 |
79 |
+IUSE="headers-only idl libraries tools" |
80 |
+RESTRICT="strip" |
81 |
+ |
82 |
+S="${WORKDIR}/mingw-w64-v${PV}" |
83 |
+ |
84 |
+PATCHES=( |
85 |
+ "${FILESDIR}"/${P}-fortify-only-ssp.patch |
86 |
+) |
87 |
+ |
88 |
+is_crosscompile() { |
89 |
+ [[ ${CHOST} != ${CTARGET} ]] |
90 |
+} |
91 |
+just_headers() { |
92 |
+ use headers-only |
93 |
+} |
94 |
+alt_prefix() { |
95 |
+ is_crosscompile && echo /usr/${CTARGET} |
96 |
+} |
97 |
+crt_with() { |
98 |
+ just_headers && echo --without-$1 || echo --with-$1 |
99 |
+} |
100 |
+crt_use_enable() { |
101 |
+ just_headers && echo --without-$2 || use_enable "$@" |
102 |
+} |
103 |
+crt_use_with() { |
104 |
+ just_headers && echo --without-$2 || use_with "$@" |
105 |
+} |
106 |
+ |
107 |
+pkg_setup() { |
108 |
+ if [[ ${CBUILD} == ${CHOST} ]] && [[ ${CHOST} == ${CTARGET} ]] ; then |
109 |
+ die "Invalid configuration" |
110 |
+ fi |
111 |
+} |
112 |
+ |
113 |
+src_configure() { |
114 |
+ CHOST=${CTARGET} strip-unsupported-flags |
115 |
+ # Normally mingw-64 does not use dynamic linker. |
116 |
+ # But at configure time it uses $LDFLAGS. |
117 |
+ # When default -Wl,--hash-style=gnu is passed |
118 |
+ # __CTORS_LIST__ / __DTORS_LIST__ is mis-detected |
119 |
+ # for target ld and binaries crash at shutdown. |
120 |
+ filter-ldflags '-Wl,--hash-style=*' |
121 |
+ |
122 |
+ if ! just_headers; then |
123 |
+ mkdir "${WORKDIR}/headers" |
124 |
+ pushd "${WORKDIR}/headers" > /dev/null |
125 |
+ CHOST=${CTARGET} "${S}/configure" \ |
126 |
+ --prefix="${T}/tmproot" \ |
127 |
+ --with-headers \ |
128 |
+ --without-crt \ |
129 |
+ || die |
130 |
+ popd > /dev/null |
131 |
+ append-cppflags "-I${T}/tmproot/include" |
132 |
+ fi |
133 |
+ |
134 |
+ # By default configure tries to set --sysroot=${prefix}. We disable |
135 |
+ # this behaviour with --with-sysroot=no to use gcc's sysroot default. |
136 |
+ # That way we can cross-build mingw64-runtime with cross-emerge. |
137 |
+ local prefix="${EPREFIX}"$(alt_prefix)/usr |
138 |
+ CHOST=${CTARGET} econf \ |
139 |
+ --with-sysroot=no \ |
140 |
+ --prefix="${prefix}" \ |
141 |
+ --libdir="${prefix}"/lib \ |
142 |
+ --with-headers \ |
143 |
+ --enable-sdk \ |
144 |
+ $(crt_with crt) \ |
145 |
+ $(crt_use_enable idl idl) \ |
146 |
+ $(crt_use_with libraries libraries) \ |
147 |
+ $(crt_use_with tools tools) \ |
148 |
+ $( |
149 |
+ $(tc-getCPP ${CTARGET}) ${CPPFLAGS} -dM - < /dev/null | grep -q __MINGW64__ \ |
150 |
+ && echo --disable-lib32 --enable-lib64 \ |
151 |
+ || echo --enable-lib32 --disable-lib64 |
152 |
+ ) |
153 |
+} |
154 |
+ |
155 |
+src_compile() { |
156 |
+ if ! just_headers; then |
157 |
+ emake -C "${WORKDIR}/headers" install |
158 |
+ fi |
159 |
+ default |
160 |
+} |
161 |
+ |
162 |
+src_install() { |
163 |
+ default |
164 |
+ |
165 |
+ if is_crosscompile ; then |
166 |
+ # gcc is configured to look at specific hard-coded paths for mingw #419601 |
167 |
+ dosym usr /usr/${CTARGET}/mingw |
168 |
+ dosym usr /usr/${CTARGET}/${CTARGET} |
169 |
+ dosym usr/include /usr/${CTARGET}/sys-include |
170 |
+ fi |
171 |
+ |
172 |
+ rm -rf "${ED}/usr/share" |
173 |
+} |