为什么 Rust hello world 尝试读取 /proc 和 /sys

Pet*_*mit 5 compilation rust

我需要cargo build --release在 chroot 中运行 Rust 可执行文件(用 )。通常,我只是复制 ldd 报告的文件

$ldd hello_world_rust
linux-vdso.so.1 (0x00007ffef48c6000)
libdl.so.2 => /usr/lib/libdl.so.2 (0x00007f3224c3e000)
libpthread.so.0 => /usr/lib/libpthread.so.0 (0x00007f3224a21000)
librt.so.1 => /usr/lib/librt.so.1 (0x00007f3224819000)
libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x00007f3224603000)
libc.so.6 => /usr/lib/libc.so.6 (0x00007f3224261000)
/lib64/ld-linux-x86-64.so.2 (0x00007f3224e42000)
libm.so.6 => /usr/lib/libm.so.6 (0x00007f3223f5d000)
Run Code Online (Sandbox Code Playgroud)

但是我的 Rust 程序在监狱内运行时崩溃了

thread '<unnamed>' panicked at 'assertion failed: `(left == right)` (left: `2`, right: `0`)', /build/rust/src/rustc-1.1.0/src/libstd/sys/unix/thread.rs:204
fatal runtime error: Could not unwind stack, error = 5
Illegal instruction (core dumped)
Run Code Online (Sandbox Code Playgroud)

当使用 strace (在监狱内)检查内容时,我注意到以下内容

strace -e file hello_world_rust
.... 14 lines of loading dynlibs cut
readlink("/etc/je_malloc.conf", 0x7fff7c2ed380, 4096) = -1 ENOENT (No such file or directory)
open("/sys/devices/system/cpu/online", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/proc/stat", O_RDONLY|O_CLOEXEC)  = -1 ENOENT (No such file or directory)
open("/proc/cpuinfo", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/proc/self/maps", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
Run Code Online (Sandbox Code Playgroud)

我相信发生崩溃是因为 chroot 内没有 /proc 和 /sys。

我的信念正确吗?如果是这样,为什么它们是必要的?有没有办法可以编译我的 rust 程序,使其不需要 /sys 和 /proc?

She*_*ter 3

我相信这是一个已知问题。根据亚历克斯·克莱顿的说法:

看起来有问题的失败是我们在设置第一个保护页时检测到主线程的堆栈开始。我忘记了linux为我们设置的保护页面有多可靠,至少现在很难删除。