From: eonu24@castle.ed.ac.uk (I Reid)
Newsgroups: alt.os.linux,comp.os.linux
Subject: Installing Gcc2.1/Rebuilding 95c+ kernel: notes
Date: 14 Apr 92 00:02:06 GMT
Distribution: alt, comp
Organization: Edinburgh University

Solutions to 2 common questions
-------------------------------

1. How to install and use gcc 2.1
2. How to install and rebuild the 0.95c+ kernel using gcc 2.1

As usual, I welcome all and any comments to Iain_Reid@ed.ac.uk and I
will try to reply to them if the message warrants it. Please note that
I have not tried to compile 0.95c+ (or anything post 0.95a) with any
compiler other than gcc 2.1. I understand (from postings in
com/alt.os.linux) that this is possible but I have no details on it.
If anyone wants to write notes on this then please feel free to send
them to me and I will include them.

Iain

----------------------------------------------------------------------------

1. Installing and using gcc 2.1
-------------------------------

The information in this section is all from the gcc 2.1 FAQ (available
at tsx-11 and other archive sites). You should get this document and
read it well. It is clear and very informative.

GCC 2.1 WILL NOT WORK WITH PRE 0.95 KERNELS. IT REQUIRES AT LEAST 2MB
of RAM AND AT LEAST 4MB OF SWAP SPACE.

n.b. I did this while still running 0.95a with ps patches.


Q1. Which files do I need?

A1. 2.1lib.tar.Z
    2.1misc.tar.Z.
    binutils.tar.Z,
    2.1shared-x.tar.Z.
    Gcc 2.1 FAQ <------- essential!


Q2. What are the contents of them?

A2. - 2.1lib.tar.Z contains cc1, cc1plus and cpp.
    - 2.1misc.tar.Z contains gcc 2.1 drivers, header files, libraries,
      manual pages and installation instructions.
    - binutils.tar.Z contains binaries needed to run gcc 2.1
    - 2.1shared-x.tar.Z ..... erm, not to sure about this one. It
      contains some example precompiled shared libs stuff I think.


Installation
------------

1. Backup your old compiler. As root I went into /usr/bin,
   /usr/local/bin, /usr/local/lib and /usr/include and put all the gcc
   related stuff into a tar file (tar -cf tarfile file-to-archive for the
   first file and then tar -rf tarfile file-to-archive for all the rest).

   Do NOT throw this tar file away yet 'cos you may need part of it (or
   if nothing works, all of it).

   You should not have any C compiler on your system when you install
   2.1 (it has caused problems apparently).

2. From this point I will assume that xxxx is the directory where you
   have put the gcc 2.1 tar files. For me this was /tmp/new/gcc2.1.
   Type

# cd /usr
# tar xvpfz xxxx/2.1misc.tar.Z

   If you tar doesn't support the z option then uncompress the tar
   file before doing this and think about getting a better version. I
   use version 1.10 without problems (tar +version reports the version
   details) 

3. Read the FAQ in /usr/install/gcc2. This appears to be the same one
   as is at the archive sites but it doesn't hurt to have a look
   through it. When you've finished type

# cd /usr
# tar xvpfz xxxx/2.1lib.tar.Z

4. Run the installation script (took a bit of finding this one!) by
   typing

# cd /usr/install/gcc2
# inst2.x

   If this doesn't do anything check that you have execute permission
   set for it (chmod u+x inst2.x will make sure!). Note that you need
   the contents of binutils.tar.Z for this so if necessary type

# cd /usr
# tar xvpfz xxxx/binutils.tar.Z

   before trying again.

That's it! You now has gcc 2.1 installed on your system. My first test
was on some code that I'm working on and it failed abysmally with a
fatal signal 11 (internal compiler error) from ld. I renamed /usr/bin/ld
to /usr/bin/ld2.1 and retrieved my old ld from the tar file (ld-old in
the archives is equivalent). I made this /usr/bin/ld and everything
compiled properly.
------------------------------------------------------------

2. Installing and rebuilding the linux v0.95c+ kernel using gcc 2.1
-------------------------------------------------------------------

Full source code for the linux kernel is available at the archive sites
and it is useful to know how to rebuild the kernel from this code. This
is very easy to do.

You will need - the kernel source for the latest version (0.95c+)
              - gcc 2.1
              - a working copy of make (I use pmake from the archives)
              - 1.5 - 2 Mb of free disk space
              - gcc 2.1 FAQ (read the bit about a.out.h!)

n.b. you need the old ld to compile the kernel (even while running
under 95c+ with a.out.h changed it seems).


The standard place for the linux source tree is in /usr/src/linux so
if you don't have a /usr/src directory you will need to create one
with mkdir. Once you have done this move the tar file of the kernel
source (probably called linux-0.95c+.tar.Z) to /usr/src and type

tar -xzvf linux-0.95a.tar.Z

You should see a whole load of file names flashing by on the screen.
This is good. When tar finishes you should have a directory called
/usr/src/linux and this will have a number of subdirectories. You will
probably want to hang on to the original tar in case you want an
original source tree.

You might want to make a few small changes to the kernel source tree
at the point.

1. In the master makefile (/usr/src/linux/Makefile) you should choose
   the keyboard definition that suits you (round about line 12). For
   me this means changing


# KEYBOARD = -DKBD_FINNISH
KEYBOARD = -DKBD_US
# KEYBOARD = -DKBD_GR
# KEYBOARD = -DKBD_FR
# KEYBOARD = -DKBD_UK
# KEYBOARD = -DKBD_DK

to

# KEYBOARD = -DKBD_FINNISH
# KEYBOARD = -DKBD_US
# KEYBOARD = -DKBD_GR
# KEYBOARD = -DKBD_FR
KEYBOARD = -DKBD_UK
# KEYBOARD = -DKBD_DK


You should also tell make what your root device is by editing the bit
that looks like this 

#
# ROOT_DEV specifies the default root-device when making the image.
# This can be either FLOPPY, /dev/xxxx or empty, in which case the
# default of FLOPPY is used by 'build'.
#

# ROOT_DEV = /dev/hdb1

so that the rootdev entry matches what you use (the bit you ran mkfs
for). In mine I have the line

ROOT_DEV = /dev/hda2

Ok, now making sure that you are /usr/src/linux type

make

If your compiler is set up properly you should see something that
looks like this

------------------------------------------------------------
expr: not found
[: syntax error
Usage: date [-q] [[MMDDYY]hhmm[ss]]
touch include/linux/config.h
cpp -nostdinc -Iinclude -traditional boot/bootsect.S -o boot/bootsect.s
as86 -0 -a -o boot/bootsect.o boot/bootsect.s
ld86 -0 -s -o boot/bootsect boot/bootsect.o
cpp -nostdinc -Iinclude -traditional boot/setup.S -o boot/setup.s
as86 -0 -a -o boot/setup.o boot/setup.s
ld86 -0 -s -o boot/setup boot/setup.o
as -c -o boot/head.o boot/head.s
gcc  -Wall -O6 -fomit-frame-pointer   -nostdinc -Iinclude -c -o init/main.o init/main.c
init/main.c:23: warning: `fork' declarations disagree about `inline'
init/main.c:23: warning: static declaration for `fork' follows non-static
init/main.c:24: warning: `pause' declarations disagree about `inline'
init/main.c:24: warning: static declaration for `pause' follows non-static
init/main.c:26: warning: `sync' declarations disagree about `inline'
init/main.c:26: warning: static declaration for `sync' follows non-static
init/main.c:46: warning: `strcpy' declarations disagree about `inline'
init/main.c:184: warning: static declaration for `printf' follows non-static
(cd kernel; make CFLAGS="-Wall -O6 -fomit-frame-pointer ")
gcc -nostdinc -I../include -Wall -O6 -fomit-frame-pointer  -fno-omit-frame-pointer -c sched.c
as -c -o sys_call.o sys_call.s
gcc -nostdinc -I../include -Wall -O6 -fomit-frame-pointer   -c -o traps.o traps.c
as -c -o asm.o asm.s
gcc -nostdinc -I../include -Wall -O6 -fomit-frame-pointer   -c -o fork.o fork.c
gcc -nostdinc -I../include -Wall -O6 -fomit-frame-pointer   -c -o panic.o panic.c
gcc -nostdinc -I../include -Wall -O6 -fomit-frame-pointer   -c -o printk.o printk.c
gcc -nostdinc -I../include -Wall -O6 -fomit-frame-pointer   -c -o vsprintf.o vsprintf.c
gcc -nostdinc -I../include -Wall -O6 -fomit-frame-pointer   -c -o sys.o sys.c
gcc -nostdinc -I../include -Wall -O6 -fomit-frame-pointer   -c -o exit.o exit.c
exit.c: In function `do_exit':
exit.c:367: warning: `volatile' function does return
gcc -nostdinc -I../include -Wall -O6 -fomit-frame-pointer   -c -o signal.o signal.c
gcc -nostdinc -I../include -Wall -O6 -fomit-frame-pointer   -c -o mktime.o mktime.c
gcc -nostdinc -I../include -Wall -O6 -fomit-frame-pointer   -c -o ptrace.o ptrace.c
ld -r -o kernel.o sched.o sys_call.o traps.o asm.o fork.o  panic.o printk.o vsprintf.o sys.o exit.o  signal.o mktime.o ptrace.o
sync
(cd mm; make CFLAGS="-Wall -O6 -fomit-frame-pointer ")
gcc -nostdinc -I../include -Wall -O6 -fomit-frame-pointer   -c -o memory.o memory.c
gcc -nostdinc -I../include -Wall -O6 -fomit-frame-pointer   -c -o swap.o swap.c
ld -r -o mm.o memory.o swap.o
(cd fs; make CFLAGS="-Wall -O6 -fomit-frame-pointer ")
gcc -nostdinc -I../include -Wall -O6 -fomit-frame-pointer   -c -o open.o open.c
gcc -nostdinc -I../include -Wall -O6 -fomit-frame-pointer   -c -o read_write.o read_write.c
gcc -nostdinc -I../include -Wall -O6 -fomit-frame-pointer   -c -o inode.o inode.c
gcc -nostdinc -I../include -Wall -O6 -fomit-frame-pointer   -c -o file_table.o file_table.c
gcc -nostdinc -I../include -Wall -O6 -fomit-frame-pointer   -c -o buffer.o buffer.c
buffer.c: In function `check_disk_change':
buffer.c:124: warning: implicit declaration of function `put_super'
buffer.c:125: warning: implicit declaration of function `invalidate_inodes'
gcc -nostdinc -I../include -Wall -O6 -fomit-frame-pointer   -c -o super.o super.c
gcc -nostdinc -I../include -Wall -O6 -fomit-frame-pointer   -c -o block_dev.o block_dev.c
gcc -nostdinc -I../include -Wall -O6 -fomit-frame-pointer   -c -o char_dev.o char_dev.c
char_dev.c: In function `rw_mem':
char_dev.c:65: warning: implicit declaration of function `un_wp_page'
gcc -nostdinc -I../include -Wall -O6 -fomit-frame-pointer   -c -o stat.o stat.c
gcc -nostdinc -I../include -Wall -O6 -fomit-frame-pointer   -c -o exec.o exec.c
exec.c: In function `copy_strings':
exec.c:130: warning: `pag' may be used uninitialized in this function
exec.c: In function `do_execve':
exec.c:393: warning: implicit declaration of function `send_sig'
gcc -nostdinc -I../include -Wall -O6 -fomit-frame-pointer   -c -o pipe.o pipe.c
gcc -nostdinc -I../include -Wall -O6 -fomit-frame-pointer   -c -o namei.o namei.c
gcc -nostdinc -I../include -Wall -O6 -fomit-frame-pointer   -c -o fcntl.o fcntl.c
gcc -nostdinc -I../include -Wall -O6 -fomit-frame-pointer   -c -o ioctl.o ioctl.c
gcc -nostdinc -I../include -Wall -O6 -fomit-frame-pointer   -c -o select.o select.c
ld -r -o fs.o open.o read_write.o inode.o file_table.o buffer.o super.o  block_dev.o char_dev.o stat.o exec.o pipe.o namei.o  fcntl.o ioctl.o select.o
(cd fs/minix; make CFLAGS="-Wall -O6 -fomit-frame-pointer ")
gcc -nostdinc -I../../include -Wall -O6 -fomit-frame-pointer   -c -o minix_op.o minix_op.c
gcc -nostdinc -I../../include -Wall -O6 -fomit-frame-pointer   -c -o bitmap.o bitmap.c
gcc -nostdinc -I../../include -Wall -O6 -fomit-frame-pointer   -c -o truncate.o truncate.c
gcc -nostdinc -I../../include -Wall -O6 -fomit-frame-pointer   -c -o namei.o namei.c
gcc -nostdinc -I../../include -Wall -O6 -fomit-frame-pointer   -c -o inode.o inode.c
gcc -nostdinc -I../../include -Wall -O6 -fomit-frame-pointer   -c -o file_dev.o file_dev.c
ld -r -o minix.o minix_op.o bitmap.o truncate.o namei.o inode.o file_dev.o
(cd kernel/blk_drv; make CFLAGS="-Wall -O6 -fomit-frame-pointer ")
gcc -nostdinc -I../../include -Wall -O6 -fomit-frame-pointer   -c -o ll_rw_blk.o ll_rw_blk.c
gcc -nostdinc -I../../include -Wall -O6 -fomit-frame-pointer   -c -o floppy.o floppy.c
gcc -nostdinc -I../../include -Wall -O6 -fomit-frame-pointer   -c -o hd.o hd.c
gcc -nostdinc -I../../include -Wall -O6 -fomit-frame-pointer   -c -o ramdisk.o ramdisk.c
ar rcs blk_drv.a ll_rw_blk.o floppy.o hd.o ramdisk.o
sync
(cd kernel/chr_drv; make CFLAGS="-Wall -O6 -fomit-frame-pointer " KEYBOARD="-DKBD_UK")
gcc -nostdinc -I../../include -Wall -O6 -fomit-frame-pointer   -c -o tty_io.o tty_io.c
gcc -nostdinc -I../../include -Wall -O6 -fomit-frame-pointer   -c -o console.o console.c
console.c: In function `con_write':
console.c:815: warning: empty body in an else-statement
console.c:815: warning: empty body in an else-statement
cpp -nostdinc -I../../include -DKBD_UK -traditional keyboard.S -o keyboard.s
as -c -o keyboard.o keyboard.s
gcc -nostdinc -I../../include -Wall -O6 -fomit-frame-pointer   -c -o serial.o serial.c
as -c -o rs_io.o rs_io.s
gcc -nostdinc -I../../include -Wall -O6 -fomit-frame-pointer   -c -o tty_ioctl.o tty_ioctl.c
gcc -nostdinc -I../../include -Wall -O6 -fomit-frame-pointer   -c -o pty.o pty.c
gcc -nostdinc -I../../include -Wall -O6 -fomit-frame-pointer   -c -o lp.o lp.c
ar rcs chr_drv.a tty_io.o console.o keyboard.o serial.o rs_io.o  tty_ioctl.o pty.o lp.o
sync
(cd kernel/math; make CFLAGS="-Wall -O6 -fomit-frame-pointer " MATH_EMULATION="-DKERNEL_MATH_EMULATION")
gcc -nostdinc -I../../include -Wall -O6 -fomit-frame-pointer  -DKERNEL_MATH_EMULATION  -c -o emulate.o emulate.c
gcc -nostdinc -I../../include -Wall -O6 -fomit-frame-pointer  -DKERNEL_MATH_EMULATION  -c -o error.o error.c
gcc -nostdinc -I../../include -Wall -O6 -fomit-frame-pointer  -DKERNEL_MATH_EMULATION  -c -o convert.o convert.c
gcc -nostdinc -I../../include -Wall -O6 -fomit-frame-pointer  -DKERNEL_MATH_EMULATION  -c -o ea.o ea.c
gcc -nostdinc -I../../include -Wall -O6 -fomit-frame-pointer  -DKERNEL_MATH_EMULATION  -c -o get_put.o get_put.c
gcc -nostdinc -I../../include -Wall -O6 -fomit-frame-pointer  -DKERNEL_MATH_EMULATION  -c -o add.o add.c
gcc -nostdinc -I../../include -Wall -O6 -fomit-frame-pointer  -DKERNEL_MATH_EMULATION  -c -o mul.o mul.c
gcc -nostdinc -I../../include -Wall -O6 -fomit-frame-pointer  -DKERNEL_MATH_EMULATION  -c -o div.o div.c
gcc -nostdinc -I../../include -Wall -O6 -fomit-frame-pointer  -DKERNEL_MATH_EMULATION  -c -o compare.o compare.c
ar rcs math.a emulate.o error.o convert.o ea.o get_put.o  add.o mul.o div.o compare.o
sync
(cd lib; make CFLAGS="-Wall -O6 -fomit-frame-pointer ")
gcc -nostdinc -I../include -Wall -O6 -fomit-frame-pointer   -c -o ctype.o ctype.c
gcc -nostdinc -I../include -Wall -O6 -fomit-frame-pointer   -c -o _exit.o _exit.c
_exit.c: In function `_exit':
_exit.c:14: warning: `volatile' function does return
gcc -nostdinc -I../include -Wall -O6 -fomit-frame-pointer   -c -o open.o open.c
gcc -nostdinc -I../include -Wall -O6 -fomit-frame-pointer   -c -o close.o close.c
gcc -nostdinc -I../include -Wall -O6 -fomit-frame-pointer   -c -o errno.o errno.c
gcc -nostdinc -I../include -Wall -O6 -fomit-frame-pointer   -c -o write.o write.c
gcc -nostdinc -I../include -Wall -O6 -fomit-frame-pointer   -c -o dup.o dup.c
gcc -nostdinc -I../include -Wall -O6 -fomit-frame-pointer   -c -o setsid.o setsid.c
gcc -nostdinc -I../include -Wall -O6 -fomit-frame-pointer   -c -o execve.o execve.c
gcc -nostdinc -I../include -Wall -O6 -fomit-frame-pointer   -c -o wait.o wait.c
gcc -nostdinc -I../include -Wall -O6 -fomit-frame-pointer   -c -o string.o string.c
gcc -nostdinc -I../include -Wall -O6 -fomit-frame-pointer   -c -o malloc.o malloc.c
ar rcs lib.a ctype.o _exit.o open.o close.o errno.o write.o dup.o setsid.o  execve.o wait.o string.o malloc.o
sync
ld -M boot/head.o init/main.o  kernel/kernel.o mm/mm.o fs/fs.o  fs/minix/minix.o  kernel/blk_drv/blk_drv.a kernel/chr_drv/chr_drv.a  kernel/math/math.a  lib/lib.a  -o tools/system > System.map
gcc  -Wall -O6 -fomit-frame-pointer   -o tools/build tools/build.c
cp tools/system system.tmp
strip system.tmp
tools/build boot/bootsect boot/setup system.tmp /dev/hda2 > Image
Root device is (3, 2)
Boot sector 512 bytes.
Setup is 1456 bytes.
System is 188420 bytes.
rm system.tmp
sync
------------------------------------------------------------

This takes about 7 minutes on my machine (heavily cached 386-33 with
8Mb Ram) and seems to use up to about 2.5Mb of memory. Don't worry about
the expr bit at the start. Expr is in the gnu shell utils 1.6 release
and is needed for compiling c++ code. You do not NEED it to rebuild
the 0.95c kernel (but it would make it slightly aesthetically more
pleasing I suppose :-)). Before anyone asks, no I don't know where you
can find the shell utils 1.6 (perhaps the gcc2.1 FAQ should indicate
this). There may be a copy somewhere in the Linux archives (don't
remember seeing one) but if not you should be able to get the original
from ftp.gnu.ai.mit.edu.

N.b. don't worry if it seems to hang while compiling floppy.c.... give
it a few seconds and it should burst back into life.... it's thinking :-)

If it gets all the way through there will be a file called Image
created in /usr/src/linux. This is the new bootimage and you can put
it onto a floppy in /dev/PS0 (a 3.5" 1.44Mb floppy on my machine) by
typing

dd bs=8192 if=Image of=/dev/PS0

You can do this automatically by typing make disk instead of make
(above) if you wish.

Congratulations! You have just rebuilt the linux kernel and created a
new boot floppy. Time to sync, reboot your machine and test it. I
hope you didn't overwrite your original bootimage; 'cos if you did then
what are going to use to boot up if the new bootimage is faulty?? Ah,
the value of forward planning :-)
-------------------------------------------------------------------

What now?

You probably want to compile ps (process status) now. There is a
version of this for 2.1 but it refused to compile for me and
complained about missing structure members. I don't intend to pursue
this 'cos my old version of ps (as compiled for 0.95a) works a treat
with the new kernel!
------------------------------------------------------------
Newsgroups: alt.os.linux