trofi / ski

ia64 (Itanium) instruction set simulator. Fork of http://ski.sourceforge.net
GNU General Public License v2.0
40 stars 7 forks source link

User mode is incomplete: lacks system calls to run bash #1

Open kasperk81 opened 3 years ago

kasperk81 commented 3 years ago

On (very old) Debian 7 wheezy x64 (the last version before ia64 support was dropped from Deb), I built ski and created chroot using archive:

$ debootstrap --arch=ia64 wheezy /ia64 http://archive.debian.org/debian/

1. User mode

after that running bash from ia64 rootfs with user mode gives me errors like:

$ bski -forceuser -simroot /ia64 -noconsole /ia64/bin/bash
doSyscall: unimplemented system call 1293
doSyscall: unimplemented system call 1293
doSyscall: unimplemented system call 1293

root@debian $ uname -a
                    Ignoring unimplemented clone() system call
bash: fork: Function not implemented

root@debian $ apt-get --help
                                Ignoring unimplemented clone() system call
bash: fork: Function not implemented

2. System mode

and with system mode, I get:

$ bski -forcesystem -simroot /ia64 -noconsole /ia64/bin/bash
/ia64/bin/bash - PT_INTERP segment not allowed
bski: Could not open /ia64/bin/bash for reading

is there a way to fix either of these? I want to test build some library code on ia64 without an Itanium system.

kasperk81 commented 3 years ago

Same issue on buster.

Setup is:

$ docker run --privileged -it debian:buster
$ apt update && apt install debootstrap
# ignore unsupported architecture check
$ sed -i 's/1)      error 1 ARCHNOTEXEC/#1)      error 1 ARCHNOTEXEC/' $(command -v debootstrap)
$ debootstrap --verbose --no-check-gpg  --arch ia64 wheezy /ia64 http://archive.debian.org/debian/

# install dependencies and build ski
$ apt install -y debootstrap build-essential git libtool-bin autoconf automake libglade2-dev bison libelf-dev ncurses-dev gperf flex
$ git clone https://github.com/trofi/ski; cd ski
$ ./autogen.sh;./configure;make -j > logs 2>&1   # log file has 62K+ lines full of unused variable warnings!!!
# if it fails (due to concurrency issue; eparse.h is required before it is generated ...)
# just rerun `make -j`
$ echo $?  # should be zero now

# usage, both give same errors as noted in previous comment
$ /ski/src/bski -forceuser   -simroot /ia64 -noconsole /ia64/bin/bash
$ /ski/src/bski -forcesystem -simroot /ia64 -noconsole /ia64/bin/bash
trofi commented 3 years ago
  1. User mode

We'll need to add more fresh syscalls to see how it goes. My expectation is that compatibility is weaker that of most qemu-user targets. But might work. I'll have a look.

  1. System mode

This one has higher chance to succeed. But also has quite a few caveats:

  1. system mode needs a block device to boot from
  2. system mode needs special hpsim build of kernel and boot loader to boot (was removed recently from linux kernel)
  3. system mode is expected to be 1000x slower than native. That might make any real-world building impractical.

A few years ago I booted 4.11 successfully: https://trofi.github.io/posts/199-ia64-machine-emulation.html

A few other options are: a. build ia64-unknown-linux-gnu cross-compiler. In gentoo it's as easy as running crossdev -t ia64-unknown-linux-gnu. b. ask for access to ia64 debian system on irc://oftc/#debian-ports

kasperk81 commented 3 years ago

Thanks, latest kernel support for user+system modes would be great! After all ski is exclusively supporting ia64 emulation (other than a WIP for qemu ia64 in a fork). :)

I tried the cross compiler option on gentoo meanwhile, and got errors. Here is what I did:

$ docker run -it --privileged gentoo/stage3

$ emerge-webrsync
$ emerge sys-devel/crossdev app-eselect/eselect-repository
$ mkdir -p /etc/portage/repos.conf/
$ eselect repository create localrepo
$ crossdev -t ia64-unknown-linux-gnu
...
 * Emerging cross-gcc-stage1 ...

 * error: gcc failed :(
 *
 * If you file a bug, please attach the following logfiles:
 * /var/log/portage/cross-ia64-unknown-linux-gnu-info.log
 * /var/log/portage/cross-ia64-unknown-linux-gnu-gcc-stage1.log.xz
 * /var/tmp/portage/cross-ia64-unknown-linux-gnu/gcc*/temp/gcc-config.logs.tar.xz

# strip ANSI colors from logs and upload
$ cat /var/log/portage/cross-ia64-unknown-linux-gnu-gcc-stage1.log \
    | sed 's/\x1B[@A-Z\\\]^_]\|\x1B\[[0-9:;<=>?]*[-!"#$%&'"'"'()*+,.\/]*[][\\@A-Z^_`a-z{|}~]//g' \
    | curl -F"sprunge=<-" http://sprunge.us

logs: http://sprunge.us/gXNYGu

trofi commented 3 years ago

/var/tmp/portage/cross-ia64-unknown-linux-gnu/gcc-11.1.0-r1/work/gcc-11.1.0/libgcc/config/ia64/fde-glibc.c:33:10: fatal error: stdlib.h: No such file or directory 33 | #include | ^~~~~~

Oh, that was recently fixed in https://gitweb.gentoo.org/proj/crossdev.git/commit/?id=bcedb8deeb2e08b91db7b6f5c31623d2a777cb8b

As a workaround you can enable it explicitly: crossdev -t ia64-unknown-linux-gnu --with-headers

kasperk81 commented 3 years ago

Thanks @trofi! crossdev solution worked. :)

trofi commented 2 years ago

https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=cef03728234644b1a9ad5bd8e94daeac8650a71b should fix --without-headers build upstream as well.

trofi commented 2 years ago

Added basic HOWTO on how to get both user and system modes to run: https://github.com/trofi/ski/commit/420652374dd2cc7aa563e4af91fbeb4815d6cdc5.

Released 1.4.0 with minor tweak to make ski built on modern environments: https://github.com/trofi/ski/releases/tag/v1.4.0

Let's rename this report into incomplete support of user mode.

trofi commented 2 years ago

Current bash status:

$ LANG=C bskinc ./bash-ia64/bin/bash
doSyscall: unimplemented system call 1298
doSyscall: unimplemented system call 1325
doSyscall: unimplemented system call 1254
Ignoring unimplemented sysinfo() system call
doSyscall: unimplemented system call 1254
doSyscall: unimplemented system call 1254
doSyscall: unimplemented system call 1325
doSyscall: unimplemented system call 1325
doSyscall: unimplemented system call 1317
bash: cannot make pipe for command substitution: Function not implemented
doSyscall: unimplemented system call 1317
bash: cannot make pipe for command substitution: Function not implemented
doSyscall: unimplemented system call 1254
doSyscall: unimplemented system call 1254
sskras commented 1 year ago

That's interesting. I wonder if running a simpler thing, some Borne-like shell (like Dash or PDksh) would be more successful.

trofi commented 1 year ago

My guess would be that most of these syscalls come from modern glibc and are not very specific to the shell code.