CS611
Programming Assignment 5
Spring 1999


Write a linker for object modules produced by the as611 assembler. The linker should take two object modules, bind them together, resolve external references, and output the result as one object module.

The two input filenames will be given on the command line. The output filename should be a.out.

If the output object module does not have an empty outsymbol table, print to the stdout the names of all undefined symbols. Also, if there is a duplicate symbol, write an error message.

Here are the steps the linker should perform:

  1. Read in all sections of both input files and store in memory for later processing. As you read in the two sets of object code, place them physically together in memory (the file whose name appeared first on the command line should appear first in memory, and eventually in the output).

  2. Add the length of the first module's object code to all the addresses in the second module's object code (the `first' module appeared first on the command line). Remember: the relocation bits tell you where a address is in the object code.

  3. Concatenate the two sets of relocation bits together in the same order that you put the object code together. Be careful! You can't just concatenate bytes, you must concatenate bits! Knowing the lengths of the two modules' object code will be necessary. (And, no, you may not pad the object code from the first file!)

  4. Combine the two insymbol tables by installing all insymbols into a symbol table. If a symbol appears in both insymbol tables, it is a duplicately defined symbol and an error message should be printed. As you process the second insymbol table, add the length of the first module's object code to the offset fields.

  5. Process the two outsymbol tables. As you process the second outsymbol table, add the length of the first module's object code to the offset fields. Look up each symbol which is in an outsymbol table in the new, combined, insymbol table you've built in memory (step 4). If it is found, pick up its address and fill in all the address fields on the chain emanating from the offset field of the outsymbol table. If the symbol was not found in the new, combined, insymbol table, the symbol remains an outsymbol. Place it in a new outsymbol table and print an error message.

  6. Write out a new object module. You've got everything you need to do this in memory.

This is not the only way to do the assignment, but it gives you an idea of what has to be done. However, the file that appears first in the command line must be placed first in the output object module.

Actually there is a subtle bug in the above description concerning the end-of-list marker in the outsymbol linked lists. Think about it!

Use the symbol table routines from as611 for the linker's symbol table.

Look in ~cs611/public/progs/prog5 for direction on how the source code will be organized. Your task is to complete the `link' function in the file link.c.

Six public test cases (pairs of assembly language source files) are available in ~cs611/public/progs/prog5/tests. Each case tests a different aspect of the assignment. Read the file TESTS for information about the test cases. Most of these cases are simply meant to be used to test the linker and the output is not intended to be executed by sim611. One hidden test case will be used to test error handling and other items not covered in the public files. All test files will have equal weight for grading purposes.

Your implementation must be performed using C.

Your program will be graded primarily by testing it for correct functionality. However, you may lose points if your program is not properly structured or adequately documented.

Your code should be submitted for grading from alberti (or hopper or christa). To turn in this assignment, type:
~cs611/bin/submit prog5 link.c

Do not turn in any non-Ascii files (i.e. no object files, no executable files, etc.).

Submissions can be checked by typing:
~cs611/bin/scheck prog5

To receive full credit for the assignment, you must turn in your files prior to 8am on Monday April 12. Late submissions will be accepted at the penalty of 5% per day up to one week late.

Remember: as always you are expected to do your own work on this assignment.


Last modified on March 28, 1999.

Comments and questions should be directed to pjh@cs.unh.edu