rcore-os / zCore

Zircon microkernel reimplemented in Rust.
MIT License
1.71k stars 208 forks source link

Unable to run qemu in macOS #367

Closed MrZLeo closed 2 years ago

MrZLeo commented 2 years ago

I use command cargo qemu --arch aarch64 --smp 4 to build the kernel and run it in the qemu, but it failed with error:

/bin/sh: /Users/mrzleo/zCore/ignored/target/aarch64/aarch64-linux-musl-cross/bin/aarch64-linux-musl-gcc: cannot execute binary file
make[1]: *** [applets/applets.o] Error 126
make: *** [applets_dir] Error 2
thread 'main' panicked at 'Failed with code 2: "cd /Users/mrzleo/zCore/ignored/target/aarch64/busybox && make CROSS_COMPILE=/Users/mrzleo/zCore/ignored/target/aarch64/aarch64-linux-musl-cross/bin/aarch64-linux-musl-"', /Users/mrzleo/.cargo/git/checkouts/command-ext-58b697115b23f0c6/f25befb/src/lib.rs:99:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

I don't understand why we need aarch64-linux-musl-gcc here. Do we run it in qemu user mode? I can not find detail document about this command. If I want to build the kernel and run it in qemu system mode, what should I do?

My environment is as followed:

$ uname -a
Darwin MrZLeos-MacBook-Pro.local 21.6.0 Darwin Kernel Version 21.6.0: Wed Aug 10 14:28:35 PDT 2022; root:xnu-8020.141.5~2/RELEASE_ARM64_T8101 arm64

$ qemu-system-aarch64 --version
QEMU emulator version 7.1.0
Copyright (c) 2003-2022 Fabrice Bellard and the QEMU Project developers

$ rustup default nightly
info: using existing install for 'nightly-aarch64-apple-darwin'
info: default toolchain set to 'nightly-aarch64-apple-darwin'

  nightly-aarch64-apple-darwin unchanged - rustc 1.65.0-nightly (84f0c3f79 2022-09-03)

info: note that the toolchain 'nightly-2022-08-05-aarch64-apple-darwin' is currently in use (overridden by '/Users/mrzleo/zCore/rust-toolchain.toml')

$ rustup --version
rustup 1.25.1 (bb60b1e89 2022-07-12)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.64.0-nightly (f6f9d5e73 2022-08-04)`

$ rustc --version
rustc 1.64.0-nightly (f6f9d5e73 2022-08-04)
YdrMaster commented 2 years ago

cargo qemu 就是用 qemu-system 的,musl-gcc 是为了编译 busybox,它必须得有 busybox。还有一些其他非必要的测例也需要 musl-gcc 编译。我们没有 mac,没试过。好像之前用 mac 的人都是直接开 linux 虚拟机的,应该虚拟机里能搞运行。

YdrMaster commented 2 years ago

aarch64 的支持整个都是国防科大的同学提供的,我们理解不深。实际上测例也经常不过。如果你试出来什么可以告诉我们一声,微信上 rcore-os 群里找我们也行。

MrZLeo commented 2 years ago

@YdrMaster 我使用其他架构的时候也是一样,应该是musl-gcc缺失。我不是很了解musl-gcc工具链,但是这里用的是linux-musl-gcc,似乎只能在Linux中运行,是否有对应的mac编译器呢?

MrZLeo commented 2 years ago

@YdrMaster 我找到的是这样的工具链,不知道是否能满足在macOS下编译的需求?

YdrMaster commented 2 years ago

@MrZLeo 也许可以,但我没法试……这一块的逻辑是它会层层递归地构造 rootfs,如果你能提供一个 rootfs 他就不会试图编译了。在根目录下新建 rootfs/$arch 目录就行,至少需要 busybox 和 musl-libc 的 ld:

> ~/repos/zCore$ tree rootfs
rootfs
└── riscv64
    ├── bin
    │   ├── busybox
    │   ├── cat -> busybox
    │   ├── cp -> busybox
    │   ├── echo -> busybox
    │   ├── false -> busybox
    │   ├── grep -> busybox
    │   ├── gzip -> busybox
    │   ├── kill -> busybox
    │   ├── ln -> busybox
    │   ├── ls -> busybox
    │   ├── mkdir -> busybox
    │   ├── mv -> busybox
    │   ├── pidof -> busybox
    │   ├── ping -> busybox
    │   ├── ping6 -> busybox
    │   ├── printenv -> busybox
    │   ├── ps -> busybox
    │   ├── pwd -> busybox
    │   ├── rm -> busybox
    │   ├── rmdir -> busybox
    │   ├── sh -> busybox
    │   ├── sleep -> busybox
    │   ├── stat -> busybox
    │   ├── tar -> busybox
    │   ├── touch -> busybox
    │   ├── true -> busybox
    │   ├── uname -> busybox
    │   ├── usleep -> busybox
    │   └── watch -> busybox
    └── lib
        └── ld-musl-riscv64.so.1

3 directories, 30 files
YdrMaster commented 2 years ago

@YdrMaster 我使用其他架构的时候也是一样,应该是musl-gcc缺失。我不是很了解musl-gcc工具链,但是这里用的是linux-musl-gcc,似乎只能在Linux中运行,是否有对应的mac编译器呢?

它说的是 cannot execute binary file,因为苹果 m1/2 处理器是 arm64,预编译的 gcc 是给 x86 编译的所以没法运行。

MrZLeo commented 2 years ago

@YdrMaster 我使用其他架构的时候也是一样,应该是musl-gcc缺失。我不是很了解musl-gcc工具链,但是这里用的是linux-musl-gcc,似乎只能在Linux中运行,是否有对应的mac编译器呢?

它说的是 cannot execute binary file,因为苹果 m1/2 处理器是 arm64,预编译的 gcc 是给 x86 编译的所以没法运行。

但是这里换成aarch64也是不行的,因为这里是linux-musl-gcc,不能在Linux之外的OS上运行。我先尝试一下直接下载预编译的rootfs,后续如果成功用上面说的工具链编译的话,再通过这个issue说一声。

非常感谢!!!

YdrMaster commented 2 years ago

@YdrMaster 我使用其他架构的时候也是一样,应该是musl-gcc缺失。我不是很了解musl-gcc工具链,但是这里用的是linux-musl-gcc,似乎只能在Linux中运行,是否有对应的mac编译器呢?

它说的是 cannot execute binary file,因为苹果 m1/2 处理器是 arm64,预编译的 gcc 是给 x86 编译的所以没法运行。

但是这里换成aarch64也是不行的,因为这里是linux-musl-gcc,不能在Linux之外的OS上运行。我先尝试一下直接下载预编译的rootfs,后续如果成功用上面说的工具链编译的话,再通过这个issue说一声。

非常感谢!!!

我理解这个 aarch64 是从 x86 交叉编译到 aarch64,不是自己能在 aarch64 运行。应该大部分 linux 程序都可以直接在 mac 上运行吧,因为都是类 unix……

anyway,祝你成功

YdrMaster commented 2 years ago

可以找个 x86 的电脑或者云服务器什么的编出来拷到你电脑上用