Paul Kelly: Operating Systems Concepts - Linking and loading on linux


The first assessed exercise on Operating Systems Concepts (Exercise 3) is a practical introduction to linking and loading. The exercise uses the Linux operating system because linking and loading is considerably simpler with Linux than with Windows - but the principles are the same.

The following web resources may be of value to you in getting started:

If you're having trouble, try this (I said this in the lecture): don't worry about the questions at all. Instead, just run the commands described in the handout, and see if you can see what is happening.

The commands are:

First part - take an assembly-language program, assemble it, and relocate it and run it:

exercise linkload
as assembler.s -o assembler.o
od -xc -Ax assembler.o                             (skip this first time)
nm assembler.o                                          (skip this first
time)
objdump --all-headers assembler.o             (skip this first time)
objdump --disassemble assembler.o             (skip this first time)
ld -N assembler.o -o assembler
./assembler                                               (run it!)
Second part: take a C program, compile to assembler, assemble it and link it with an assembly language program:
nedit cversion.c &                    (just to see what is going on)
egcs -S cversion.c
nedit cversion.s &                   (just to see what is going on)
as cversion.s -o cversion.o
nm cversion.o
nedit writeexit.s &                   (just to see what is going on)
as writeexit.s -o writeexit.o
nm cversion.o
ld -N cversion.o writeexit.o -o cversion
./cversion                                               (run it!)