CSE 4105 System Programming · Lab 6

Object File Formats

elfread: your own small readelf.

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.

Lab 6 · Object File Formats

  1. TODO 1: the magic
    memcmp(buf, ELFMAG, SELFMAG). Test: ./elfread elfread.c must say "not an ELF file".
  2. TODO 2: sections
    Point an Elf64_Shdr array at e_shoff; names from .shstrtab. Compare with readelf -S main.o.
  3. TODO 3: symbols
    Use sh_link to find the names; ELF64_ST_TYPE and ELF64_ST_BIND. Compare with readelf -s.
  4. TODO 4: relocations
    Split r_info with ELF64_R_SYM and ELF64_R_TYPE. Check counta − 4 at offset 9.
  5. TODO 5: program headers
    Same pattern as TODO 2 with Elf64_Phdr. Try it on count and on tiny.
  6. Check everything
    ./elfread main.o | diff - expected_main.o.txt (and sections.o, tiny): no output means done.

Submit: elfread.c and its output for count. Extra: run it on a damaged file (bad) and on /bin/ls.

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 lab06_files.zip. Read here, then download the zip to work on them.

    ← Lab 5All lecturesLab 7 →