Posted Jun 18, 2008 18:45 UTC (Wed) by pynm0001 (guest, #18379)
Parent article: Converting GCC to C++
As long as he doesn't go overboard this could be a really good thing, as
his experience with implementing the gold linker in C++ shows. C++ is
really the only modern language now designed to be a systems programming
language.
However gcc is a very large program... I wonder if he'll be able to move it
over to C++ with a clean design at the same time as gcc proper is being
developed?
Problems: Fewer alternative C++ compilers, so harder to test against 'Trusting Trust' attack
Posted Jun 18, 2008 18:55 UTC (Wed) by dwheeler (guest, #1216)
[Link]
There is a downside: Countering the "Trusting Trust" attack (as made well-known by Ken Thompson). There _IS_ a counter to this attack, but it requires have a second C++ compiler that isn't subverted the same way.
It's relatively easy to develop a C compiler that generates running code (may not be efficient, but it runs). It's harder to create a C++ compiler. Thus, there are more C compilers, which can act as a check on the gcc C compiler.
Problems: Fewer alternative C++ compilers, so harder to test against 'Trusting Trust' attack
Posted Jun 18, 2008 19:12 UTC (Wed) by pynm0001 (guest, #18379)
[Link]
Um, fair enough, but this is like using autoconf so that your program can build on 10 year old
AIX machines... it's optimizing for a problem that only precious few people care about, and the
other 99% of people who could benefit would instead have to suffer. Which is why we have the
explosion in new build systems... :-/
Those who are really worried that Ubuntu has corrupted their g++ binaries can use pcc to
compile an older version of gcc I suppose.
But you leave out one thing. Can an ANSI C compiler build gcc? I'm pretty sure that gcc
requires gcc-extensions to C to build at this point anyways so you already need to trust gcc if you
use it as your compiler. In addition if you look at Ian's slides on how things could look I would claim
that a C++ implementation would at least be easier to perform code review on, and even static
analysis.
Actually you could simply build a current g++ and place it on read-only media and use it to build
the new C++-based gcc. If it's different from the installed version then perhaps there has been the
malware code slipped into the compiler as described in Thompson's article. But I don't see how
simply having the compiler in C helps in this case. You still need a "safe" version of gcc, and that
already compiles C++.
Problems: Fewer alternative C++ compilers, so harder to test against 'Trusting Trust' attack
Posted Jun 18, 2008 19:19 UTC (Wed) by willy (subscriber, #9762)
[Link]
> Can an ANSI C compiler build gcc?
Yes. Indeed, until a few years ago, GCC could be compiled with pre-ANSI compilers.
Thankfully, functions now have prototypes.
On the trusting trust issue, there's nothing to stop you starting with your own trusted C
compiler, compiling gcc/g++ 4.3, then using those to compile gcc/g++ 5.0.
Converting GCC to C++
Posted Jun 18, 2008 19:10 UTC (Wed) by ncm (subscriber, #165)
[Link]
The conversion of Gcc will be fundamentally different from gld -> gold. He will start by just
compiling Gcc with g++. Then he will re-write parts that have been problems in C to use
safer, more powerful C++ constructs.
Converting GCC to C++
Posted Jun 18, 2008 19:46 UTC (Wed) by pynm0001 (guest, #18379)
[Link]
Sounds good then. I just got through reading the slides and I think there could be great gain by
doing nothing more than converting the already-existing object-oriented code (like TARGETS) to
appropriate C++ and using the standard C++ containers instead of the various ad-hoc routines that
look to be scattered in the code.
Converting GCC to C++
Posted Jun 18, 2008 20:55 UTC (Wed) by jordanb (subscriber, #45668)
[Link]
It seems to me that trying to do it piecemeal line-by-line is a good way to end up with "C
code implemented in C++" which is pretty good way to get the worst of both worlds. Anyway his
idea seems to be driving at using RAII for the objects so that he can then start using
exceptions. But wouldn't he have to get destructors for *everything* before he uses any
exception? Otherwise he'll have old C stuff leaking all over the place whenever exceptions
cause it to skip the free call.
So there'd be a huge front-end cost to this no matter what. And given that it seems like the
argument for using C++ (that it's compatible with C) ends up being quite a bit weaker. GCC's
already got a ton of Ada code in the GNAT front end, perhaps he should look at remaking the
backends in Ada and making the front ends all self-hosting. Having to rewrite each component
would at least discourage the appeal of mushing the new C++ code into the old C design.
Converting GCC to C++
Posted Jun 18, 2008 21:16 UTC (Wed) by ncm (subscriber, #165)
[Link]
It's easy to speculate, but since he's actually doing the work, we'll see. If it's not really
better, it won't be merged.
Converting GCC to C++
Posted Jun 19, 2008 12:03 UTC (Thu) by nix (subscriber, #2304)
[Link]
'Start using exceptions' is probably quite a bit less important than 'start using typechecked
STL structures in place of rather horrible macros without type-checking'.
Converting GCC to C++
Posted Jun 18, 2008 22:36 UTC (Wed) by pphaneuf (subscriber, #23480)
[Link]
The greatest thing is that C is almost all the time C++. You don't necessarily have to use classes or templates. In my experience, just having stronger type checking is already a big win over plain C. Then you can do a few easy things like using a vector<Foo> instead of a manually managed array of Foo, and so on, making for that fewer bugs.
Converting GCC to C++
Posted Jun 19, 2008 0:27 UTC (Thu) by pphaneuf (subscriber, #23480)
[Link]
If he gets numbers (including source code size) half as nice as what he got with gold, it should be a shoo-in. ;-)
Converting GCC to C++
Posted Jun 19, 2008 15:06 UTC (Thu) by renox (guest, #23785)
[Link]
> C++ is really the only modern language now designed to be a systems programming language.
Uh? Only because you don't know the other ones..
The D language is also designed to be a system programming language.
And there is Lisaac (don't know much about it except that it has a syntax that I dislike)
http://isaacproject.u-strasbg.fr/