public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Compiling GCC with g++: a report
@ 2005-05-23 11:50 Gabriel Dos Reis
  2005-05-23 12:22 ` Ranjit Mathew
                   ` (6 more replies)
  0 siblings, 7 replies; 106+ messages in thread
From: Gabriel Dos Reis @ 2005-05-23 11:50 UTC (permalink / raw)
  To: gcc; +Cc: jason, mark, dberlin


Hi,

  I spent the week-end trying to get GCC -- mainline -- compilable
(i.e. those compoenents written in C) with a C++ compiler (e.g. g++).

My summary is:  It is largely doable and it is within our reach at this
point of development.  More specifically, I successfully got all
files necessary to build a native GNU C compiler on an i686-pc-linux-gnu.
Attempt to get the GNU C++ compiler through the same massage is
underway (but I'm going to bed shortly ;-)).

I think this project is beneficial to GCC for several reasons:

  (1) for testing purposes, we can use a compiler with stricter type
      checking.

  (2) there have been lots of discussions about more static typing in
      the data structures, but so far we haven't made anything
      concrete.  Partly because, we need this sort of preliminary
      preparation of thee source tree.  We can have infinite debates
      about the merits of such approaches, but I think a way to know
      is to do actual experiments and we better start making that
      possible now.

  (3) It might open the door for more contributions and foster more
      free software based on GCC.

  (4) <insert your favorite reasons why you would like to see this happen>.


What I have learnt from this little experience.  Well, the source code
seems to have been carefully written to make sure that no lunatic
(e.g. the author of this writing) will succeed in feeding a C++
compiler with GCC :-)

The first resistance seems to come from the pervasive use of the implicit
conversion void* -> T*, mostly with storage allocating functions.
We've recently introduced C++ friendly macros in libiberty, but we
have yet to take advantage of them.  We should start now.
(I also noted a happy confusion about the calling convention of the
function [x]calloc(), but it is mostly harmless as everything "multiply
nicely" in the end and we don't get burned by strict alignment
issues).  We should generalize the notation for GGC allocators and
alloca(). 


The second resistance is the pervasive use of C++ keywords (e.g. new,
class, template, try, catch, ...).  The first three are quite
frequent in the middle-end.


Third, there is some "type-punning" with enums, int and unsigned int,
where the middle-end (mostly) relies on implicit conversion from int
to enums.  That is a bit annoying but could be avoided as most of the
time, we do have names for those integer constants.  For example, we
should be using EXPAND_NORMAL instead of 0, or VOIDmode, instead of
0, TV_TOTAL instead of 0, etc.  At this point, I should also note that
not implicit conversions between enums (c_tree_code <-> tree_code, or
rtx_code  <-> reg_note, etc.) is not supported in C++.  So, we should
probably arrange to make the relationship (mostly subsetting) between
more explicit, as opposed to throwing in casts.  Also, there are few
cases where we want to iterate over all the values of enumerations.
I've shamelessly used the following macros:

   #define NEXT(E)  ((__typeof__(E)) (E + 1))
   #define PREV(E)  ((__typeof__(E)) (E - 1))
   #define DECR(E)  (E = (__typeof__(E)) (E - 1))
   #define INCR(E)  (E = (__typeof__(E)) (E + 1))
   #define IOR(A,B) ((__typeof__(A)) (A | B))
   #define AND(A,B) ((__typeof__(A)) (A & B))
   #define XOR(A,B) ((__typeof__(A)) (A ^ B))

but I'm not suggesting that as real replacement; just reporting the
dirty tricks I did and I'm looking for better suggestions. 


Fourth, it appears that we're implicilty using C99's semantics of 
"extern inline" in our source -- when we have a pure C90 compiler that
does not understand "inline", we just #define inline to nothing so we
don't get into trouble.  With a C++ compiler, we're in trouble because
an inline function needs to be defined in every translation where it
is used.  So, I either move the affected functions to "static inline"
or just make then non-inline (cases are in hashtable.c and toplev.c).


Fifth, there is a slight difference between "const" in C and in C++.
In C++, a const variable implicitly has an internal linkage; so a
C++ compiler tends to optimize it out when its address is not taken
(so no storage is wasted).  This is an issue for the objects
automatically generated by the gengtype support machinery.  The are
supposed to have external linkage, so we need to explicitly say
"extern" in their definitions. 


Sixth, there is a real "mess" about name spaces.  It is true that
every C programmers knows the rule saying tags inhabit different name
space than variable of functions.  However, all the C coding standards
I've read so far usually suggest 

   typedef struct foo foo;

but *not*

   typedef struct foo *foo;

i.e. "bringing" the tag-name into normal name space to name the type
structure or enumeration is OK, but not naming a different type!  the
latter practice will be flagged by a C++ compiler.  I guess we may
need some discussion about the naming of structure (POSIX reserves
anything ending with "_t", so we might want to choose something so
that we don't run into problem.  However, I do not expect this issue
to dominate the discussion :-))


So, if various components maintainers (e.g. C and C++, middle-end,
ports, etc.)  are willing to help quickly reviewing patches we can
have this done for this week (assuming mainline is unslushed soon).
And, of course, everybody can help :-)

Thanks,


-- 
                                                        Gabriel Dos Reis
                                                         gdr@cs.tamu.edu
	Texas A&M University -- Department of Computer Science
	301, Bright Building -- College Station, TX 77843-3112

^ permalink raw reply	[flat|nested] 106+ messages in thread
* Re: Compiling GCC with g++: a report
@ 2005-05-25  5:26 Paul Schlie
  2005-05-25  6:10 ` DJ Delorie
  0 siblings, 1 reply; 106+ messages in thread
From: Paul Schlie @ 2005-05-25  5:26 UTC (permalink / raw)
  To: Gabriel Dos Reis, DJ Delorie; +Cc: gcc

> Gabriel Dos Reis <gdr at integrable-solutions dot net>
>| J Delorie <dj at redhat dot com> writes:
>| And the target can do this in tm.c:
>| 
>|       class machine_mode SImode ("SI", 32);
>|       class machine_mode V4QImode ("V4QI", 8, 0, 8, 4);
>| 
>| Then, the MI parts can obtain a mode with certain characteristics,
>| enumerate available modes, and get info about a given mode, but don't
>| have a compile-time identifier for a "well-known named" mode.
>
> I like it.
>
> However, that is orthogonal to changing the plain numeric value "0" to
> the named constant with current machinery, don't you believe?

Might it be more desirable for the compiler's code to only refer to target
"type" modes as opposed to "size" modes? Thereby avoiding the temptation to
incorrectly assume that any particular "size" mode, like SImode corresponds
to the targets int or int* mode for example?

Thereby the compiler's code should only refer to "type" modes:

  target_unit_mode:
  target_word_mode:
  target_vect_mode:

  target_char_mode;
  target_short_mode;
  target_int_mode;
  target_ptr_mode;
  target_long_mode:
  target_long_long_mode
  ...

Where then the target then defines their corresponding "size" modes:

  class machine_mode target_unit_mode ("QI", 8);
  class machine_mode target_word_mode ("HI", 16);
  class machine_mode target_vect_mode ("SI", 32);

  class machine_mode target_char_mode ("QI", 8);
  class machine_mode target_short_mode ("HI",16);
  class machine_mode target_int_mode ("HI", 32);
  class machine_mode target_ptr_mode ("HI", 16);
  class machine_mode target_long_mode ("SI", 32);
  class machine_mode target_long_long_mode ("SI", 32);
  ...


^ permalink raw reply	[flat|nested] 106+ messages in thread
* Re: Compiling GCC with g++: a report
@ 2005-05-25 19:27 Richard Kenner
  0 siblings, 0 replies; 106+ messages in thread
From: Richard Kenner @ 2005-05-25 19:27 UTC (permalink / raw)
  To: dj; +Cc: gcc

    And YES I have a port with multiple pointer sizes, and YES the
    customer wanted both sizes supported in a single compilation unit 

This is actually not that uncommon.

    Oh, and sometimes gcc randomly uses pointer_mode instead of Pmode.  I
    haven't a clue why there's a difference, or how badly gcc would break
    if pointer_mode and Pmode were different.  Ok, I lied, I *do* know how
    badly it breaks if they differ; I did try that at one point.

There have been a number of ports where these differ.  Though undoubtably
there are bugs in this support, it does basically work.

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

end of thread, other threads:[~2005-05-27  0:54 UTC | newest]

Thread overview: 106+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-05-23 11:50 Compiling GCC with g++: a report Gabriel Dos Reis
2005-05-23 12:22 ` Ranjit Mathew
2005-05-23 19:07   ` Tom Tromey
2005-05-23 18:04 ` Gabriel Dos Reis
2005-05-24  4:57 ` Gabriel Dos Reis
2005-05-24  4:59   ` Joseph S. Myers
2005-05-24 21:50   ` Kevin Handy
2005-05-25 12:02     ` Bernardo Innocenti
2005-05-24  5:54 ` Zack Weinberg
2005-05-24  6:04   ` Daniel Jacobowitz
2005-05-24  6:22     ` Gabriel Dos Reis
2005-05-24  6:29     ` Zack Weinberg
2005-05-24  6:31       ` Mark Mitchell
2005-05-24  7:08         ` Zack Weinberg
2005-05-24  7:09           ` Mark Mitchell
2005-05-24  7:39           ` Gabriel Dos Reis
2005-05-24  8:48             ` Zack Weinberg
2005-05-24 13:41               ` Gabriel Dos Reis
2005-05-25  0:47             ` Russ Allbery
2005-05-25  1:24               ` Gabriel Dos Reis
2005-05-24 16:07       ` Paolo Bonzini
2005-05-24 16:44       ` Daniel Jacobowitz
2005-05-24 23:53         ` Zack Weinberg
2005-05-25  0:06           ` Daniel Jacobowitz
2005-05-25  0:11             ` Richard Henderson
2005-05-25  0:22             ` Zack Weinberg
2005-05-25  0:26           ` Paolo Carlini
2005-05-25  0:37             ` Zack Weinberg
2005-05-25  0:43               ` Daniel Jacobowitz
2005-05-25  0:48                 ` Zack Weinberg
2005-05-25  1:02                   ` Paolo Carlini
2005-05-25  3:14                   ` Daniel Jacobowitz
2005-05-25 13:30                     ` libstdc++ soname and versioning (was: Re: Compiling GCC...) Paolo Carlini
2005-05-25 13:45                       ` Theodore Papadopoulo
2005-05-25 13:53                         ` libstdc++ soname and versioning Paolo Carlini
2005-05-25 14:18                           ` Theodore Papadopoulo
2005-05-25 14:51                             ` Gabriel Dos Reis
2005-05-25 14:52                             ` Paolo Carlini
2005-05-25 13:54                         ` libstdc++ soname and versioning (was: Re: Compiling GCC...) Gabriel Dos Reis
2005-05-25 14:35                           ` Theodore Papadopoulo
2005-05-25 16:18                   ` Compiling GCC with g++: a report Jason Merrill
2005-05-25 12:44               ` Christoph Hellwig
2005-05-25 13:33                 ` Florian Weimer
2005-05-27  3:10                 ` Marcin Dalecki
2005-05-24  6:13   ` Andrew Pinski
2005-05-24  6:25     ` Gabriel Dos Reis
2005-05-27  4:04     ` Marcin Dalecki
2005-05-24  6:18   ` Gabriel Dos Reis
2005-05-24  6:43     ` Zack Weinberg
2005-05-24  7:04       ` Mark Mitchell
2005-05-24  8:00         ` Gabriel Dos Reis
2005-05-25  3:45         ` Kaveh R. Ghazi
2005-05-25  7:45           ` DJ Delorie
2005-05-25  8:36             ` Gabriel Dos Reis
2005-05-25 13:38             ` Kaveh R. Ghazi
2005-05-26 13:40               ` Gabriel Dos Reis
2005-05-24  7:38       ` Gabriel Dos Reis
2005-05-24  8:32         ` Zack Weinberg
2005-05-24 13:18           ` Gabriel Dos Reis
2005-05-24 23:45             ` Zack Weinberg
2005-05-25  0:29               ` Gabriel Dos Reis
2005-05-25  0:37                 ` Zack Weinberg
2005-05-25  0:52                   ` DJ Delorie
2005-05-25  0:55                     ` Zack Weinberg
2005-05-25  1:02                       ` Ian Lance Taylor
2005-05-25  1:36                       ` DJ Delorie
2005-05-25  1:40                         ` Zack Weinberg
2005-05-25  2:24                           ` Gabriel Dos Reis
2005-05-25 21:37                           ` hidden enum constants (Was: Compiling GCC with g++: a report) Giovanni Bajo
2005-05-25  1:50                         ` Compiling GCC with g++: a report Gabriel Dos Reis
2005-05-25  2:20                           ` DJ Delorie
2005-05-25  1:47                       ` Gabriel Dos Reis
2005-05-25  2:08                         ` DJ Delorie
2005-05-25  2:36                           ` Gabriel Dos Reis
2005-05-25  3:34                             ` DJ Delorie
2005-05-25  5:01                               ` Gabriel Dos Reis
2005-05-25  1:12                   ` Gabriel Dos Reis
2005-05-25  1:47                     ` DJ Delorie
2005-05-25  3:20                       ` Gabriel Dos Reis
2005-05-27  1:20           ` Marcin Dalecki
2005-05-24 17:17         ` Paul Koning
2005-05-24 17:25           ` Andreas Schwab
2005-05-24 20:43             ` Joe Buck
2005-05-24 21:40               ` Dale Johannesen
2005-05-24 17:49           ` Gabriel Dos Reis
2005-05-24  6:26   ` Mark Mitchell
2005-05-24  6:54     ` Zack Weinberg
2005-05-24  7:04       ` Mark Mitchell
2005-05-24 15:03         ` Kai Henningsen
2005-05-25  9:51         ` Jason Merrill
2005-05-24 10:01 ` Florian Weimer
2005-05-24 14:22   ` Gabriel Dos Reis
2005-05-24 18:00 ` Diego Novillo
2005-05-24 20:41   ` Richard Guenther
2005-05-24 23:14   ` Kevin Handy
2005-05-27  3:47   ` Marcin Dalecki
2005-05-27  1:20 ` Marcin Dalecki
2005-05-25  5:26 Paul Schlie
2005-05-25  6:10 ` DJ Delorie
2005-05-25 11:46   ` Paul Schlie
2005-05-25 18:31     ` DJ Delorie
2005-05-25 21:41       ` Paul Schlie
2005-05-26  6:11         ` DJ Delorie
2005-05-26  8:15           ` Paul Schlie
2005-05-26 11:57             ` DJ Delorie
2005-05-25 19:27 Richard Kenner

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).