Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Chicken and egg: How was the first linux gcc binary created??

1,350 views
Skip to first unread message

Tim Peoples

unread,
Oct 10, 1992, 8:49:26 AM10/10/92
to

As I was standing in the shower this morning I was thinking (I do
my best thinking in the shower) "How did Linus generate that first
gcc binary?" This was prompted by a newbie question about compilers
where he said something like "I can't compile a compiler until I have
a compiler to compile it."

I guess Linus is the only one who can answer this but I figured it
would also be of general interest. So Linus, how'd ya do it???


--

+--------------------------------------+-------------------------------------+
| Tim Peoples | The time has come the hacker said |
| t...@engr.uark.edu | to talk of many things, |
| Dept. of Computer Systems Engineering| of simms and sockets and semaphores |
| University of Arkansas, Fayetteville | of processes and pings.... |
+--------------------------------------+-------------------------------------+
| I need no disclaimer; nobody listens to what I have to say anyway!! |
+----------------------------------------------------------------------------+

H.J. Lu

unread,
Oct 10, 1992, 10:55:01 AM10/10/92
to
In article <1992Oct10.1...@engr.uark.edu> t...@engr.uark.edu writes:
>
> As I was standing in the shower this morning I was thinking (I do
>my best thinking in the shower) "How did Linus generate that first
>gcc binary?" This was prompted by a newbie question about compilers
>where he said something like "I can't compile a compiler until I have
>a compiler to compile it."
>
> I guess Linus is the only one who can answer this but I figured it
>would also be of general interest. So Linus, how'd ya do it???

I think I can answer this for Linus. The answer is cross-compiling.
After you decided the format of a.out and the system call interface,
you had to choose a compiler to port. Linus chose gcc, of course.
Linus only uses the best. Then you wrote the C library. You now could
cross-compile gcc from another machine. First build gas, gld, gar
and granlib running on host machine for Linux. Then

1. build gcc for host machine.
2. build gcc running on host machine but generating codes for Linux.
3. use the cross-compiling gcc to build gcc for Linux.

gcc 1.xx doesn't support those. You have to modify the gcc source
code. Before gcc 2.2.2, there is only some limited support. In gcc
2.3, you will get the full support for this purpose.

Hope I have made myself clear.

H.J.

David W. Summers

unread,
Oct 10, 1992, 1:03:18 PM10/10/92
to
t...@engr.uark.edu (Tim Peoples) writes:

I would guess that he (Linus) either got GCC running on MINIX and compiled
a cross-compiler with GCC or did the same thing on a Sun or some other
computer.

With GCC, it is fairly easy to have it compile itself as a cross-compiler
to target another machine.

- David Summers

--
"Never under-estimate the bandwidth of a station-wagon
David Summers full of tapes, hurtling down the highway."
d...@engr.uark.edu - Tanenbaum, "Computer Networks"

Cory West

unread,
Oct 10, 1992, 1:59:32 PM10/10/92
to
In article <1992Oct10.1...@engr.uark.edu>
t...@engr.uark.edu (Tim Peoples) writes:

> (I do my best thinking in the shower) "How did Linus generate that first
> gcc binary?" This was prompted by a newbie question about compilers
> where he said something like "I can't compile a compiler until I have
> a compiler to compile it."

Well, I recently wondered about this myself, but my questions were
answered when I built the Linux cross-compiler on my Sun4. The answer
that I have, unfortunately, won't completely answer your question: I compiled
gcc with itself. Well, actually, I used the sun version of gcc to build
the linux cross-compiler version of gcc (to a point) and then I used the
partially built linux cross-compiler to compile the rest of the distribution
and libraries.

I think the answer you're looking for is that it all started way back when :
a little assembler was written to assemble a better assembler which assembled a small
compiler which compiled a better compiler and so on, until gcc was built.

As for Linux, I think that Linus built it using Minix tools.

P.S. Yes, I have a working cross compiler for linux on my Sun4, but I don't have
a working linker. I plan to complete the installation and write some docs
for everyone else interested, but school is keeping me quite busy right now
(as I'm sure many of you can relate). Mail inquiries are welcome.

--
Cory West | School: cory...@rice.edu | Rice University, '94
P.O. Box 2011 | Home: co...@lambada.hou.tx.us | Team Wiess!
Houston, TX 77252 | POP Mail: corywe...@rice.edu | Phone: (713) 630-8858

Mitchell Brandsma

unread,
Oct 12, 1992, 12:15:23 AM10/12/92
to

> As I was standing in the shower this morning I was thinking (I do
>my best thinking in the shower) "How did Linus generate that first
>gcc binary?" This was prompted by a newbie question about compilers
>where he said something like "I can't compile a compiler until I have
>a compiler to compile it."

Gcc can be compiled with cc. Then to optimize it you'd normally recompile
gcc with itself. Ah, but then how did cc come about ? Yes, it can get
interesting. One thing I'd be interested in finding out is how much RAM +
swap space it takes gcc to compile itself.

> I guess Linus is the only one who can answer this but I figured it
>would also be of general interest. So Linus, how'd ya do it???

My question is how did cc get compiled (or was it carefully written in
assembler)? The chain must end somewhere.

Happy hacking, and remember: GCC RULZ!

- Mitchell Brandsma (mee...@DIALix.oz.au :)

David Giller

unread,
Oct 12, 1992, 4:04:00 AM10/12/92
to
mee...@DIALix.oz.au (Mitchell Brandsma) wrote:
>In <1992Oct10.1...@engr.uark.edu> t...@engr.uark.edu (Tim Peoples) writes:
>
>> As I was standing in the shower this morning I was thinking (I do
>>my best thinking in the shower) "How did Linus generate that first
>>gcc binary?" This was prompted by a newbie question about compilers
>>where he said something like "I can't compile a compiler until I have
>>a compiler to compile it."
>
>Gcc can be compiled with cc. Then to optimize it you'd normally recompile
>gcc with itself. Ah, but then how did cc come about ? Yes, it can get

Gcc can cross-compile. I beleive this is how the first gcc binary
came about. But memory fails me...

Also, remember that Linux, for a while, could co-exist with minix:
minix could have been used to compile for linux (a modified cc?).

-Dave
--
David Giller, Box 134 | Q: How many Oregonians does it take to screw in a light
Occidental College | bulb? A: Three. One to replace the bulb, and two to
1600 Campus Road | fend off all the Californians trying to share the
Los Angeles, CA 90041 | experience. ---------------------------rafe...@oxy.edu

Drew Eckhardt

unread,
Oct 12, 1992, 7:49:38 AM10/12/92
to
In article <1992Oct12.0...@DIALix.oz.au> mee...@DIALix.oz.au (Mitchell Brandsma) writes:
>In <1992Oct10.1...@engr.uark.edu> t...@engr.uark.edu (Tim Peoples) writes:
>
>> As I was standing in the shower this morning I was thinking (I do
>>my best thinking in the shower) "How did Linus generate that first
>>gcc binary?" This was prompted by a newbie question about compilers
>>where he said something like "I can't compile a compiler until I have
>>a compiler to compile it."
>
>Gcc can be compiled with cc. Then to optimize it you'd normally recompile
>gcc with itself. Ah, but then how did cc come about ? Yes, it can get
>interesting. One thing I'd be interested in finding out is how much RAM +
>swap space it takes gcc to compile itself.
>
>> I guess Linus is the only one who can answer this but I figured it

Nah. Getting gcc up on a new system with a supported processor,
with a gas supported processor, and binutils supported
.o format isn't that bad.


>>would also be of general interest. So Linus, how'd ya do it???

>
>My question is how did cc get compiled (or was it carefully written in
>assembler)? The chain must end somewhere.
>

Under Linux, gcc is cc. Problematic, eh?

The solution is to cross compile :

You compile a gcc with the native cc or gcc on another platform, that
produces i386 code in a.out format. Of course, you must have
any libraries needed present for the target system on the
host, as well as ld, as, etc.

Older versions of the binutils weren't too happy doing cross-endian
work, but on the same machine, different OS, you don't have that
problem.

I'd guess that gcc was originally cross compiled from under Minix 386.

--
Microsoft is responsible for propogating the evils it calls DOS and Windows,
IBM for AIX (appropriately called Aches by those having to administer it), but
marketing's sins don't come close to those of legal departments.
Boycott AT&T for their absurd anti-BSDI lawsuit.

David W. Summers

unread,
Oct 12, 1992, 8:13:04 PM10/12/92
to
mee...@DIALix.oz.au (Mitchell Brandsma) writes:

>One thing I'd be interested in finding out is how much RAM +
>swap space it takes gcc to compile itself.
>

Well, last time I compiled GCC on the Sun it took about 67 Megabytes to
hold all three versions of the compiler.

1. The gcc compiled with cc
2. The gcc compiled with gcc to optimize it.
3. The gcc compiled with the optimzed gcc to verify correct operation.

Rick Kelly

unread,
Oct 12, 1992, 3:57:20 PM10/12/92
to

Since he was using MINIX as his development base, it seems to me that he
could have brought up a first pass of gcc using the MINIX compiler. The
kinkiest part of it would have been the makefiles, but he could have also
brought up gnu make under MINIX. I believe that he was running the 386
32 bit patches for MINIX, so I would think that he would have had an ld
that could build a 386 protected mode image, since he built Linux kernels
that way.

--

Rick Kelly r...@rmkhome.UUCP unixland!rmkhome!rmk r...@frog.UUCP

Message has been deleted

Linus Torvalds

unread,
Oct 12, 1992, 6:08:43 AM10/12/92
to
> As I was standing in the shower this morning I was thinking (I do
>my best thinking in the shower) "How did Linus generate that first
>gcc binary?" This was prompted by a newbie question about compilers
>where he said something like "I can't compile a compiler until I have
>a compiler to compile it."
>
> I guess Linus is the only one who can answer this but I figured it
>would also be of general interest. So Linus, how'd ya do it???

As has already been noted, it's fairly easy to cross-compile gcc from
one system into another, and that is what I did.

The original gcc I used was the minix gcc (1.37.1) by Alan W Black (and
somebody.. forgotten who?), which did some very ugly things in order to
handle floating point. I used that to compile gcc-1.40 for minix, with
patches by Bruce Evans to clean up the floating point handling and some
of my own patches (I fooled around with gcc when learning about it, and
added a "-mstring-insns" switch which allowed gcc-1.40 to use the 386
string instructions for structure copying etc).

The minix-386 (thanks again, Bruce - without the 386 patches for minix I
would never have gotten anywhere) I was running by that time was able to
execute normal gcc binaries directly (the only major diff I did to minix
- and awb later made a better version of it), which is also the standard
linux binary format. So the same gcc binary running under minix could
make both minix and linux binaries: the only thing that differed was the
startup routine (crt0.o) and the standard library. My first binaries
used modified minix library routines, and the first shell I used under
linux (pre-0.01) was the minix bourne shell recompiled with those
library routines.

The binaries I later released used a library that was heavily based on
Earl Chew's (free) estdio package (thanks), with some minor routines by
me and some from various other sources (I think the minix termcap
routines were free etc). Back then (0.01-0.11), the biggest problem
with gcc were the libraries - estdio worked (even though it had it's
quirks) but many other routines were either incomplete or missing.
Porting many programs meant I had to write new library routines or find
them from some other source (like the early and very buggy glibc.a).

Also, I wasn't able to compile binaries under linux until version 0.10
or so - all the major first binaries (notably bash) were crosscompiled
from minix. The reason was the bad buffer-cache bugs in early linux
versions which made running gcc (which easily fills the buffer-cache)
impossible. 0.03 was able to run a gcc binary, but recompiling gcc
itself under linux led to weird crashes due to the buffer cache
corruption.

By 0.11-0.12, hlu had showed interest in maintaining gcc-2.x (I checked
out early snapshots of the alpha sources), which meant I had to
implement the math-emulation in the kernel, so that gcc wouldn't need
the patches for integer floating-point. By that time glibc.a also
started to be partly useable, so the linux libraries started using that
more and more (with some bad bugs as a result in the early versions).
The rest is history.

Linus

Chip Salzenberg

unread,
Oct 14, 1992, 9:20:54 AM10/14/92
to
[ followups to comp.unix.misc, for lack of a better place ]

According to torv...@klaava.Helsinki.FI (Linus Torvalds):


>The original gcc I used was the minix gcc (1.37.1) by Alan W Black (and
>somebody..

>The minix-386 (thanks again, Bruce - without the 386 patches for minix I
>would never have gotten anywhere) I was running by that time was able to
>execute normal gcc binaries directly (the only major diff I did to minix
>- and awb later made a better version of it), which is also the standard
>linux binary format.

So without Minix, Linux might not have been; or if it had, its
creation would have been much more difficult.

Now Linux and 386BSD can become starting points for new projects, too.

Source code is a wonderful thing, n'est ce pas?
--
Chip Salzenberg at Teltronics/TCT <ch...@tct.com>, <7371...@compuserve.com>
"I am truly as big a genius as all other Rush fans." -- Bruce Bufalini

0 new messages