# HG changeset patch # User Michael Schloh von Bennewitz # Date 1301421874 -7200 # Node ID 4a34d7a82eabc4d1fc44593a8d02c4cbefce3f48 # Parent 4ecfc2416fd8fce7dc4915bb2f4bd21a4f4b55f7 Rework package yet again, correcting and introducing new buildconf logic: Conditionally disable bootstrap stage comparison correctly, correct english grammar, better find system as(1) and ld(1), indotruce detailed optimization option messages, more completely guess cpu types, allow profiled bootstrapping without a preinstalled GCC because many other compilers have long since implemented 64-bit arithmetic, instruct make to build sequentially (not in sparallel) when building a profiled bootstrap as GCC online documents recommend, and generally improve comment blocks. The single most important correction in this changeset relates to the GCC changed optimization policy since at least GCC 4.5, in which -march is always passed and not always correctly guessed. In the case of this package, allowing GCC to guess the architecture leads to wild build errors at various subcomponents (zlib, libgcc, libiberty...) and bootstrap stages. It seems quite platform specific, and the safest approach to correcting this seems to be explicitly always specifying the -march argument when bootstrapping GCC. Because the best choice 'native' is not available when bootstrapping using a foreign (non GCC) compiler, a guess is made according to rpmmacros l_platform in that case. It is questionable as to whether these recent optimization changes on the part of GCC or this package are compatible with each other, or if either are complete or correct at all. At least applying these corrections allows this package to build again in most cases test. diff -r 4ecfc2416fd8 -r 4a34d7a82eab gcc/gcc.spec --- a/gcc/gcc.spec Tue Mar 29 19:46:35 2011 +0200 +++ b/gcc/gcc.spec Tue Mar 29 20:04:34 2011 +0200 @@ -131,8 +131,11 @@ -e 's;(libdir)/gcc/;(libdir)/gcc%{V_comp}/;' \ `find . -name Makefile.in -type f -print` fi + %{l_shtool} subst \ + -e 's;^\(do-compare\) *\(=.*\);#\1-shouldnt-be-defined-here \2;' \ + config/*.mk case "%{l_platform -t}" in - amd64*-linux* ) + amd64-linux* ) %{l_shtool} subst \ -e 's/GLIBCXX_IS_NATIVE=false/GLIBCXX_IS_NATIVE=true/g' \ -e 's/test x.gcc_no_link = xyes/false/g' \ @@ -144,21 +147,19 @@ libstdc++-v3/include/ext/codecvt_specializations.h %build - # create build sub-directory + # create build subdirectory %{l_shtool} mkdir -p obj cd obj - # solve strange compatability problems + # locate ld(1) and as(1) accordingly %if "%{with_binutils}" == "yes" - # determine ld(1) and as(1) usage, allowing either - # one to be from the GNU distribution of binutils + # allow OpenPKG binutils LD=%{l_tool_locate ld ld} AS=%{l_tool_locate as as} %else - # locate ld(1) and as(1), using the GNU assembler - # but ignoring the presence of any OpenPKG linker - LD=`PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/ccs/bin:/opt/bin:/opt/sbin which ld` - AS=`PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/ccs/bin:/opt/bin:/opt/sbin which as` + # ignore OpenPKG binutils + LD=`PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/ccs/bin:/opt/bin:/opt/sbin:/usr/local/bin:/usr/local/sbin which ld` + AS=`PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/ccs/bin:/opt/bin:/opt/sbin:/usr/local/bin:/usr/local/sbin which as` %endif l_with_gnu_ld_as="" echo $LD | grep '^/' >/dev/null && l_with_gnu_ld_as="--with-ld=$LD" @@ -166,14 +167,14 @@ $LD --version /dev/null | grep "^GNU ld " >/dev/null && l_with_gnu_ld_as="${l_with_gnu_ld_as} --with-gnu-ld" || l_with_gnu_ld_as="${l_with_gnu_ld_as} --without-gnu-ld" $AS --version /dev/null | grep "^GNU assembler " >/dev/null && l_with_gnu_ld_as="${l_with_gnu_ld_as} --with-gnu-as" || l_with_gnu_ld_as="${l_with_gnu_ld_as} --without-gnu-as" - # determine threads usage + # determine threads use %if "%{with_threads}" == "yes" l_enable_threads="posix" %else l_enable_threads="single" %endif - # determine language usage + # determine language use l_enable_languages="c" %if "%{with_cxx}" == "yes" l_enable_languages="${l_enable_languages},c++" @@ -188,14 +189,14 @@ l_enable_languages="${l_enable_languages},f95" %endif - # disable GNU iconv usage + # disable GNU iconv use ( echo "am_cv_func_iconv=no" echo "am_cv_lib_iconv=no" ) >config.cache - - # platform specific config logic + # platforms failing 'compare' make target (see prep as well) case "%{l_platform -t}" in - *i?86-sunos* ) echo "gcc_cv_prog_cmp_skip=true" >>config.cache;; + *i?86-sunos* ) echo "gcc_cv_prog_cmp_skip=true" >>config.cache ;; + *amd64-linux* ) echo "gcc_cv_prog_cmp_skip=true" >>config.cache ;; esac # configure the package @@ -259,50 +260,67 @@ l_libcxxflags="$l_libcxxflags -pipe" } %if "%{with_optimize}" == "yes" + # GCC authors are not keeping up with optimized portability expectations + ( echo "As GCC advances its optimization logic becomes increasingly complex (and" + echo "buggy?) Since at least GCC 4.5, problems have been reported using arguments" + echo "-O, -mtune, or -march implicitly or explicitly during different bootstrap" + echo "stages as well as stage comparison and even the final installation." + echo "" + echo "Pay attention when building on one computer and installing on another as" + echo "problems may be platform specific. If in doubt, disable optimization." + ) | %{l_rpmtool} msg -b -t warn if [ ".$l_ccisgcc" = .yes ]; then - l_ia32=native + l_archia32=native; l_archia64=native; l_archamd64=native else - l_ia32=pentium3 + # CPU native detection only works with GCC (see driver-i386.c) + ( echo "Platform specific optimization is enabled, but detection of appropriate" + echo "native architecture is only possible when bootstrapping GCC using a pre-" + echo "installed GCC. The current build is using a different compiler, so to" + echo "provide any optimization at all a wild guess is made and a CPU type" + echo "hardcoded instead of using accurate native detection." + echo "" + echo "To achieve accurate optimization of GCC please install GCC first. Then" + echo "build this package a second time which will use GCC to bootstrap itself." + ) | %{l_rpmtool} msg -b -t notice + + # guess lowest common denominator CPU types + # http://en.wikipedia.org/wiki/(X86|X64-64) + # http://gcc.gnu.org/onlinedocs/gcc/i386-and-x86_002d64-Options.html + l_archia32=pentium3; l_archia64=nocona; l_archamd64=k8 fi + # this optimization logic is unportable and could cause problems + # if installing the resulting binary package on a different host! case "%{l_platform -t}" in - *i?86-* ) l_boot_cflags="$l_boot_cflags -mtune=$l_ia32" ;; *sun4[uv]-* ) l_boot_cflags="$l_boot_cflags -mtune=v9" ;; + *sun-* ) l_boot_cflags="$l_boot_cflags -mtune=v8" ;; + *i?86-* ) l_boot_cflags="$l_boot_cflags -march=$l_archia32" ;; + *ia64-* ) l_boot_cflags="$l_boot_cflags -march=$l_archia64" ;; + *amd64-* ) l_boot_cflags="$l_boot_cflags -march=$l_archamd64" ;; + * ) l_boot_cflags="$l_boot_cflags -mtune=generic" ;; esac l_cflags="$l_cflags -O" l_boot_cflags="$l_boot_cflags -O3 -fomit-frame-pointer" l_libcxxflags="$l_libcxxflags -O3 -fno-implicit-templates" %else -%if "%{with_optimize}" == "port" - # conservatively optimize the generated program code for portable use, - # also _tune_ for particular CPUs, but _without_ requiring these CPUs! - case "%{l_platform -t}" in - *i?86-* ) l_boot_cflags="$l_boot_cflags -mtune=generic" ;; - *sun4[uv]-* ) l_boot_cflags="$l_boot_cflags -mtune=v8" ;; - esac - l_cflags="$l_cflags -O" - l_boot_cflags="$l_boot_cflags -O2 -fomit-frame-pointer" - l_libcxxflags="$l_libcxxflags -O2 -fno-implicit-templates" -%else - # do not optimize at all to avoid problems + # don't optimize at all to avoid problems l_boot_cflags="$l_boot_cflags -O0" l_libcxxflags="$l_libcxxflags -O0" %endif -%endif +%if "%{with_profile}" == "yes" + maketarget="profiledbootstrap" + loc_makeflags="%{l_mflags}" + if [ ".$l_ccisgcc" != .yes ]; then + ( echo "A preinstalled GCC is recommended when bootstrapping a profiled GCC. If the" + echo "compiler used to bootstrap GCC doesn't support 64-bit arithmetic, then" + echo "either runtime or buildtime errors could occur. Regardless of this," + echo "parallel make logic is disabled according to profiling requirements." + echo "" + echo "If in doubt, stop now and start the build again with profiling disabled." + ) | %{l_rpmtool} msg -b -t warn + fi +%else maketarget="bootstrap" -%if "%{with_profile}" == "yes" - # GCC >= 3.4 supports a "profiledbootstrap" target to build an - # optimized version of itself through profiling. Because this - # requires a (bootstrapping) C compiler with 64-bit arithmetic, - # the whole approach is currently supported only if already - # building with GCC as the bootstrapping C compiler. - if [ ".$l_ccisgcc" = .yes ]; then - maketarget="profiledbootstrap" - else - ( echo "Building a profiled GCC requires GCC. Please install GCC" - echo "first and then build again with the profile option enabled." - ) | %{l_rpmtool} msg -b -t error - exit 1 - fi + loc_makeflags="%{l_mflags -O}" %endif case "%{l_platform -t}" in *64-* ) l_cflags="$l_cflags -fPIC"; l_cxxflags="$l_cxxflags -fPIC" ;; @@ -315,10 +333,10 @@ %endif # build the package - MAKE="%{l_make} %{l_mflags -O}" \ - %{l_make} %{l_mflags -O} \ + MAKE="%{l_make} ${loc_makeflags}" \ + %{l_make} ${loc_makeflags} \ GREP="grep" \ - MAKE="%{l_make} %{l_mflags -O}" \ + MAKE="%{l_make} ${loc_makeflags}" \ BOOT_CFLAGS="${l_boot_cflags}" \ CFLAGS="${l_cflags}" \ CXXFLAGS="${l_cxxflags}" \