]> git.wh0rd.org - patches.git/blame - toolchain.eclass.xgcc.patch
more random patches. who knows.
[patches.git] / toolchain.eclass.xgcc.patch
CommitLineData
b53d1f41
MF
1Index: toolchain.eclass
2===================================================================
3RCS file: /var/cvsroot/gentoo-x86/eclass/toolchain.eclass,v
4retrieving revision 1.252
5diff -u -p -r1.252 toolchain.eclass
6--- toolchain.eclass 18 Mar 2006 18:38:11 -0000 1.252
7+++ toolchain.eclass 22 Mar 2006 03:28:22 -0000
8@@ -123,7 +123,6 @@ elif [[ ${GCC_VAR_TYPE} == "non-versione
9 STDCXX_INCDIR=${TOOLCHAIN_STDCXX_INCDIR:-${PREFIX}/include/g++-v3}
10 fi
11
12-XGCC="${WORKDIR}/build/gcc/xgcc -B${WORKDIR}/build/gcc"
13 #----<< globals >>----
14
15
16@@ -343,6 +342,14 @@ SRC_URI=$(get_gcc_src_uri)
17
18 #---->> support checks <<----
19
20+# Grab a variable from the build system (taken from linux-info.eclass)
21+get_make_var() {
22+ local var=$1 makefile=${2:-${WORKDIR}/build/Makefile}
23+ echo -e "e:\\n\\t@echo \$(${var})\\ninclude ${makefile}" | \
24+ r=${makefile%/*} emake -s -f - 2>/dev/null
25+}
26+XGCC() { get_make_var GCC_FOR_TARGET ; }
27+
28 # The gentoo piessp patches allow for 3 configurations:
29 # 1) PIE+SSP by default
30 # 2) PIE by default
31@@ -547,114 +554,50 @@ make_gcc_hard() {
32 release_version="${release_version/Gentoo/Gentoo Hardened}"
33 }
34
35-create_vanilla_specs_file() {
36+# now we generate different spec files so that the user can select a compiler
37+# that enforces certain features in gcc itself and so we don't have to worry
38+# about a certain package ignoring CFLAGS/LDFLAGS
39+_create_specs_file() {
40+ # Usage: _create_specs_file <USE flag> <specs name> <CFLAGS>
41+ local uflag=$1 name=$2 flags=${*:3}
42+ ebegin "Creating a ${name} gcc specs file"
43 pushd "${WORKDIR}"/build/gcc > /dev/null
44- if use hardened ; then
45- # if using hardened, then we need to move xgcc out of the way
46- # and recompile it
47+ if [[ -z ${uflag} ]] || use ${uflag} ; then
48+ # backup the compiler first
49 cp Makefile Makefile.orig
50- sed -i -e 's/^HARD_CFLAGS.*/HARD_CFLAGS = /g' Makefile
51- mv xgcc xgcc.hard
52- mv gcc.o gcc.o.hard
53- make xgcc
54- einfo "Creating a vanilla gcc specs file"
55- ./xgcc -dumpspecs > "${WORKDIR}"/build/vanilla.specs
56+ sed -i -e '/^HARD_CFLAGS/s:=.*:='"${flags}"':' Makefile
57+ mv xgcc xgcc.foo
58+ mv gcc.o gcc.o.foo
59+ emake -s xgcc
60+ $(XGCC) -dumpspecs > "${WORKDIR}"/build/${name}.specs
61 # restore everything to normal
62- mv gcc.o.hard gcc.o
63- mv xgcc.hard xgcc
64+ mv gcc.o.foo gcc.o
65+ mv xgcc.foo xgcc
66 mv Makefile.orig Makefile
67 else
68- einfo "Creating a vanilla gcc specs file"
69- ./xgcc -dumpspecs > "${WORKDIR}"/build/vanilla.specs
70+ $(XGCC) -dumpspecs > "${WORKDIR}"/build/${name}.specs
71 fi
72 popd > /dev/null
73+ eend $([[ -s ${WORKDIR}/build/${name}.specs ]] ; echo $?)
74 }
75-
76-create_hardened_specs_file() {
77- pushd "${WORKDIR}"/build/gcc > /dev/null
78- if ! use hardened ; then
79- # if not using hardened, then we need to move xgcc out of the way
80- # and recompile it
81- cp Makefile Makefile.orig
82- sed -i -e "s/^HARD_CFLAGS.*/HARD_CFLAGS = -DEFAULT_PIE_SSP ${gcc_common_hard}/g" Makefile
83- mv xgcc xgcc.vanilla
84- mv gcc.o gcc.o.vanilla
85- make xgcc
86- einfo "Creating a hardened gcc specs file"
87- ./xgcc -dumpspecs > "${WORKDIR}"/build/hardened.specs
88- # restore everything to normal
89- mv gcc.o.vanilla gcc.o
90- mv xgcc.vanilla xgcc
91- mv Makefile.orig Makefile
92- else
93- einfo "Creating a hardened gcc specs file"
94- ./xgcc -dumpspecs > "${WORKDIR}"/build/hardened.specs
95- fi
96- popd > /dev/null
97-}
98-
99-create_hardenednossp_specs_file() {
100- pushd "${WORKDIR}"/build/gcc > /dev/null
101- cp Makefile Makefile.orig
102- sed -i -e "s/^HARD_CFLAGS.*/HARD_CFLAGS = -DEFAULT_PIE ${gcc_common_hard}/g" Makefile
103- mv xgcc xgcc.moo
104- mv gcc.o gcc.o.moo
105- make xgcc
106- einfo "Creating a hardened no-ssp gcc specs file"
107- ./xgcc -dumpspecs > "${WORKDIR}"/build/hardenednossp.specs
108- # restore everything to normal
109- mv gcc.o.moo gcc.o
110- mv xgcc.moo xgcc
111- mv Makefile.orig Makefile
112- popd > /dev/null
113-}
114-
115-create_hardenednopie_specs_file() {
116- pushd "${WORKDIR}"/build/gcc > /dev/null
117- cp Makefile Makefile.orig
118- sed -i -e "s/^HARD_CFLAGS.*/HARD_CFLAGS = -DEFAULT_SSP ${gcc_common_hard}/g" Makefile
119- mv xgcc xgcc.moo
120- mv gcc.o gcc.o.moo
121- make xgcc
122- einfo "Creating a hardened no-pie gcc specs file"
123- ./xgcc -dumpspecs > "${WORKDIR}"/build/hardenednopie.specs
124- # restore everything to normal
125- mv gcc.o.moo gcc.o
126- mv xgcc.moo xgcc
127- mv Makefile.orig Makefile
128- popd > /dev/null
129-}
130-
131-create_hardenednopiessp_specs_file() {
132- pushd "${WORKDIR}"/build/gcc > /dev/null
133- cp Makefile Makefile.orig
134- sed -i -e "s/^HARD_CFLAGS.*/HARD_CFLAGS = ${gcc_common_hard}/g" Makefile
135- mv xgcc xgcc.moo
136- mv gcc.o gcc.o.moo
137- make xgcc
138- einfo "Creating a hardened no-pie no-ssp gcc specs file"
139- ./xgcc -dumpspecs > "${WORKDIR}"/build/hardenednopiessp.specs
140- # restore everything to normal
141- mv gcc.o.moo gcc.o
142- mv xgcc.moo xgcc
143- mv Makefile.orig Makefile
144- popd > /dev/null
145-}
146+create_vanilla_specs_file() { _create_specs_file hardened vanilla ; }
147+create_hardened_specs_file() { _create_specs_file !hardened hardened ${gcc_common_hard} -DEFAULT_PIE_SSP ; }
148+create_hardenednossp_specs_file() { _create_specs_file "" hardenednossp ${gcc_common_hard} -DEFAULT_PIE ; }
149+create_hardenednopie_specs_file() { _create_specs_file "" hardenednopie ${gcc_common_hard} -DEFAULT_SSP ; }
150+create_hardenednopiessp_specs_file() { _create_specs_file "" hardenednopiessp ${gcc_common_hard} ; }
151
152 split_out_specs_files() {
153+ local s spec_list="hardenednopiessp vanilla"
154 if hardened_gcc_works ; then
155- create_hardened_specs_file
156- create_vanilla_specs_file
157- create_hardenednossp_specs_file
158- create_hardenednopie_specs_file
159+ spec_list="${spec_list} hardened hardenednossp hardenednopie"
160 elif hardened_gcc_works pie ; then
161- create_vanilla_specs_file
162- create_hardenednossp_specs_file
163+ spec_list="${spec_list} hardenednossp"
164 elif hardened_gcc_works ssp ; then
165- create_vanilla_specs_file
166- create_hardenednopie_specs_file
167+ spec_list="${spec_list} hardenednopie"
168 fi
169- create_hardenednopiessp_specs_file
170+ for s in ${spec_list} ; do
171+ create_${s}_specs_file || return 1
172+ done
173 }
174
175 create_gcc_env_entry() {
176@@ -693,7 +636,7 @@ create_gcc_env_entry() {
177 # XXX: This breaks when cross-compiling a native compiler (CBUILD != CHOST)
178
179 local abi=${DEFAULT_ABI}
180- local MULTIDIR=$(${XGCC} -B./ $(get_abi_CFLAGS ${abi}) --print-multi-directory)
181+ local MULTIDIR=$($(XGCC) $(get_abi_CFLAGS ${abi}) --print-multi-directory)
182 if [[ ${MULTIDIR} == "." ]] ; then
183 LDPATH=${LIBPATH}
184 else
185@@ -703,7 +646,7 @@ create_gcc_env_entry() {
186 for abi in $(get_all_abis) ; do
187 [[ ${abi} == ${DEFAULT_ABI} ]] && continue
188
189- MULTIDIR=$(${XGCC} -B./ $(get_abi_CFLAGS ${abi}) --print-multi-directory)
190+ MULTIDIR=$($(XGCC) $(get_abi_CFLAGS ${abi}) --print-multi-directory)
191 if [[ ${MULTIDIR} == "." ]] ; then
192 LDPATH=${LDPATH}:${LIBPATH}
193 else
194@@ -715,8 +658,8 @@ create_gcc_env_entry() {
195 echo "LDPATH=\"${LDPATH}\"" >> ${gcc_envd_file}
196
197 local mbits
198- CC=${XGCC} has_m32 && mbits="${mbits:+${mbits} }32"
199- CC=${XGCC} has_m64 && mbits="${mbits:+${mbits} }64"
200+ CC=$(XGCC) has_m32 && mbits="${mbits:+${mbits} }32"
201+ CC=$(XGCC) has_m64 && mbits="${mbits:+${mbits} }64"
202 echo "GCCBITS=\"${mbits}\"" >> ${gcc_envd_file}
203
204 echo "MANPATH=\"${DATAPATH}/man\"" >> ${gcc_envd_file}
205@@ -771,7 +714,7 @@ add_profile_eselect_conf() {
206 fi
207 fi
208
209- local MULTIDIR=$(${XGCC} -B./ $(get_abi_CFLAGS ${abi}) --print-multi-directory)
210+ local MULTIDIR=$($(XGCC) $(get_abi_CFLAGS ${abi}) --print-multi-directory)
211 local LDPATH=${LIBPATH}
212 if [[ ${MULTIDIR} != "." ]] ; then
213 LDPATH="${LIBPATH}/${MULTIDIR}"
214@@ -1709,12 +1652,12 @@ gcc_movelibs() {
215 # XXX: This breaks when cross-compiling a native compiler (CBUILD != CHOST)
216
217 local multiarg
218- for multiarg in $(${XGCC} -print-multi-lib) ; do
219+ for multiarg in $($(XGCC) -print-multi-lib) ; do
220 multiarg=${multiarg#*;}
221 multiarg=${multiarg//@/ -}
222
223- local OS_MULTIDIR=$(${XGCC} -B./ ${multiarg} --print-multi-os-directory)
224- local MULTIDIR=$(${XGCC} -B./ ${multiarg} --print-multi-directory)
225+ local OS_MULTIDIR=$($(XGCC) ${multiarg} --print-multi-os-directory)
226+ local MULTIDIR=$($(XGCC) ${multiarg} --print-multi-directory)
227 local TODIR=${D}${LIBPATH}/${MULTIDIR}
228 local FROMDIR=
229