diff --git a/.hgignore b/.hgignore
--- a/.hgignore
+++ b/.hgignore
@@ -1,3 +1,1 @@
 src
-patches/configure
-patches/configure.in
diff --git a/.hgtags b/.hgtags
--- a/.hgtags
+++ b/.hgtags
@@ -2,3 +2,4 @@
 4d6646f19caecfa0810d3341a8a1361cb529a7b4 ecm-6.3.p3
 62e5a142f7157c6dfa8ab59fc9228208326507ad ecm-6.3.p4
 14c0237361c1ffefdcece11d745f3381ec009a46 ecm-6.3.p5
+7ac46fc5997fb25668f35b8571f48af69f5859f4 ecm-6.3.p6
diff --git a/SPKG.txt b/SPKG.txt
--- a/SPKG.txt
+++ b/SPKG.txt
@@ -21,13 +21,18 @@
 == Dependencies ==
 
  * GMP/MPIR (Note: Python is *not* required for ordinary builds.)
+ * GNU patch
 
 == Special Update/Build Instructions ==
 
- * src/ contains "stable" upstream code, to which we currently apply
-   one upstream patch (to 'configure'). This (i.e., the file
-   'patches/configure') should be removed on the next upgrade to a stable
-   release.
+ * src/ contains "stable" upstream code, to which we currently apply a single
+   upstream patch (to 'configure'). The patch should be removed on the next
+   upgrade to a stable release.
+   Note that all autotools-generated files (and their support files) in src/
+   have been regenerated with newer versions of autotools (autoconf 2.68,
+   automake 1.11.3 and libtool 2.4.2), to make the size of the patch to the
+   also generated `configure` acceptable.  (See "Patches" section below for
+   why we don't patch `configure.in`, from which `configure` is created.)
  * GMP-ECM comes with a self-tuning feature; we could support
    that as an option ($SAGE_TUNE_*=yes) in the future.
  * We currently work around a linker bug on MacOS X 10.5 PPC (with
@@ -35,10 +40,9 @@
    This *might* get fixed in later upstream releases.
  * ECM currently does not (by itself) use the CC and CFLAGS settings
    from 'gmp.h' since we pass (other) options in CFLAGS, and CC is set
-   by Sage and might got set by the user (though MPIR currently doesn't
-   use its own CFLAGS for the same reason, which is fixed in an MPIR
-   2.1.3.p2 spkg). We now at least partially fix that s.t. "optimized"
-   code generation options ('-mcpu=...', '-mtune=...') are used by gcc.
+   by Sage and might got set by the user.  We now at least partially fix that
+   such that "optimized" code generation options ('-mcpu=...', '-mtune=...')
+   are used by gcc.
    Of course a user can also manually enable them by setting the "global"
    CFLAGS to e.g. '-march=native' on x86[_64] systems, or '-mcpu=...' and
    '-mtune=...' on other architectures where "native" isn't supported.
@@ -50,9 +54,60 @@
    "-mcpu=...", and perhaps pass a more generic "--host=..." to 
    'configure'. (MPIR honors '--enable-fat' to some extent, but this
    option isn't used on anything other than x86 / x86_64.)
+ * Check whether the work-around for GCC 4.7 on ia64 is still appropriate, i.e.
+   adapt it in case the issue has been fixed in later GCC versions of the 4.7
+   release series.  (Although the bug currently affects only GCC 4.7.0, it
+   seems unlikely that it will be fixed soon, hence we apply the work-around
+   for any GCC 4.7.x version on ia64.)
+   See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48496 for details and the
+   current status of that bug.
+ * We could save some space by removing the `src/build.vc9/` directory which
+   isn't used in Sage.  (It gets probably more worth in case also directories /
+   files for later versions of Microsoft Visual C get added.) 
+
+=== Patches ===
+ * configure.patch:
+   - Disable "asm-redc" on 32-bit Darwin PPCs (upstream revision 1516 / bug
+     #10646).
+     (Note that this upstream patch is likely to slow down GMP-ECM on 64-bit
+     PPC CPUs running (32-bit) MacOS X, since the extended instruction set of
+     the CPU is no longer exploitet.  A proper fix would just pass an option
+     to Apple's assembler to allow the use of the extended instruction set.)  
+   - Fix compilation error on x86 CPUs supporting SSE2. (Sage trac #10252,
+     upstream revision 1546).
+   Note that we don't patch `configure.in`, since it is only needed to generate
+   automatically-generated files in the source tree.  Patching `configure.in`
+   would force `automake` to be run, which could cause build failures on
+   systems where autotools aren't installed.
+
 
 == Changelog ==
 
+=== ecm-6.3.p6 (Leif Leonhardy, April 16th 2012) ===
+ * #12830: Add a work-around for GCC 4.7.x on ia64 (Itanium), since GMP-ECM
+   currently won't build with that and anything but `-O0` on that platform.
+ * Use `\{1,\}` instead of `\+` in `sed` patterns, which is more portable.
+ * Also support newer system-wide MPIR installations for printing their
+   settings.
+ * Use `patch` to apply patches.  Since the pre-patched `configure` in
+   `patches/` was created with a newer version of autotools (or, rather, the
+   original `configure` was created with an outdated version), the patch would
+   have been almost as large as the patched `configure` file itself.  Hence
+   I `autoreconf`ed the source tree with a patched `configure.in` (and almost
+   the latest versions of autotools), then created a patch to `configure`
+   from the resulting file(s).  Note that therefore `src/` isn't really vanilla
+   any more, although just the auto-generated files differ (which are still
+   made from vanilla upstream sources, including `configure.in`).
+   Add a "Patches" subsection and update "Special Update/Build Instructions".
+   Remove files in `patches/` from `.hgignore` (and also remove pre-patched
+   files from that directory); the patch to `configure` and the diff of
+   `configure.in` are [now] under revision control, which IMHO makes sense.
+ * Beautify (and simplify) the output with respect to options passed to
+   `configure`; print the settings of a few more environment variables that
+   GMP-ECM uses (in case they're set); add some messages, also mention
+   `--enable-assert` etc. if `SAGE_DEBUG=yes`.
+ * Remove unused test for GCC.
+
 === ecm-6.3.p5 (Leif Leonhardy, April 11th 2012) ===
  * #12830: Don't add `-march=native` if the assembler doesn't understand the
    instructions the compiler emits with that.  (E.g. the Apple/XCode assembler
diff --git a/patches/configure.patch b/patches/configure.patch
new file mode 100644
--- /dev/null
+++ b/patches/configure.patch
@@ -0,0 +1,85 @@
+--- src/configure	2012-04-16 21:51:42.586783117 +0200
++++ src-patched/configure	2012-04-16 22:13:59.096783235 +0200
+@@ -12343,7 +12343,7 @@
+ # asm_redc enabled by default for x86_64 and 64 bit PowerPC
+ if test "x$enable_asm_redc" = x; then
+   case $host in
+-    x86_64* | powerpc-apple-darwin* | powerpc64-*-linux*) enable_asm_redc=yes;;
++    x86_64*-*-* | powerpc-apple-darwin* | powerpc64-*-linux*) enable_asm_redc=yes;;
+     *) enable_asm_redc=no;;
+   esac
+ fi
+@@ -12351,8 +12351,35 @@
+ if test "x$enable_asm_redc" = xyes; then
+   case $host in
+     pentium4-*-* | pentium3-*-* | viac7-*-* | i786-*-*) ASMPATH=pentium4;;
+-    x86_64-*-*)  ASMPATH=x86_64;;
+-    powerpc-apple-darwin*) ASMPATH=powerpc64;;
++    x86_64*-*-*)  ASMPATH=x86_64;;
++# warning: with powerpc-apple-darwin* we can have ABI=32
++# see bug #10646 on the bug tracker, where config.guess says
++# powerpc-apple-darwin8.11.0 (this a 64-bit machine, but most applications
++# are compiled in 32 bits). It works with --disable-asm-redc.
++    powerpc-apple-darwin*)
++cat confdefs.h - <<_ACEOF >conftest.$ac_ext
++/* end confdefs.h.  */
++
++#if defined(__ppc__)
++#error
++#endif
++int
++main ()
++{
++
++  ;
++  return 0;
++}
++_ACEOF
++if ac_fn_c_try_cpp "$LINENO"; then :
++
++else
++  { $as_echo "$as_me:${as_lineno-$LINENO}: 32-bit PowerPC, disabling asm-redc" >&5
++$as_echo "$as_me: 32-bit PowerPC, disabling asm-redc" >&6;}
++                enable_asm_redc=no
++fi
++rm -f conftest.err conftest.i conftest.$ac_ext
++                          ASMPATH=powerpc64;;
+     powerpc64-*-linux*)
+ 
+ echo "include(<"$srcdir"/powerpc64/powerpc-defs.m4>)" >> $gmp_tmpconfigm4
+@@ -12363,7 +12390,9 @@
+     		   	  ASMPATH=athlon;;
+     *) as_fn_error $? "asm redc not available on this machine $host" "$LINENO" 5;;
+   esac
++fi
+ 
++if test "x$enable_asm_redc" = xyes; then
+ # do the necessary definitions and includes
+ 
+ $as_echo "#define NATIVE_REDC 1" >>confdefs.h
+@@ -12684,9 +12713,9 @@
+ main ()
+ {
+ #if (defined(__GNUC__) || defined(__ICL)) && defined(__i386__)
+-/* When there are no constraints, registers are referred to by
+-   single % sign, not double. Argh */
+-asm volatile ("pmuludq %xmm2, %xmm0");
++/* On some machines, a program without constraints may pass without -msse2 but
++   those with constraints in spv.c fail, thus we test with constraints here. */
++asm volatile ("pmuludq %%xmm2, %%xmm0" : : :"%xmm0");
+ #else
+ #error
+ #IRIXdoesnotexitaterrordirective
+@@ -12708,9 +12737,9 @@
+ main ()
+ {
+ #if (defined(__GNUC__) || defined(__ICL)) && defined(__i386__)
+-/* When there are no constraints, registers are referred to by
+-   single % sign, not double. Argh */
+-asm volatile ("pmuludq %xmm2, %xmm0");
++/* On some machines, a program without constraints may pass without -msse2 but
++   those with constraints in spv.c fail, thus we test with constraints here. */
++asm volatile ("pmuludq %%xmm2, %%xmm0" : : :"%xmm0");
+ #else
+ #error
+ #IRIXdoesnotexitaterrordirective
diff --git a/spkg-check b/spkg-check
--- a/spkg-check
+++ b/spkg-check
@@ -6,17 +6,19 @@
 fi
 
 # Note: Running the test suite should not involve (re)compilation,
-#       so we don't set CFLAGS et al. here.
+#       so we don't set CFLAGS et al. here.  (Their settings are
+#       stored in the Makefiles created by 'configure' anyway.)
 
 cd src
 
-echo "Running the GMP-ECM test suite..."
+echo
+echo "Now running GMP-ECM's test suite..."
 
 $MAKE check
 
 if [ $? -ne 0 ]; then
-    echo >&2 "Error: The GMP-ECM test suite failed."
+    echo >&2 "Error: GMP-ECM's test suite failed."
     exit 1
 fi
 
-echo "The GMP-ECM test suite passed."
+echo "GMP-ECM's test suite passed."
diff --git a/spkg-install b/spkg-install
--- a/spkg-install
+++ b/spkg-install
@@ -5,24 +5,23 @@
     exit 1
 fi
 
+cd src/
+
 ###############################################################################
 # Apply patches (if any):
 ###############################################################################
 
-# Patch configure (and configure.in):
-# - Disable asm-redc on 32-bit Darwin PPCs (upstream revision 1516 / bug #10646)
-# - Fix compilation error on x86 CPUs supporting SSE2. (Sage trac #10252,
-#   upstream revision 1546)
-echo "Copying patched files..."
-# Note that we don't patch configure.in here, since it is only needed
-# to generate automatically-generated files in the source tree.
-# Patching configure.in forces automake to be run, which may cause
-# build failures on systems where autotools aren't installed.
-cp -pf patches/configure src/
-if [ $? -ne 0 ]; then
-    echo >&2 "Error copying patched 'configure'."
-    exit 1
-fi
+ls ../patches/*.patch &>/dev/null &&
+echo "Applying patches to upstream sources..." &&
+for patch in ../patches/*.patch; do
+    basename "$patch"
+    patch -p1 <"$patch"
+    if [ $? -ne 0 ]; then
+        echo >&2 "Error: '$patch' failed to apply."
+        exit 1
+    fi
+done &&
+echo
 
 ###############################################################################
 # Set up environment variables, depending on SAGE_* settings:
@@ -34,8 +33,8 @@
 # processor-specific code, since ECM doesn't use them if we set our own:
 # (But currently MPIR doesn't provide optimized settings either if we pass
 # non-empty CFLAGS; of course the user could set such manually though.)
-gmp_cc_pat='/^[ 	]*#[ 	]*define[ 	]\+__GMP_CC[ 	]\+/s/.*"\([^"]*\)"/\1/p'
-gmp_cflags_pat='/^[ 	]*#[ 	]*define[ 	]\+__GMP_CFLAGS[ 	]\+/s/.*"\([^"]*\)"/\1/p'
+gmp_cc_pat='/^[ 	]*#[ 	]*define[ 	]\{1,\}__GMP_CC[ 	]\{1,\}/s/.*"\([^"]*\)"/\1/p'
+gmp_cflags_pat='/^[ 	]*#[ 	]*define[ 	]\{1,\}__GMP_CFLAGS[ 	]\{1,\}/s/.*"\([^"]*\)"/\1/p'
 gmp_header_file="$SAGE_LOCAL"/include/gmp.h
 
 gmp_cc=`sed -n -e "$gmp_cc_pat" "$gmp_header_file"`
@@ -54,6 +53,8 @@
     gmp_cflags=`sed -n -e "${gmp_cflags_pat/GMP/MPIR}" "$gmp_header_file"`
 esac
 
+# Extract GMP's/MPIR's settings of CC and CFLAGS from a system-wide installation
+# (if present); these are only printed, for informational purposes.
 system_gmp_h=""
 for incdir in /usr/include /usr/local/include; do
     if [ -f $incdir/gmp.h ]; then
@@ -63,11 +64,12 @@
 if [ -n "$system_gmp_h" ]; then
     system_gmp_cc=`sed -n -e "$gmp_cc_pat" $system_gmp_h`
     system_gmp_cflags=`sed -n -e "$gmp_cflags_pat" $system_gmp_h`
-fi
-
-cc_is_gcc=false
-if $CC -v 2>&1 | grep -i gcc &>/dev/null; then
-    cc_is_gcc=true;
+    case "$system_gmp_cc" in __MPIR_CC|"")
+        system_gmp_cc=`sed -n -e "${gmp_cc_pat/GMP/MPIR}" $system_gmp_h`
+    esac
+    case "$system_gmp_cflags" in __MPIR_CFLAGS|"")
+        system_gmp_cflags=`sed -n -e "${gmp_cflags_pat/GMP/MPIR}" $system_gmp_h`
+    esac
 fi
 
 
@@ -103,6 +105,9 @@
     # Add debug symbols and disable optimization:
     echo >&2 "Warning: Setting SAGE_DEBUG=yes completely disables optimization."
     CFLAGS="$CFLAGS -g -O0"
+    echo "You may in addition (or instead) pass '--enable-assert' and/or"
+    echo "'--enable-memory-debug' to GMP-ECM's 'configure' by setting (and"
+    echo "of course exporting) ECM_EXTRA_OPTS accordingly."
 else
     # Enable optimization, may be overridden by user settings:
     case "`uname -srm | tr ' ' '-'`" in
@@ -115,7 +120,7 @@
                 "PowerPC because of a linker (?) bug."
             echo >&2 "See http://trac.sagemath.org/sage_trac/ticket/5847#comment:35" \
                 "ff. for details."
-            echo ""
+            echo >&2
             CFLAGS="-O3 $CFLAGS"
             ;;
         *)
@@ -124,6 +129,23 @@
 fi
 
 
+# Work around a bug in GCC 4.7.0 which breaks the build on Itanium CPUs with
+# '-O3', '-O2' and '-O1' (cf. #12765, #12751, and the bug URL below.)
+if [ "`uname -m`" = ia64 ] && [ "`testcc.sh $CC`" = GCC ]; then
+    gcc_version=`$CC -dumpversion`
+    case "$gcc_version" in
+      4.7.*)
+        CFLAGS="$CFLAGS -O0 -finline-functions -fschedule-insns"
+        echo >&2 "Warning: Disabling almost all optimization due to a bug in (at least)"
+        echo >&2 "         GCC 4.7.0 on Itanium, which otherwise would break the build."
+        echo >&2 "         See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48496"
+        echo >&2 "         for current status and further details."
+        echo >&2 "         (And please report to e.g. sage-devel in case you feel this bug"
+        echo >&2 "          should already be fixed in GCC $gcc_version.)"
+    esac
+fi
+
+
 if [ "$SAGE_FAT_BINARY" = yes ]; then
     # XXX Disable SSE2 on x86? (by passing '--enable-sse2=no' to 'configure')
     # XXX Disable asm-redc? Or pass some "generic" '--host=...' to 'configure'?
@@ -182,30 +204,35 @@
 fi
 
 
-echo ""
+echo
 echo "Settings from SAGE_LOCAL/include/gmp.h:"
-echo "    CC=$gmp_cc"
-echo "    CFLAGS=$gmp_cflags"
+echo "  CC=$gmp_cc"
+echo "  CFLAGS=$gmp_cflags"
 if [ -n "$system_gmp_h" ]; then
     echo "Settings found in $system_gmp_h (currently not used):"
-    echo "    CC=$system_gmp_cc"
-    echo "    CFLAGS=$system_gmp_cflags"
+    echo "  CC=$system_gmp_cc"
+    echo "  CFLAGS=$system_gmp_cflags"
 fi
 
-echo "Using CC=$CC"
-echo "Using CFLAGS=$CFLAGS"
-echo "Using CPPFLAGS=$CPPFLAGS"
-echo "Using LDFLAGS=$LDFLAGS"
-echo "Using ABI=$ABI"
-echo "(These settings may get overridden by 'configure' or Makefiles.)"
-echo ""
+echo "Finally using:"
+echo "  CC=$CC"
+echo "  CFLAGS=$CFLAGS"
+echo "  CPP=$CPP"
+echo "  CPPFLAGS=$CPPFLAGS"
+test -n "$CCAS" && echo "  CCAS=$CCAS"
+test -n "$CCASFLAGS" && echo "  CCASFLAGS=$CCASFLAGS"
+echo "  LDFLAGS=$LDFLAGS"
+test -n "$LIBS" && echo "  LIBS=$LIBS"
+echo "  ABI=$ABI"
+echo "  M4=$M4"
+echo "(These settings may still get overridden by 'configure' or Makefiles.)"
 
-export CFLAGS # usually redundant, but safe(r)
+export CFLAGS # Not exported by 'sage-env'.  LDFLAGS are exported above if
+              # necessary.  We currently don't set (or modify) any other
+              # environment variables, so don't have to export them here.
 
 unset RM
 
-cd src
-
 ###############################################################################
 # Now configure ECM:
 # (Note: Building (also) a *shared* library is disabled by default.
@@ -219,24 +246,23 @@
 
 echo
 if [ -z "$ECM_EXTRA_OPTS" ]; then
-    echo "Configuring GMP-ECM with the following options:"
-    echo "    --prefix=\"$SAGE_LOCAL\""
-    echo "    --libdir=\"$SAGE_LOCAL/lib\""
-    echo "    --with-gmp=\"$SAGE_LOCAL\""
-    test -n "$SAGE_CONF_OPTS" && echo "    $SAGE_CONF_OPTS"
+    echo "Now configuring GMP-ECM with the following options:"
+else
+    echo "Now configuring GMP-ECM with additional options as specified by" \
+        "ECM_EXTRA_OPTS:"
+    echo "  $ECM_EXTRA_OPTS"
+    echo "Finally configuring GMP-ECM with the following options:"
+fi
+echo "  --prefix=\"$SAGE_LOCAL\""
+echo "  --libdir=\"$SAGE_LOCAL/lib\""
+echo "  --with-gmp=\"$SAGE_LOCAL\""
+for opt in $SAGE_CONF_OPTS $ECM_EXTRA_OPTS; do
+    echo "  $opt"
+done
+if [ -z "$ECM_EXTRA_OPTS" ]; then
     echo "You can set ECM_EXTRA_OPTS to pass additional parameters,"
     echo "e.g. \"--enable-shared\" to also build a *shared* library,"
     echo "or \"--disable-sse2\" if you encounter problems on a Pentium III system."
-else
-    echo "Using additional 'configure' options as specified with" \
-        "ECM_EXTRA_OPTS:"
-    echo "    $ECM_EXTRA_OPTS"
-    echo "Configuring ECM with the following options:"
-    echo "    --prefix=\"$SAGE_LOCAL\""
-    echo "    --libdir=\"$SAGE_LOCAL/lib\""
-    echo "    --with-gmp=\"$SAGE_LOCAL\""
-    test -n "$SAGE_CONF_OPTS" && echo "    $SAGE_CONF_OPTS"
-    echo "    $ECM_EXTRA_OPTS"
 fi
 echo
 
@@ -245,6 +271,7 @@
             $SAGE_CONF_OPTS $ECM_EXTRA_OPTS
 if [ $? -ne 0 ]; then
     echo >&2 "Error configuring GMP-ECM."
+    echo >&2 "(See above for the options passed to its 'configure'.)"
     exit 1
 fi
 
