CSE 4105 System Programming · Lab 5

Loaders · Loader Design Options

A SIC loader in C: absolute, relocating and linking.

Tasks

The same steps as the lab slide. Do them on a Linux PC with the files from the zip; the tools below help you check your thinking first.

  1. Build the starter
    gcc -Wall -o sicload sicload_starter.c then ./sicload count.obj. Memory is all xx: nothing is loaded yet.
  2. TODO 1: load_T
    Copy the bytes of a T record into memory. ./sicload count.obj | diff - expected_abs.txt must print nothing.
  3. TODO 2: patch
    Add delta to a field of 4, 5 or 6 half-bytes, keeping the other bits. Test by hand: 100000 + 4011 → 104011.
  4. TODO 3: M records
    One line in load_one. Then ./sicload -v -x -r 5000 count0.obj: TOTAL must become 000003.
  5. Try other addresses
    Load count0.obj at 0, 1234 and 7000 with -x. Same result every time? Then your relocation is right.
  6. C side
    In the demo folder: nm, readelf -r and objdump -d on main.o, then link with -Wl,-Map and find the call to counta.

Extra: TODO 6 loads bit-mask records (-b 5000 count0_mask.obj). Submit: sicload.c and the output of task 4.

Lab 5.2 · Loader Design Options

  1. TODO 4: Pass 1
    Fill ESTAB from H and D records. ./sicload -l 4000 main.obj counta.obj data.obj must print the load map of Lecture 5.1.
  2. TODO 5: Pass 2
    Apply M records with ±symbol from ESTAB. diff your output with expected_link4000.txt: nothing.
  3. Errors
    Leave out data.obj, then give data.obj twice. You must get "undefined external symbol TOTAL" and "duplicate external symbol DATA".
  4. Libraries
    In demo/: build libcount.a and libcount.so; reproduce the -l order error and the 'cannot open shared object file' error, and fix both.
  5. Watch ld.so
    Run with LD_DEBUG=libs and LD_DEBUG=bindings, and with strace. Find where libcount.so is opened and mapped.
  6. The GOT
    gdb -batch -x got.gdb ./lazy: write down GOT[counta] before and after the first call; check base + 10f9.

Submit: sicload.c, your load map, and a short report with the GOT values from task 6.

Try it here

These run in your browser, with no server and no internet. They are built from the same reference programs as the lab, so their output matches what your finished C program should print. They do not replace the real lab: the kernel, gcc and your own code are the point.

Read the files

Every text file from lab05_files.zip. Read here, then download the zip to work on them.

    ← Lab 4All lecturesLab 6 →