我在i386-pc-linux-gnu as --build and --host for --target=x86_64-pc-linux-gnu with binutils-2.27 and gcc-6.3.0.
工具链似乎工作正常,为x86_64生成二进制文件。
但是尝试使用init=/tools/bin/bash
启动到新编译的bash会给bash带来段错误,从而导致内核崩溃。
我编译了一个静态busybox,gdb和strace。静态二进制文件工作,我能够启动到busybox。尝试动态链接的bash,它是段错误。
以下是strace和gdb的调试输出:
(gdb) r --help
Starting program: /tools/bin/bash --help
Program received signal SIGSEGV, Segmentation fault. 0xffffffffffffffff in ?? ()
(gdb) bt
#0 0xffffffffffffffff in ?? ()
#1 0x00007ffff7de91da in call_init (l=<optimized out>, argc=argc@entry=2, argv=argv@entry=0x7fffffffedf8, env=env@entry=0x7fffffffee10) at dl-init.c:72
#2 0x00007ffff7de92eb in call_init (env=0x7fffffffee10, argv=0x7fffffffedf8, argc=2, l=<optimized out>) at dl-init.c:30
#3 _dl_init (main_map=0x7ffff7ffe110, argc=2, argv=0x7fffffffedf8, env=0x7fffffffee10) at dl-init.c:120
#4 0x00007ffff7ddac4a in _dl_start_user () from /tools/x86_64-lfs-linux-gnu/lib64/ld-linux-x86-64.so.2
#5 0x0000000000000002 in ?? ()
#6 0x00007fffffffef9d in ?? ()
#7 0x00007fffffffefad in ?? ()
#8 0x0000000000000000 in ?? ()
(gdb)
execve("/tools/bin/bash", ["/tools/bin/bash"], [/* 4 vars */]) = 0
brk(0) = 0x15b5000
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f6a816a1000
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
open("/tools/x86_64-lfs-linux-gnu/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/tools/x86_64-lfs-linux-gnu/lib/tls/x86_64/libdl.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/tools/x86_64-lfs-linux-gnu/lib/tls/x86_64", 0x7ffe1a856a90) = -1 ENOENT (No such file or directory)
open("/tools/x86_64-lfs-linux-gnu/lib/tls/libdl.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/tools/x86_64-lfs-linux-gnu/lib/tls", 0x7ffe1a856a90) = -1 ENOENT (No such file or directory)
open("/tools/x86_64-lfs-linux-gnu/lib/x86_64/libdl.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/tools/x86_64-lfs-linux-gnu/lib/x86_64", 0x7ffe1a856a90) = -1 ENOENT (No such file or directory)
open("/tools/x86_64-lfs-linux-gnu/lib/libdl.so.2", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0P\16\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=207816, ...}) = 0
mmap(NULL, 2109712, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f6a8127d000
mprotect(0x7f6a81280000, 2093056, PROT_NONE) = 0
mmap(0x7f6a8147f000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x2000) = 0x7f6a8147f000
close(3) = 0
open("/tools/x86_64-lfs-linux-gnu/lib/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\320\5\2\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=15199320, ...}) = 0
mmap(NULL, 3901760, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f6a80ec4000
mprotect(0x7f6a81073000, 2097152, PROT_NONE) = 0
mmap(0x7f6a81273000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1af000) = 0x7f6a81273000
mmap(0x7f6a81279000, 14656, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f6a81279000
close(3) = 0
mmap(NULL, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f6a8169e000
arch_prctl(ARCH_SET_FS, 0x7f6a8169e700) = 0
mprotect(0x7f6a81273000, 16384, PROT_READ) = 0
mprotect(0x7f6a8147f000, 4096, PROT_READ) = 0
mprotect(0x6df000, 4096, PROT_READ) = 0
mprotect(0x7f6a816a3000, 4096, PROT_READ) = 0
--- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_MAPERR, si_addr=0xffffffffffffffff} ---
在调用main()之前发生了段错误。交叉工具链的动态加载器一定存在问题。我有点陷入困境,如果有人暗示如何进一步调查,我会很感激。
谢谢!