This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH, build] Fix PR 37137
- From: Adam Nemet <anemet at caviumnetworks dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 9 Oct 2008 16:16:40 -0700
- Subject: [PATCH, build] Fix PR 37137
The problem in the bug is that currently CFLAGS_FOR_TARGET is used to build
host libraries (e.g., all-stage1-libiberty) which are built with the
pre-installed host compiler.
The behavior was changed by Paolo here:
http://gcc.gnu.org/ml/gcc-patches/2008-02/msg00818.html. STAGE1_LIBCFLAGS was
set to CFLAGS_FOR_TARGET, and STAGE1_LIBCFLAGS was passed as LIBCFLAGS and
CFLAGS_FOR_TARGET to the sub-makes.
In the first version of the patch STAGE1_LIBCFLAGS was set to @stage1_cflags@
which are valid host compiler flags. In the final version it was changed to
CFLAGS_FOR_TARGET. The motivation was this:
Before committing, I noticed that PR/32161 was marked as a dup of PR/32009,
but my previous patch did not fix it.
This alternative patch is better because it lets you just use
CFLAGS_FOR_TARGET to set the compilation flags for libgcc. Since
bootstrapped target libraries are never compiled with the native compiler,
it makes little sense to use different flags for stage1 and later
stages. And it also makes little sense to use a different variable than
CFLAGS_FOR_TARGET.
The root of the problem seems to be the coupling of LIBCFLAGS and
CFLAGS_FOR_TARGET. In stage1, setting the two to @stage1_cflags@ leads to
PR/32161 (stage1 libgcc is built unoptimized) whereas setting it to
CFLAGS_FOR_TARGET leads to current bug.
Alexandre's patch on the vta branch
(http://gcc.gnu.org/ml/gcc-patches/2008-10/msg00213.html) decouples the two.
Backporting that would probably fix this bug. A slight issue with the
approach taken there is that it completely removes STAGE1_LIBCFLAGS. (Another
issue is that the patch does further cleanup which might not be appropriate at
this stage). Having a separate variable for this seems to be beneficial as
explained by install.texi:
@code{BOOT_CFLAGS} does not apply to bootstrapped target libraries.
Since these are always compiled with the compiler currently being
bootstrapped, you can use @code{CFLAGS_FOR_TARGET} to modify their
compilation flags, as for non-bootstrapped target libraries.
Again, if the native compiler miscompiles the stage1 compiler, you may
need to work around this by avoiding non-working parts of the stage1
compiler. Use @code{STAGE1_LIBCFLAGS} to this end.
My fix does the decoupling and splits STAGE1_CFLAGS_FOR_TARGET out of
STAGE1_LIBCFLAGS. Now STAGE1_CFLAGS_FOR_TARGET can be initialized to
CFLAGS_FOR_TARGET and STAGE1_LIBCFLAGS to @stage1_cflags@.
Bootstrapped and regtested on {x86_64,mips64octeon}-unknown-linux-gnu.
Comments? OK?
Adam
PR target/37137
* Makefile.tpl (STAGE1_CFLAGS_FOR_TARGET): New variable.
(all-stage[+id+]-[+prefix+][+module+]): Use it in stage 1 for
CFLAGS_FOR_TARGET.
* Maekfile.in: Regenerate.
gcc/
* doc/install.texi: Change STAGE1_LIBCFLAGS to
STAGE1_CFLAGS_FOR_TARGET.
Index: Makefile.tpl
===================================================================
--- Makefile.tpl (revision 140961)
+++ Makefile.tpl (working copy)
@@ -370,7 +370,11 @@ STAGE2_CFLAGS=$(BOOT_CFLAGS)
STAGE3_CFLAGS=$(BOOT_CFLAGS)
STAGE4_CFLAGS=$(BOOT_CFLAGS)
-STAGE1_LIBCFLAGS=$(CFLAGS_FOR_TARGET)
+# Used during stage1 with host libraries.
+STAGE1_LIBCFLAGS=@stage1_cflags@
+# Used during stage1 with target libraries.
+STAGE1_CFLAGS_FOR_TARGET=$(CFLAGS_FOR_TARGET)
+
STAGE2_LIBCFLAGS=$(CFLAGS_FOR_TARGET)
STAGE3_LIBCFLAGS=$(CFLAGS_FOR_TARGET)
STAGE4_LIBCFLAGS=$(CFLAGS_FOR_TARGET)
@@ -945,9 +949,14 @@ all-stage[+id+]-[+prefix+][+module+]: co
cd [+subdir+]/[+module+] && \
$(MAKE) $(BASE_FLAGS_TO_PASS) \
CFLAGS="[+stage_cflags+]" CXXFLAGS="[+stage_cflags+]" \
- LIBCFLAGS="[+stage_libcflags+]" \
+ LIBCFLAGS="[+stage_libcflags+]"[+
+ IF prev +] \
CFLAGS_FOR_TARGET="[+stage_libcflags+]" \
- CXXFLAGS_FOR_TARGET="[+stage_libcflags+]" [+args+] [+
+ CXXFLAGS_FOR_TARGET="[+stage_libcflags+]"[+
+ ELSE prev +] \
+ CFLAGS_FOR_TARGET="$(STAGE1_CFLAGS_FOR_TARGET)" \
+ CXXFLAGS_FOR_TARGET="$(STAGE1_CFLAGS_FOR_TARGET)"[+
+ ENDIF prev +] [+args+] [+
IF prev +][+poststage1_args+][+ ENDIF prev
+] [+extra_make_flags+] \
$(TARGET-stage[+id+]-[+prefix+][+module+])
Index: gcc/doc/install.texi
===================================================================
--- gcc/doc/install.texi (revision 140961)
+++ gcc/doc/install.texi (working copy)
@@ -1848,7 +1848,7 @@ bootstrapped, you can use @code{CFLAGS_F
compilation flags, as for non-bootstrapped target libraries.
Again, if the native compiler miscompiles the stage1 compiler, you may
need to work around this by avoiding non-working parts of the stage1
-compiler. Use @code{STAGE1_LIBCFLAGS} to this end.
+compiler. Use @code{STAGE1_CFLAGS_FOR_TARGET} to this end.
If you used the flag @option{--enable-languages=@dots{}} to restrict
the compilers to be built, only those you've actually enabled will be