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

我需要在chroot中运行Rust可执行文件(使用cargo build –release).通常,我只是复制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)

但是我的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)

当用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)

我相信崩溃的发生是因为chroot里面没有/ proc和/ sys.

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

最佳答案 我相信这是一个
known issue.据Alex Crichton说:

it looks like 07001 is our detection of the stack start of the main thread in setting up the first guard page. I forget how reliable it is that linux sets up a guard page for us, and it would be tough to remove for now at least.

点赞