Fwd: [GSoC22 Weekly Status report #10&11] Fixed bug for supporting dynamically linked Linux binary: Koichi Imai

From: 今井航一 <kotty.0704_at_gmail.com>
Date: Mon, 19 Sep 2022 10:49:27 UTC
Hello,

It appears that I was not able to send the previous email, so I will send
the previous one. Shortly after this, I will also send you an email with
the progress for the past few weeks.

After I successfully ran the statically linked Linux binary that just
returns in the main function last week, I verified that basic system calls
such as write and read, and file system operations such as fwrite and fread
work if they are statically linked.

I've also tried to check if the dynamically linked binary works by
$ chroot /compat/lg64 /bin/bash
(I made the /compat/lg64 directory and opened the gentoo linux stage3
tarball here.)
However, it failed because of a segmentation fault in the startup code. I
tried to find out why but since there was no symbol found in libc.so.6 and
ld64.so I had to get the one with debug symbols.
Using gdb, I could finally figure out the cause and it was because the
stack with argc, argv, and envp pushed was not being passed correctly. The
static link seemed to pass them as registers, so I did not find the
problem, but it seemed to have failed because the dynamic link passed them
as stacks.

I also added some code to support linux_mmap(not linux_mmap2) since it was
failing at mmap syscall. However, it still fails with the error message as
follows
"linux: jid 0 pid 907 (bash): linux_ioctl_fallback fd=0, cmd=0x402c7413
('t',19) is not implemented"
To solve this I've looked around the source code of Linux and found that
linux's ioctl-related macros are different on powerpc, and I think I can
solve it by overriding them in /powerpc/linux/linux.h.

Koichi