This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

CXXFLAGS and target libraries


I recently tried building a i686-pc-linux-gnu-hosted MIPS compiler
on x86_64-linux-gnu with CC="gcc -m32".  I had no 32-bit C++ library,
so the test for a C++ compiler failed, and CXXFLAGS was set to empty
in the toplevel makefile.  This meant that the C++ libraries were
built without optimisation and debugging info.

CFLAGS_FOR_TARGET already accounts for the possibility that CFLAGS
might not include -O2:

# During gcc bootstrap, if we use some random cc for stage1 then
# CFLAGS will be just -g.  We want to ensure that TARGET libraries
# (which we know are built with gcc) are built with optimizations so
# prepend -O2 when setting CFLAGS_FOR_TARGET.
CFLAGS_FOR_TARGET = -O2 $(CFLAGS) $(SYSROOT_CFLAGS_FOR_TARGET) \
	$(DEBUG_PREFIX_CFLAGS_FOR_TARGET)

but CXXFLAGS_FOR_TARGET doesn't.  Also, adding just -O2 is wrong in
the case of an empty CXXFLAGS: we need -g too.  (The same thing could
theoretically happen for CFLAGS, if you're using some odd bootstrap
compiler that doesn't even support -g.)

So with the current scheme, I think we need to add -O2 and -g to
the beginning of both CFLAGS_FOR_TARGET and CXXFLAGS_FOR_TARGET.
I think this fits better with what install.texi says:

--------------------------------------------------------------------------
If you want to save additional space during the bootstrap and in
the final installation as well, you can build the compiler binaries
without debugging information as in the following example.  This will save
roughly 40% of disk space both for the bootstrap and the final installation.
(Libraries will still contain debugging information.)

@smallexample
     make CFLAGS='-O' LIBCFLAGS='-g -O2' \
       LIBCXXFLAGS='-g -O2 -fno-implicit-templates' bootstrap
@end smallexample
--------------------------------------------------------------------------

At the moment, I think "make CFLAGS='-O'" would actually build (some?)
target libraries without debug info.  "make CFLAGS='-O -g0'" would still
build libraries without debug info after the patch; I'm not sure if that's
the way it supposed to be or not.  The interaction between CFLAGS, LIBCFLAGS
and *FLAGS_FOR_TARGET seems a little odd.

All in all, I have no great confidence that this is correct, but FWIW...
bootstrapped & regression-tested on i686-pc-linux-gnu, and regression-tested
on mipsisa64-elfoabi.

Richard


	* Makefile.tpl (CFLAGS_FOR_TARGET): Add -g.
	(CXXFLAGS_FOR_TARGET): Add -O2 -g.
	* Makefile.in: Regenerate.

Index: Makefile.tpl
===================================================================
--- Makefile.tpl	(revision 130651)
+++ Makefile.tpl	(working copy)
@@ -376,15 +376,17 @@ COMPILER_AS_FOR_TARGET=@COMPILER_AS_FOR_
 COMPILER_LD_FOR_TARGET=@COMPILER_LD_FOR_TARGET@
 COMPILER_NM_FOR_TARGET=@COMPILER_NM_FOR_TARGET@
 
-# During gcc bootstrap, if we use some random cc for stage1 then
-# CFLAGS will be just -g.  We want to ensure that TARGET libraries
-# (which we know are built with gcc) are built with optimizations so
-# prepend -O2 when setting CFLAGS_FOR_TARGET.
-CFLAGS_FOR_TARGET = -O2 $(CFLAGS) $(SYSROOT_CFLAGS_FOR_TARGET) \
+# During gcc bootstrap, if we use some random cc for stage1 then CFLAGS
+# might be empty or "-g".  We don't require a C++ compiler, so CXXFLAGS
+# might also be empty (or "-g", if a non-GCC C++ compiler is in the path).
+# We want to ensure that TARGET libraries (which we know are built with
+# gcc) are built with "-O2 -g", so prepend those options when setting
+# CFLAGS_FOR_TARGET and CXXFLAGS_FOR_TARGET.
+CFLAGS_FOR_TARGET = -O2 -g $(CFLAGS) $(SYSROOT_CFLAGS_FOR_TARGET) \
 	$(DEBUG_PREFIX_CFLAGS_FOR_TARGET)
 SYSROOT_CFLAGS_FOR_TARGET = @SYSROOT_CFLAGS_FOR_TARGET@
 DEBUG_PREFIX_CFLAGS_FOR_TARGET = @DEBUG_PREFIX_CFLAGS_FOR_TARGET@
-CXXFLAGS_FOR_TARGET = $(CXXFLAGS) $(SYSROOT_CFLAGS_FOR_TARGET) \
+CXXFLAGS_FOR_TARGET = -O2 -g $(CXXFLAGS) $(SYSROOT_CFLAGS_FOR_TARGET) \
 	$(DEBUG_PREFIX_CFLAGS_FOR_TARGET)
 LIBCFLAGS_FOR_TARGET = $(CFLAGS_FOR_TARGET)
 LIBCXXFLAGS_FOR_TARGET = $(CXXFLAGS_FOR_TARGET) -fno-implicit-templates
Index: Makefile.in
===================================================================
--- Makefile.in	(revision 130651)
+++ Makefile.in	(working copy)
@@ -373,15 +373,17 @@ COMPILER_AS_FOR_TARGET=@COMPILER_AS_FOR_
 COMPILER_LD_FOR_TARGET=@COMPILER_LD_FOR_TARGET@
 COMPILER_NM_FOR_TARGET=@COMPILER_NM_FOR_TARGET@
 
-# During gcc bootstrap, if we use some random cc for stage1 then
-# CFLAGS will be just -g.  We want to ensure that TARGET libraries
-# (which we know are built with gcc) are built with optimizations so
-# prepend -O2 when setting CFLAGS_FOR_TARGET.
-CFLAGS_FOR_TARGET = -O2 $(CFLAGS) $(SYSROOT_CFLAGS_FOR_TARGET) \
+# During gcc bootstrap, if we use some random cc for stage1 then CFLAGS
+# might be empty or "-g".  We don't require a C++ compiler, so CXXFLAGS
+# might also be empty (or "-g", if a non-GCC C++ compiler is in the path).
+# We want to ensure that TARGET libraries (which we know are built with
+# gcc) are built with "-O2 -g", so prepend those options when setting
+# CFLAGS_FOR_TARGET and CXXFLAGS_FOR_TARGET.
+CFLAGS_FOR_TARGET = -O2 -g $(CFLAGS) $(SYSROOT_CFLAGS_FOR_TARGET) \
 	$(DEBUG_PREFIX_CFLAGS_FOR_TARGET)
 SYSROOT_CFLAGS_FOR_TARGET = @SYSROOT_CFLAGS_FOR_TARGET@
 DEBUG_PREFIX_CFLAGS_FOR_TARGET = @DEBUG_PREFIX_CFLAGS_FOR_TARGET@
-CXXFLAGS_FOR_TARGET = $(CXXFLAGS) $(SYSROOT_CFLAGS_FOR_TARGET) \
+CXXFLAGS_FOR_TARGET = -O2 -g $(CXXFLAGS) $(SYSROOT_CFLAGS_FOR_TARGET) \
 	$(DEBUG_PREFIX_CFLAGS_FOR_TARGET)
 LIBCFLAGS_FOR_TARGET = $(CFLAGS_FOR_TARGET)
 LIBCXXFLAGS_FOR_TARGET = $(CXXFLAGS_FOR_TARGET) -fno-implicit-templates


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]