public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Sandiford <rsandifo@nildram.co.uk>
To: gcc-patches@gcc.gnu.org
Subject: CXXFLAGS and target libraries
Date: Thu, 06 Dec 2007 18:36:00 -0000	[thread overview]
Message-ID: <87ejdz1xhm.fsf@firetop.home> (raw)

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

             reply	other threads:[~2007-12-06 18:36 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-12-06 18:36 Richard Sandiford [this message]
2007-12-10  0:21 ` Mark Mitchell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ejdz1xhm.fsf@firetop.home \
    --to=rsandifo@nildram.co.uk \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).