How to compile and run an executable in gem5 syscall emulation mode with se.py?

旧街凉风 提交于 2019-12-17 16:39:43

问题


There are many possible errors and workarounds scattered in may different places, can anyone provide at least one detailed working setup, with exact gem5 and compiler versions, hopefully on Ubuntu?


回答1:


Minimal working Ubuntu setup

As of gem5 8162e0da0285d346046151b2a45ceeb1baf63b8f Oct 2018, a C hello world for all of x86, arm and aarch64 just works on both Ubuntu 16.04 and 18.04. x86 was working previously, but that commit finalized some required arm changes to make the glibc int code run before main work properly.

Given that gem5 version and one of those Ubuntu versions, you can run the following C program:

main.c

#include <stdio.h>

int main(int argc, char **argv) {
    size_t i;
    for (i = 0; i < (size_t)argc; ++i)
        printf("%s\n", argv[i]);
    return 0;
}

simply as:

sudo apt-get install gcc
gcc -O0 -ggdb3 -std=c99 -static -o x86.out main.c
build/X86/gem5.opt \
  configs/example/se.py \
  -c x86.out \
  -o 'asdf qwer' \
;

sudo apt-get install gcc-arm-linux-gnueabihf
arm-linux-gnueabihf-gcc -O0 -ggdb3 -std=c99 -static -o arm.out main.c
build/ARM/gem5.opt \
  configs/example/se.py \
  -c arm.out \
  -o 'asdf qwer' \
;

sudo apt-get install gcc-aarch64-linux-gnu
aarch64-linux-gnu-gcc -O0 -ggdb3 -std=c99 -static -o aarch64.out main.c
build/ARM/gem5.opt \
    configs/example/se.py \
    -c aarch64.out \
    -o 'asdf qwer' \
;

and in all cases produces the correct output:

asdf
qwer

-static is required on ARM as mentioned at: How to run a dynamically linked executable syscall emulation mode se.py in gem5?

If anyone finds a setup at a newer gem5 revision or Ubuntu version for which such minimal C program does not execute correctly in one of the previously mentioned arches, please send an email describing your system setup in detail to the mailing list and CC me.

Missing syscalls

Then of course, as you try to run more complex userland programs, you will inevitably meet unimplemented syscalls, as there are many of those.

Please don't report those as bugs unless they appear on the glibc setup code for a minimal C example, since we already have a list of the missing syscalls on the source code itself.

Rather, don't be put off, and try a patch!

Many of the syscalls are trivial to implement, see for example 8162e0da0285d346046151b2a45ceeb1baf63b8f.

Only then, if you have tried a patch, but failed, start pinging people on the mailing list and asking for guidance on how to make your patch work.

Multi-threading

TODO this is a known major pain point. I don't know what the status is, but I've heard it is flaky.

Recent fixes that made ARM work

As things inevitably break again, you might be able to take some inspiration from the following fixes that we have done, and possibly patch the problem yourself:

  • FATAL: kernel too old: How to solve "FATAL: kernel too old" when running gem5 in syscall emulation SE mode? Fixed by: 260b0fc5381a47c681e7ead8e4f13aad45069665
  • openat unimplemented. The glibc ARM startup code on Ubuntu 18.04 started using it, which broke the hello world. Fixed by: 8162e0da0285d346046151b2a45ceeb1baf63b8f
  • panic: Attempted to execute unimplemented instruction 'mrs'. Fixed by: 6efe7e1abf9d289859eb23b52b3a319f15f2736a. By decoding it manually, instruction executed was mrs x0, midr_el1.

crosstool-NG

Using crosstool-NG to enable ulibc instead of glibc can sometimes serve as a workaround for glibc init code, since ulibc is more minimal an exercises less code than glibc. It is not ideal, but might work if you really can't manage to patch gem5. Described at: How to solve "FATAL: kernel too old" when running gem5 in syscall emulation SE mode?



来源:https://stackoverflow.com/questions/53085048/how-to-compile-and-run-an-executable-in-gem5-syscall-emulation-mode-with-se-py

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!