This is a one of the tasks of the Advanced Operating Systems course (Zawansowane Systemy Operacyjne) on MIMUW (University of Warsaw). The description of full task can be found here: http://students.mimuw.edu.pl/ZSO/PUBLIC-SO/2018-2019/z1_elf/index.html
crossld_start is a function that while executing x86_64 code, start Elf32 executable [fname] with provided functions. For each function it creates a trampoline that:
- from 32 bit mode switches to 64 bit mode
- moves arguments to right registers for the x64 calling convention
- executes given function
- checks if returned value fits into return type, if not finished execution with code -1
- switches to 32 bit mode
- returns to 32 bit exec
It then set all the relocations of the given executable. For now, only REL is supported.
In the end, it returns the code for the execution.
In elf_utils.h you can find usefull C++ functions for reading ELF32 file.