Message from discussion
Chicken and egg: How was the first linux gcc binary created??Path: sparky!uunet!math.fu-berlin.de!news.netmbx.de!Germany.EU.net!mcsun!news.funet.fi!hydra!klaava!torvalds From: torva...@klaava.Helsinki.FI (Linus Torvalds) Newsgroups: comp.os.linux Subject: Re: Chicken and egg: How was the first linux gcc binary created?? Keywords: gcc linux egg chicken soup Message-ID: <1992Oct12.100843.26287@klaava.Helsinki.FI> Date: 12 Oct 92 10:08:43 GMT References: <1992Oct10.124926.12423@engr.uark.edu> Organization: University of Helsinki Lines: 59 In article <1992Oct10.124926.12...@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??? 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