source: scripts/scripts/target-scripts/target-gcc.sh @ ad31873f

clfs-1.2clfs-2.1clfs-3.0.0-systemdclfs-3.0.0-sysvinitsystemdsysvinit
Last change on this file since ad31873f was ad31873f, checked in by Jim Gifford <clfs@…>, 18 years ago

r2539@server (orig r1260): ryan | 2006-03-10 06:07:41 -0800

r1336@rei: lfs | 2006-03-11 01:06:05 +1100
Add GCC PR20425 fixes to 4.1.0 release.
This fixes a multitude of sins, most noticably with libtool on multilib systems.
Iterative path searches the gcc driver performs should now search multilib directories first.


Submitted By: Ryan Oliver <ryan at pha dot com dot au>
Date: 2006-03-10
Initial Package Version: 4.1.0
Origin: GCC SVN Revision 108635 (diffed against 4.1.0 release)
Upstream Status: In GCC trunk
Description: Fix for PR20425


From http://gcc.gnu.org/ml/gcc-patches/2005-12/msg00818.html
---------------------------------8<------------------------------------
This gives the gcc driver a new path iteration function, for_each_path,
and uses it everywhere, making path iteration a little more consistent.
for_each_path uses the same path ordering as the existing find_file
function. I've also tweaked some of the existing find_a_file calls for
consistency, and uncovered and fixed some other bugs..


Functional changes are:


o %D library paths are printed in the same order as gcc uses elsewhere

when searching library directories, ie. all multilib paths are first.
http://gcc.gnu.org/ml/gcc-patches/2005-03/msg02044.html effectively
reverted by the rewrite because I believe the same speedup is gained
by searching the right dirs first.


o gcc -print-search-dirs prints library multilib paths followed by

non-multilib paths where before we just printed non-multilib paths.


o LIBRARY_PATH_ENV similarly includes multilib directories.


o All searches of startfile_prefixes now look in multilib dirs first

followed by non-multilib dirs. This changes the dirs we search for
spec files, and %include and %include_noerr in specs. Previously
we only searched the non-multilib dirs for specs files. I think this
change is worthwhile just for consistency, and the extension is
reasonable. For instance, it would allow different spec files to be
used for gcc -m64 vs. gcc -m32. However, if others think this wrong,
I won't argue. Consistency isn't everything.


o Some attempt made to prevent searching of duplicate paths. The old

find_file would search some paths twice (when multilib_dir was NULL
but multilib_os_dir non-NULL). We still search twice in some cases,
eg. /usr/lib/../lib and /usr/lib are considered different paths.


o find_a_file with last param (do_multi) true now searches both

multilib and non-multilib paths. Before, do_multi (well, the old
param name was multilib) meant just search multilib paths. This
isn't a user-visible change as the only place where find_a_file was
invoked with the last param true was from find_file, where we
immediately followed with a non-multilib find_a_file.


o Memory leaks fixed in is_directory.


o LIBRARY_PATH_ENV and COMPILER_PATH now only have existing

directories, making LIBRARY_PATH_ENV closer to %D paths. The
following lines (which I remove) in is_directory meant that
is_directory didn't do much for LIBRARY_PATH_ENV, except on
SMALL_ARG_MAX machines.


4278 ian #ifndef SMALL_ARG_MAX
4278 ian if (! linker)
4278 ian return 1;
4278 ian #endif


I'll also remove mention of SMALL_ARG_MAX in config and doc files
when I commit this change as this is the only place it is used.


o gcc -Bnon-dir-prefix- now works properly. The previously mentioned

is_directory peculiarity affected the following code.


43664 nickc /* Catch the case where the user has forgotten to append a
46063 jsm28 directory separator to the path. Note, they may be using
43664 nickc -B to add an executable name prefix, eg "i386-elf-", in
43664 nickc order to distinguish between multiple installations of
43664 nickc GCC in the same directory. Hence we must check to see
43664 nickc if appending a directory separator actually makes a
43664 nickc valid directory name. */
43664 nickc if (! IS_DIR_SEPARATOR (value [len - 1])
43664 nickc && is_directory (value, "", 0))
43664 nickc {
43767 ghazi char *tmp = xmalloc (len + 2);
43767 ghazi strcpy (tmp, value);
43767 ghazi tmp[len] = DIR_SEPARATOR;
43767 ghazi tmp[++ len] = 0;
43767 ghazi value = tmp;
43664 nickc }


Bootstrapped and regression tested powerpc64-linux and powerpc-linux on
a previous iteration of this patch missing is_directory fixes.
Currently running tests on this patch.



  • Property mode set to 100755
File size: 8.9 KB
Line 
1#!/bin/bash
2
3# cross-lfs target gcc build
4# --------------------------
5# $LastChangedBy$
6# $LastChangedDate$
7# $LastChangedRevision$
8# $HeadURL$
9#
10
11cd ${SRC}
12
13LOG="gcc-target.log"
14
15set_libdirname
16setup_multiarch
17
18if [ "${USE_SYSROOT}" = "Y" ]; then
19   BUILD_PREFIX=/usr
20   INSTALL_PREFIX="${LFS}${BUILD_PREFIX}"
21   INSTALL_OPTIONS="DESTDIR=${LFS}"
22else
23   BUILD_PREFIX=${TGT_TOOLS}
24   INSTALL_PREFIX="${TGT_TOOLS}"
25   INSTALL_OPTIONS=""
26fi
27
28if [ ! "${libdirname}" = "lib" ]; then
29   extra_conf="${extra_conf} --libdir=${BUILD_PREFIX}/${libdirname}"
30fi
31
32if [ "Y" = "${MULTIARCH}" ]; then
33   vendor_os=`echo ${TARGET} | sed 's@\([^-]*\)-\(.*\)@\2@'`
34   case ${TGT_ARCH} in
35      x86_64 )
36         TARGET=x86_64-${vendor_os}
37      ;;
38      sparc64* )
39         TARGET=sparc64-${vendor_os}
40      ;;
41      sparc* )
42         TARGET=sparc64-${vendor_os}
43      ;;
44      powerpc* | ppc* )
45         TARGET=powerpc64-${vendor_os}
46      ;;
47      s390* )
48         TARGET=s390x-${vendor_os}
49      ;;
50      mips*el* )
51         TARGET=mips64el-${vendor_os}
52      ;;
53      * )
54         # TODO: add some error messages etc
55         barf
56      ;;
57   esac
58else
59   # If we are not bi-arch, disable multilib
60   extra_conf="${extra_conf} --enable-multilib=no"
61
62   # HACK: this sets abi to n32 with mips... this should be handled
63   # by the multiarch funcs somehow... and set according to DEFAULTENV
64   case ${TGT_ARCH} in
65      mips* )
66         extra_conf="${extra_conf} --with-abi=${DEFAULTENV}"
67      ;;
68   esac
69fi
70
71# if target has no floating point unit, use soft float
72if [ "${WITHOUT_FPU}" = "Y" ]; then
73   extra_conf="${extra_conf} --with-float=soft"
74fi
75
76unpack_tarball gcc-${GCC_VER}
77
78#3.0 20030427
79# Cannot trust ${GCC_VER} to supply us with the correct
80# gcc version (especially if cvs).
81# Grab it straight from version.c
82cd ${SRC}/${PKGDIR}
83target_gcc_ver=`grep version_string gcc/version.c | \
84                sed 's@.* = \(\|"\)\([0-9.]*\).*@\2@g'`
85# As of gcc4, the above doesn't cut it... check gcc/BASE-VER
86if [ -z "${target_gcc_ver}" -a -f gcc/BASE-VER ]; then
87   target_gcc_ver=`cat gcc/BASE-VER`
88fi
89
90# Apply linkonce patch for gcc (should be fixed come gcc 3.4.4)
91cd ${SRC}/${PKGDIR}
92case ${target_gcc_ver} in
93   3.4.3 )
94      apply_patch gcc-3.4.3-linkonce-1
95      apply_patch gcc-3.4.0-arm-bigendian
96      apply_patch gcc-3.4.0-arm-nolibfloat
97      apply_patch gcc-3.4.0-arm-lib1asm
98      apply_patch gcc-3.4.3-clean_exec_and_lib_search_paths_when_cross-1
99   ;;
100   4.0.0 )
101      apply_patch gcc-4.0.0-fix_tree_optimisation_PR21173
102      apply_patch gcc-4.0.0-reload_check_uninitialized_pseudos_PR20973
103      apply_patch gcc-4.0.0-clean_exec_and_lib_search_paths_when_cross-1
104   ;;
105   4.1.0 )
106      apply_patch gcc-4.0.0-clean_exec_and_lib_search_paths_when_cross-1
107      apply_patch gcc-4.1.0-fix_PR20425
108   ;;
109   4.0.* | 4.1.* )
110      apply_patch gcc-4.0.0-clean_exec_and_lib_search_paths_when_cross-1
111   ;;
112esac
113
114# if we are using gcc-3.4x, set libexecdir to */${libdirname}
115case ${target_gcc_ver} in
116   3.4* | 4.* )
117      extra_conf="${extra_conf} --libexecdir=${BUILD_PREFIX}/${libdirname}"
118   ;;
119esac
120
121# HACK: should at least check if any of these are set first
122ARCH_CFLAGS="${TGT_CFLAGS} ${ARCH_CFLAGS}"
123
124# if target is same as build host, adjust build slightly to avoid running
125# configure checks which we cannot run
126if [ "${TARGET}" = "${BUILD}" ]; then
127   BUILD=`echo ${BUILD} | sed 's@\([_a-zA-Z0-9]*\)\(-[_a-zA-Z0-9]*\)\(.*\)@\1\2x\3@'`
128fi
129
130if [ ! "${USE_SYSROOT}" = "Y" ]; then
131   # LFS style build
132   #----------------
133
134   # source functions for required gcc modifications
135   . ${SCRIPTS}/funcs/cross_gcc-funcs.sh
136
137   # Alter the generated specs file to
138   #  o set dynamic linker to be under ${TGT_TOOLS}/lib{,32,64}
139   #  o set startfile_prefix_spec so we search for startfiles
140   #    under ${TGT_TOOLS}/lib/lib{,32,64}
141   gcc_specs_mod
142
143   # We need to stop cpp using /usr/include as the standard include directory.
144   # This is defined in gcc/cppdefault.c using STANDARD_INCLUDE_DIR
145   cpp_undef_standard_include_dir
146
147   # We need to override SYSTEM_HEADER_DIR so fixincludes only fixes
148   # headers under ${TGT_TOOLS}
149   fixincludes_set_native_system_header_dir
150fi
151
152# HACKS
153#-------
154# This here is a hack. mklibgcc runs the created xgcc for determining
155# the multilib dirs and multilib os dirs. Only problem here is we are
156# cross building a native compiler so we cannot actually run xgcc.
157# We get around this by substituting our cross-compiler here for xgcc,
158# by rights it should have the same specs and produce the expected results
159#
160# NOTE: with gcc-4.1 onwards we can just set GCC_FOR_TARGET to our cross-compiler
161#       and be done with the shenannigans
162
163extra_makeopts=""
164case ${target_gcc_ver} in
165   4.[1-9].* )
166      extra_makeopts="${extra_makeopts} GCC_FOR_TARGET=${HST_TOOLS}/bin/${TARGET}-gcc"
167   ;;
168   * )
169      cd ${SRC}/${PKGDIR}/gcc
170      test -f mklibgcc.in-ORIG ||
171         mv mklibgcc.in mklibgcc.in-ORIG
172
173      sed "s@\./xgcc@${HST_TOOLS}/bin/${TARGET}-gcc@g" \
174         mklibgcc.in-ORIG > mklibgcc.in
175
176      # A similar problem exists when setting MULTILIBS on the environment
177      # for the mklibgcc script for generation of libgcc.mk .
178      # Here we will force it to use our cross-compiler to produce the results
179      # of gcc --print-multi-lib
180      sed -i "/MULTILIBS/s@\$(GCC_FOR_TARGET)@${HST_TOOLS}/bin/${TARGET}-gcc@g" \
181         Makefile.in
182   ;;
183esac
184
185# When cross-building a target native compiler we run into big issues
186# when determining assembler and linker features required for tls support,
187# ( not to mention which nm, objdump et al to use ) during the configures
188# triggered by make.
189#
190# Gcc's configury does not take into account the fact that when cross
191# building the target native compiler we are _still_ actually cross-compiling.
192# As far as it is concerned during the final configure fragment host = target,
193# it doesn't check whether host = build.
194#
195# It then performs its checks for binutils components as if this was a standard
196# host native build.
197#
198# If a target native binutils was installed before attempting to build gcc
199# it will try to use the created ld, as etc under ${TGT_TOOLS}
200# This obviously will not work, they will not run on the host.
201#
202# If the target native binutils hasn't been built yet it will use the
203# as ld et al from the _build_ host.
204# This quite frankly sucks rocks.
205#
206# The following patch fixes this behaviour, enforcing usage of our
207# cross-tools for configure checks if host = target and host != build
208#
209# NOTE: 20050507 This doesn't appear to be necessary for gcc 4.x :-)
210#       This of course will have to be checked thoroughly...
211
212# TODO: Add patches for gcc-3.3 series as well
213cd ${SRC}/${PKGDIR}
214case ${target_gcc_ver} in
215   3.4* )
216      apply_patch gcc-3.4.1-fix_configure_for_target_native
217   ;;
218   4.* )
219      # set AS_FOR_TARGET and LD_FOR_TARGET so these are used for feature checks...
220      extra_makeopts="${extra_makeopts} AS_FOR_TARGET=${HST_TOOLS}/bin/${TARGET}-as"
221      extra_makeopts="${extra_makeopts} LD_FOR_TARGET=${HST_TOOLS}/bin/${TARGET}-ld"
222   ;;
223esac
224#
225# End HACKS
226
227test -d ${SRC}/gcc-${GCC_VER}-target &&
228   rm -rf ${SRC}/gcc-${GCC_VER}-target
229
230mkdir -p ${SRC}/gcc-${GCC_VER}-target &&
231cd ${SRC}/gcc-${GCC_VER}-target &&
232
233max_log_init Gcc ${GCC_VER} cross-pt2 ${CONFLOGS} ${LOG}
234#CONFIG_SHELL=/bin/bash \
235CFLAGS="-O2 -pipe" \
236CXXFLAGS="-O2 -pipe" \
237CC="${TARGET}-gcc ${ARCH_CFLAGS}" \
238../${PKGDIR}/configure --prefix=${BUILD_PREFIX} \
239   --build=${BUILD} --host=${TARGET} --target=${TARGET} \
240   --enable-languages=c,c++ --enable-__cxa_atexit \
241   --enable-c99 --enable-long-long --enable-threads=posix \
242   --disable-nls --enable-shared ${extra_conf} \
243   >> ${LOGFILE} 2>&1 &&
244echo " o Configure OK" || barf
245#   --enable-languages=c,c++,f77,objc,ada,java,pascal,treelang --enable-__cxa_atexit \
246#   --enable-version-specific-runtime-libs \
247
248min_log_init ${BUILDLOGS} &&
249make ${PMFLAGS} BOOT_LDFLAGS="-s" BOOT_CFLAGS="-O2 ${HOST_CFLAGS} -pipe" \
250   STAGE1_CFLAGS="-O2 ${HOST_CFLAGS} -pipe" ${extra_makeopts} all \
251   >> ${LOGFILE} 2>&1 &&
252echo " o Build OK" || barf
253
254min_log_init ${INSTLOGS} &&
255make ${INSTALL_OPTIONS} install \
256   >> ${LOGFILE} 2>&1 &&
257echo " o Install OK" || barf
258
259if [ ! "${USE_SYSROOT}" = "Y" ]; then
260   # Prep new root for target native glibc build
261   libdirs="${libdirname}"
262   if [ "Y" = "${MULTIARCH}" ]; then libdirs="lib lib32 lib64" ; fi
263   for dir in ${libdirs} ; do
264      if [ -d ${TGT_TOOLS}/${dir} ]; then
265         test -d ${LFS}/usr/${dir} || mkdir -p ${LFS}/usr/${dir}
266         ln -sf ../..${TGT_TOOLS}/${dir}/libgcc_s.so.1 \
267            ${LFS}/usr/${dir}/libgcc_s.so.1
268         test -f ${TGT_TOOLS}/${dir}/libgcc_s.so &&
269            ln -sf libgcc_s.so.1 ${LFS}/usr/${dir}/libgcc_s.so
270         test -f ${TGT_TOOLS}/${dir}/libgcc_s_32.so &&
271            ln -sf libgcc_s.so.1 ${LFS}/usr/${dir}/libgcc_s_32.so
272         test -f ${TGT_TOOLS}/${dir}/libgcc_s_64.so &&
273            ln -sf libgcc_s.so.1 ${LFS}/usr/${dir}/libgcc_s_64.so
274      fi
275   done
276fi
277
278test -L ${INSTALL_PREFIX}/bin/cc || ln -s gcc ${INSTALL_PREFIX}/bin/cc
279
Note: See TracBrowser for help on using the repository browser.