public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* CXXFLAGS and target libraries
@ 2007-12-06 18:36 Richard Sandiford
  2007-12-10  0:21 ` Mark Mitchell
  0 siblings, 1 reply; 2+ messages in thread
From: Richard Sandiford @ 2007-12-06 18:36 UTC (permalink / raw)
  To: gcc-patches

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: CXXFLAGS and target libraries
  2007-12-06 18:36 CXXFLAGS and target libraries Richard Sandiford
@ 2007-12-10  0:21 ` Mark Mitchell
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Mitchell @ 2007-12-10  0:21 UTC (permalink / raw)
  To: gcc-patches, rsandifo

Richard Sandiford wrote:

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

This makes sense to me.  If there are no objections within 48 hours,
please check it in.

-- 
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-12-10  0:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-12-06 18:36 CXXFLAGS and target libraries Richard Sandiford
2007-12-10  0:21 ` Mark Mitchell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).