[GSoC22 Weekly Status report #8&9] Ran the Linux binary that just returns in the main func: Koichi Imai

From: 今井航一 <kotty.0704_at_gmail.com>
Date: Mon, 15 Aug 2022 17:11:13 UTC
Hello,

These two weeks I have made an effort to run the Linux binary that just
returns in the main function successfully.

There were mainly three bugs to fix.
1. The first one seems to be due to a bug in the kernel linker. Linuxulator
is implemented as a kernel module for each architecture, and therefore I
was just specifying the module in sys/modules/Makefile to let it know the
existence of the module. However, it appears there is a bug resolving IFUNC
references from modules. Thus, I added the files for Linuxulator at
/sys/conf/files.powerpc to build it together with the kernel and that fixed
the bug.

2. The second bug was because of the mismatch of the ELF ABI version. Since
I was assuming the ELF ABI version 2, I was reusing the code of FreeBSD
exec_setregs() for ABI version 2. However, the Linux binary created in my
environment was that of the ELF ABI version 1, and therefore, there were
some differences mainly with the handling of the entry points. I reused the
exec_setregs_funcdesc() of FreeBSD to fix this.

3. I was mainly reusing the codes from FreeBSD for the process
initialization. However, it doesn't initialize the r6 register which should
hold the address of the auxiliary vector. (Actually, initializing with
zero.) This didn't make the Linux binary run correctly so I rewrite the
code to initialize properly.

Due to this debugging, I was able to run the Linux binary that just returns
in the main function successfully. I would like to check the functionality
of syscalls that are realized with machine-independent codes and add DWARF
annotations at the signal trampoline as a next step.

Koichi