Hi,
native compilers are now built with -static-libstdc++ -static-libgcc (if
bootstrapped) because the switches are added to LDFLAGS during stage 2 and 3.
Nothing is done for stage 1 or cross-compilers, except for Ada where we force
the switches, but this is far from ideal as reported under the PR.
The attached patch enables -static-libstdc++ -static-libgcc for stage 1 and
cross-compilers if g++ is detected and the switches work, using the same idea
as for later stages (i.e. setting --with-stage1-ldflags if not already set).
It turns out that --with-stage1-ldflags is currently broken: LDFLAGS is
correctly passed and set in gcc/ at configure time during stage 1, but a
'make' invocation from the toplevel passes an empty LDFLAGS to gcc/.
Tested on x86_64-suse-linux, OK for the mainline?
2012-10-09 Eric Botcazou <ebotca...@adacore.com>
PR bootstrap/54820
* Makefile.tpl (STAGE1_FLAGS_TO_PASS): New variable.
(host_modules): Add STAGE1_FLAGS_TO_PASS to args.
* Makefile.in: Regenerate.
* configure.ac (have_static_libs): New variable and associated check.
(stage1-ldflags): Move to after stage1_libs and set to -static-libstdc++
-static-libgcc if stage1_libs is empty and have_static_libs is yes.
* configure: Regenerate.
gcc/ada
* gcc-interface/Make-lang.in (GCC_LINK): Remove -static-libstdc++
-static-libgcc.
--
Eric Botcazou
Index: Makefile.tpl
===================================================================
--- Makefile.tpl (revision 192137)
+++ Makefile.tpl (working copy)
@@ -615,6 +615,12 @@ EXTRA_HOST_FLAGS = \
FLAGS_TO_PASS = $(BASE_FLAGS_TO_PASS) $(EXTRA_HOST_FLAGS)
+# Flags to pass to stage1 or when not bootstrapping.
+
+STAGE1_FLAGS_TO_PASS = \
+ LDFLAGS="$${LDFLAGS}" \
+ HOST_LIBS="$${HOST_LIBS}"
+
# Flags to pass to stage2 and later makes.
POSTSTAGE1_FLAGS_TO_PASS = \
@@ -1161,7 +1167,7 @@ clean-stage[+id+]-[+prefix+][+module+]:
[+ all prefix="" subdir="$(HOST_SUBDIR)"
exports="$(HOST_EXPORTS)"
poststage1_exports="$(POSTSTAGE1_HOST_EXPORTS)"
- args="$(EXTRA_HOST_FLAGS)"
+ args="$(EXTRA_HOST_FLAGS) $(STAGE1_FLAGS_TO_PASS)"
poststage1_args="$(POSTSTAGE1_FLAGS_TO_PASS)" +]
.PHONY: check-[+module+] maybe-check-[+module+]
Index: configure.ac
===================================================================
--- configure.ac (revision 192137)
+++ configure.ac (working copy)
@@ -1182,6 +1182,22 @@ if test -z "$LD"; then
fi
fi
+# Check whether -static-libstdc++ -static-libgcc is supported
+have_static_libs=no
+if test "$GCC" = yes; then
+ saved_LDFLAGS="$LDFLAGS"
+
+ LDFLAGS="$LDFLAGS -static-libstdc++ -static-libgcc"
+ AC_MSG_CHECKING([whether g++ accepts -static-libstdc++ -static-libgcc])
+ AC_LANG_PUSH(C++)
+ AC_LINK_IFELSE([int main() {}],
+ [AC_MSG_RESULT([yes]); have_static_libs=yes],
+ [AC_MSG_RESULT([no])])
+ AC_LANG_POP(C++)
+
+ LDFLAGS="$saved_LDFLAGS"
+fi
+
ACX_PROG_GNAT
ACX_PROG_CMP_IGNORE_INITIAL
@@ -1478,17 +1494,6 @@ case $with_host_libstdcxx in
;;
esac
-# Linker flags to use for stage1 or when not boostrapping.
-AC_ARG_WITH(stage1-ldflags,
-[AS_HELP_STRING([--with-stage1-ldflags=FLAGS], [linker flags for stage1])],
-[if test "$withval" = "no" -o "$withval" = "yes"; then
- stage1_ldflags=
- else
- stage1_ldflags=$withval
- fi],
-[stage1_ldflags=])
-AC_SUBST(stage1_ldflags)
-
# Libraries to use for stage1 or when not bootstrapping.
AC_ARG_WITH(stage1-libs,
[AS_HELP_STRING([--with-stage1-libs=LIBS], [libraries for stage1])],
@@ -1500,6 +1505,23 @@ AC_ARG_WITH(stage1-libs,
[stage1_libs=$with_host_libstdcxx])
AC_SUBST(stage1_libs)
+# Linker flags to use for stage1 or when not bootstrapping.
+AC_ARG_WITH(stage1-ldflags,
+[AS_HELP_STRING([--with-stage1-ldflags=FLAGS], [linker flags for stage1])],
+[if test "$withval" = "no" -o "$withval" = "yes"; then
+ stage1_ldflags=
+ else
+ stage1_ldflags=$withval
+ fi],
+[stage1_ldflags=
+ # In stage 1, default to linking libstdc++ and libgcc statically with GCC
+ # if supported. But if the user explicitly specified the libraries to use,
+ # trust that they are doing what they want.
+ if test "$stage1_libs" = "" -a "$have_static_libs" = yes; then
+ stage1_ldflags="-static-libstdc++ -static-libgcc"
+ fi])
+AC_SUBST(stage1_ldflags)
+
# Libraries to use for stage2 and later builds. This defaults to the
# argument passed to --with-host-libstdcxx.
AC_ARG_WITH(boot-libs,
Index: gcc/ada/gcc-interface/Make-lang.in
===================================================================
--- gcc/ada/gcc-interface/Make-lang.in (revision 192137)
+++ gcc/ada/gcc-interface/Make-lang.in (working copy)
@@ -172,7 +172,7 @@ endif
# Strip -Werror during linking for the LTO bootstrap
GCC_LINKERFLAGS = $(filter-out -Werror, $(ALL_LINKERFLAGS))
-GCC_LINK=$(LINKER) $(GCC_LINKERFLAGS) -static-libgcc -static-libstdc++ $(LDFLAGS)
+GCC_LINK=$(LINKER) $(GCC_LINKERFLAGS) $(LDFLAGS)
# Lists of files for various purposes.