1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
|
# Copyright 1999-2015 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/sys-devel/gcc/gcc-4.7.3-r1.ebuild,v 1.21 2015/03/17 06:41:31 vapier Exp $
EAPI="2"
PATCH_VER="1.5"
UCLIBC_VER="1.0"
# Hardened gcc 4 stuff
PIE_VER="0.5.5"
SPECS_VER="0.2.0"
SPECS_GCC_VER="4.4.3"
# arch/libc configurations known to be stable with {PIE,SSP}-by-default
PIE_GLIBC_STABLE="x86 amd64 ppc ppc64 arm ia64"
PIE_UCLIBC_STABLE="x86 arm amd64 ppc ppc64"
SSP_STABLE="amd64 x86 ppc ppc64 arm"
# uclibc need tls and nptl support for SSP support
# uclibc need to be >= 0.9.33
SSP_UCLIBC_STABLE="x86 amd64 ppc ppc64 arm"
#end Hardened stuff
inherit eutils flag-o-matic multilib toolchain
DESCRIPTION="The GNU Compiler Collection."
LICENSE="GPL-3+ LGPL-3+ || ( GPL-3+ libgcc libstdc++ gcc-runtime-library-exception-3.1 ) FDL-1.3+"
KEYWORDS="alpha amd64 arm hppa ia64 m68k ~mips ppc ppc64 s390 sh sparc x86 -amd64-fbsd -x86-fbsd"
KEYWORDS+="~ppc-aix ~x64-freebsd ~x86-freebsd ~ia64-hpux ~x86-interix ~amd64-linux ~ia64-linux ~x86-linux ~ppc-macos ~x64-macos ~x86-macos ~m68k-mint ~sparc-solaris ~sparc64-solaris ~x64-solaris ~x86-solaris"
RDEPEND=""
DEPEND="${RDEPEND}
!prefix? ( elibc_glibc? ( >=sys-libs/glibc-2.8 ) )
kernel_Darwin? ( ${CATEGORY}/binutils-apple )
kernel_AIX? ( ${CATEGORY}/native-cctools )
kernel_linux? ( >=${CATEGORY}/binutils-2.18 )"
if [[ ${CATEGORY} != cross-* ]] ; then
PDEPEND="${PDEPEND} !prefix? ( elibc_glibc? ( >=sys-libs/glibc-2.8 ) )"
fi
src_prepare() {
if has_version '<sys-libs/glibc-2.12' ; then
ewarn "Your host glibc is too old; disabling automatic fortify."
ewarn "Please rebuild gcc after upgrading to >=glibc-2.12 #362315"
EPATCH_EXCLUDE+=" 10_all_default-fortify-source.patch"
fi
# Fedora/RedHat ships glibc-2.15+ with some nasty warnings that cause
# configure checks for most system headers to fail, resulting in bugs
# compiling e.g. gcc itself, bug #433333
if [[ -e /usr/include/features.h ]] ; then
grep -qF "_FORTIFY_SOURCE requires compiling with optimization" \
/usr/include/features.h && \
EPATCH_EXCLUDE+=" 10_all_default-fortify-source.patch"
fi
# drop the x32 stuff in the next patchset #543578
if [[ ${CTARGET} != x86_64* ]] || ! has x32 $(get_all_abis TARGET) ; then
EPATCH_EXCLUDE+=" 90_all_gcc-4.7-x32.patch"
fi
toolchain_src_prepare
use vanilla && return 0
# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60221
epatch "${FILESDIR}"/gcc-4.7.2-cleanup-empty-eh-o0.patch
# make sure solaris-x64 doesn't misdetect tls support, bug #505446
epatch "${FILESDIR}"/4.7.2/solaris-x64-tls-gnu-as.patch
# make sure 64-bits native targets don't screw up the linker paths
epatch "${FILESDIR}"/4.7.1/solaris-searchpath.patch
epatch "${FILESDIR}"/no-libs-for-startfile.patch
if use prefix; then
epatch "${FILESDIR}"/4.5.2/prefix-search-dirs.patch
# try /usr/lib32 in 32bit profile on x86_64-linux (needs
# --enable-multilib), but this does make sense in prefix only
epatch "${FILESDIR}"/${PN}-4.7.2-linux-x86-on-amd64.patch
fi
# make it have correct install_names on Darwin
epatch "${FILESDIR}"/4.3.3/darwin-libgcc_s-installname.patch
if [[ ${CHOST} == *-mint* ]] ; then
epatch "${FILESDIR}"/4.3.2/${PN}-4.3.2-mint3.patch
epatch "${FILESDIR}"/4.7.2/mint1.patch
epatch "${FILESDIR}"/4.4.1/${PN}-4.4.1-mint3.patch
epatch "${FILESDIR}"/4.7.2/mint2.patch
epatch "${FILESDIR}"/4.7.2/mint3.patch
epatch "${FILESDIR}"/4.7.2/pr52391.patch
epatch "${FILESDIR}"/4.7.2/mint-unroll.patch
epatch "${FILESDIR}"/4.7.2/pr52773.patch
epatch "${FILESDIR}"/4.7.2/pr52714.patch
fi
# Always behave as if -pthread were passed on AIX and HPUX (#266548)
# fails, likely still necessary though
# epatch "${FILESDIR}"/4.5.1/aix-force-pthread.patch
# epatch "${FILESDIR}"/4.5.1/ia64-hpux-always-pthread.patch
[[ ${CHOST} == ${CTARGET} ]] && epatch "${FILESDIR}"/gcc-spec-env.patch
if [[ "${ARCH}" == "amd64" ]]; then
local LD32="$( get_abi_LIBDIR x86 )"
local LDx32="$( get_abi_LIBDIR x32 )"
local LD64="$( get_abi_LIBDIR amd64 )"
sed -i \
-e "/^#define GLIBC_DYNAMIC_LINKER32/{s:/lib/:/${LD32:-lib}/:}" \
-e "/^#define GLIBC_DYNAMIC_LINKERX32/{s:/libx32/:/${LDx32:-libx32}/:}" \
-e "/^#define GLIBC_DYNAMIC_LINKER64/{s:/lib64/:/${LD64:-lib64}/:}" \
gcc/config/i386/linux64.h \
|| die 'LIBDIR replacement failed'
einfo "Using the following LIBDIR defines:"
tail -n 3 gcc/config/i386/linux64.h
sed -i \
-e "/^MULTILIB_OSDIRNAMES[+ ]= m64=/{s:=../lib64$:=../${LD64:-lib64}:}" \
-e "/^MULTILIB_OSDIRNAMES[+ ]= m32=/{s:=../lib$:=../${LD32:-lib}:}" \
-e "/^MULTILIB_OSDIRNAMES[+ ]= mx32=/{s:=../libx32$:=../${LDx32:-libx32}:}" \
gcc/config/i386/t-linux64 \
|| die 'DIRNAMES replacement failed'
einfo "Using the following DIRNAMES defines:"
tail -n 3 gcc/config/i386/t-linux64
sed -i \
-e "/^const char \*__gnat_default_libgcc_subdir = \"libx32\";$/{s:\"libx32\":\"${LDx32:-libx32}\":}" \
gcc/ada/link.c \
|| die 'ADA replacement failed'
fi
}
src_configure() {
case ${CTARGET}:" ${USE} " in
powerpc*-darwin*)
# bug #381179
filter-flags "-mcpu=*" "-mtune=*"
;;
*-mint*)
EXTRA_ECONF="${EXTRA_ECONF} --enable-multilib"
;;
*-solaris*)
# todo: some magic for native vs. GNU linking?
EXTRA_ECONF="${EXTRA_ECONF} --with-gnu-ld --with-gnu-as"
;;
*-aix*)
# AIX doesn't use GNU binutils, because it doesn't produce usable
# code
EXTRA_ECONF="${EXTRA_ECONF} --without-gnu-ld --without-gnu-as"
append-ldflags -Wl,-bbigtoc,-bmaxdata:0x10000000 # bug#194635
;;
*-interix*)
# disable usage of poll() on interix, since poll() only
# works on the /proc filesystem (.......)
export glibcxx_cv_POLL=no
# if using the old system as, gcc's configure script fails
# to detect that as cannot handle .lcomm with alignment.
# on interix, it is rather easy to detect the as, since there
# is only _one_ build of it with a fixed date in the version
# header...
if as --version | grep 20021111 > /dev/null 2>&1; then
einfo "preventing gcc from detecting .lcomm alignment option in interix system as."
export gcc_cv_as_lcomm_with_alignment=no
fi
;;
i[34567]86-*-linux*:*" prefix "*)
# to allow the linux-x86-on-amd64.patch become useful, we need
# to enable multilib, even if there is just one multilib option.
EXTRA_ECONF="${EXTRA_ECONF} --enable-multilib"
if [[ ${CBUILD:-${CHOST}} == "${CHOST}" ]]; then
# we might be on x86_64-linux, but don't do cross-compile, so
# tell the host-compiler to really create 32bits (for stage1)
# (real x86-linux-gcc also accept -m32).
tc-export CC CXX
CC="${CC} -m32"
CXX="${CC} -m32"
fi
;;
esac
# Since GCC 4.1.2 some non-posix (?) /bin/sh compatible code is used, at
# least on Solaris, and AIX /bin/sh is ways too slow,
# so force it to use $BASH (that portage uses) - it can't be EPREFIX
# in case that doesn't exist yet
export CONFIG_SHELL="${CONFIG_SHELL:-${BASH}}"
toolchain_src_configure
}
src_install() {
toolchain_src_install
if [[ ${CTARGET} == *-interix* ]] && ! is_crosscompile; then
# interix delivers libdl and dlfcn.h with gcc-3.3.
# Since those parts are perfectly usable by this gcc (and
# required for example by perl), we simply can reuse them.
# As libdl is in /usr/lib, we only need to copy dlfcn.h.
# When cross compiling for interix once, ensure that sysroot
# contains dlfcn.h.
cp /opt/gcc.3.3/include/dlfcn.h "${ED}${INCLUDEPATH}" \
|| die "Cannot gain /opt/gcc.3.3/include/dlfcn.h"
fi
if [[ ${CTARGET} == *-interix3* ]]; then
# interix 3.5 has no stdint.h and no inttypes.h. This breaks
# so many packages, that i just install interix 5.2's stdint.h
# which should be ok.
cp "${FILESDIR}"/interix-3.5-stdint.h "${ED}${INCLUDEPATH}/stdint.h" \
|| die "Cannot install stdint.h for interix3"
fi
# create a small profile.d script, unsetting some of the bad
# environment variables that the system could set from the outside.
# (GCC_SPECS, GCC_EXEC_PREFIX, CPATH, LIBRARY_PATH, LD_LIBRARY_PATH,
# C_INCLUDE_PATH, CPLUS_INCLUDE_PATH, LIBPATH, SHLIB_PATH, LIB, INCLUDE,
# LD_LIBRARY_PATH_32, LD_LIBRARY_PATH_64).
# Maybe there is a better location for doing this ...? Feel free to move
# it there if you want to.
cat > "${T}"/00-gcc-paths.sh <<- _EOF
#!/bin/env bash
# GCC specific variables
unset GCC_SPECS GCC_EXEC_PREFIX
# include path variables
unset CPATH C_INCLUDE_PATH CPLUS_INCLUDE_PATH INCLUDE
# library path variables
unset LIBRARY_PATH LD_LIBRARY_PATH LIBPATH SHLIB_PATH LIB LD_LIBRARY_PATH_32 LD_LIBRARY_PATH_64
_EOF
insinto /etc/profile.d
doins "${T}"/00-gcc-paths.sh
}
|