Materials for HTS (Harmonisation Technologique Système)
Author: Gabriel Laskar
Contributor: Alizée Penel
Repository
You must push your code to:
<login>@git.cri.epita.fr:p/2022-sys/hts-<login>.git
You must change <login> with yours. You have to upload your ssh-key to
accounts.cri.epita.net.
Deadline
You work is due on the 31th of July 2021, 11:42 PM.
Rules
- An exercise which does not compile will not be marked.
- Your Git history will be reviewed and will be taken into account in the mark.
- Cheating implies a zero to the course.
- Your work will be tested on Archlinux.
Exercises
You have to complete the three following exercises.
hello world
The objective is to print the famous Hello World! string on the standard
output, where the only allowed function is printf from the libc but you are
forbidden to call printf directly: you have to find it manually.
Implementation restrictions
- you can not use assembly code
- you code should be able to work on multiple architectures and versions of the
libc - you can not use any function provided by the
libcexcept the ones you will gather manually.
Build restrictions
- your work must be located in a folder called
hello - binary will be named
hello - you must use
autotools,mesonormaketo generate your code
Git restrictions
- commits messages should be prefixed with
hello:␣
Steps
- find the link map of your process (auxv, phdr, dynamic,
r_debug,link_map) - get the dynamic segment
- get the symtab, strtab and hash
- find the address of printf inside them
- call it
Note
The description of the elf format (with the description of the hash table) can
be find here.
readelf
You have to write a small readelf clone that outputs json. You can find a
sample output here.
Implementation restrictions
- you should handle elf binaries in the same ‘size’ as your machine (look into
link.hfor the macroElfW)
Test restrictions
- use check and/or
make checkto test your code (do not forget to check that it is installed)
Build restrictions
- you must use
autotoolsormesonto generate your code - the directory for your sources is
readelf - binary should be named
simple-readelf
Hint
I recommend you to clone strace source code and take a look to the
use of xlat. You will find an example of xlat use on LSE Github.
Git restrictions
- commits should be prefixed with
readelf:␣
Bonus
- Support 32-bit and 64-bit architecture
- Support little and big endianess
small linker
You must implement our own linker.
You will find the provided files on LSE Github.
Implementation restrictions
-
Command line usage:
$ my_ld -o output_file input_file.o -
There is only 3 relocation types to handle:
R_X86_64_32(only for the debug versions)R_X86_64_64R_X86_64_PC32
-
entry_pointaddress must be the address of_start
Build restrictions
- You need to be able to build all the binaires in the
testsdirectory$ make my_ld $ make -C tests MY_LD=../my_ld - you must use
autotools,gcovandcheckto test your code (do not forget to check that it is installed) - you should have a complete coverage of your code
- in your directory, expected results should be outputted on:
$ ./autogen.sh && ./configure --enable-code-coverage && make distcheck
Note
AX_CODE_COVERAGE macro is your friend (either copy the macro inside your
repository, or install autoconf-archive)
Test descriptions
There are 3 samples:
simple: a really simple hello world with no relocationhello: a relocation in the .rodatavars: multiple relocations
And 2 variants, one with debug symbols, and one without.
Because of the time constrain, the debug versions are not mandatory.
Hints
-
instead of trying to handle all cases, assert that your are in a known code path. (for example, do not try to handle all the relocations, but write an error message for unhandled ones)
-
we only need at most 3 PHDR:
- one with RX permissions (for the section marked with
AXflags) - one with R permissions (for the section marked with
Aflags) - one with RW permissions (for the section marked with
AWflags) - drop every other sections.
- one with RX permissions (for the section marked with
- sections are useful only to be launched inside a debugger
- for debugging, strace and dmesg will help
Note
- have a look to the
elf.hheader (/usr/include/elf.h) - for the relocations, you can look into x86_64 ABI section 4.4