可执行文件适用于编译机器,而不适用于第二台机器

时间:2016-02-08 11:57:52

标签: c gcc compilation openwrt busybox

我有2个系统;一个OpenWrt和一个Busybox。

我试图在OpenWrt上编译一个简单的gcc可执行文件,将其复制并在Busybox机器上运行。

他们似乎有非常相似的CPU,所以我认为我的计划应该有效。

root@OpenWrt:/# cat /proc/cpuinfo 
system type             : Qualcomm Atheros QCA9558 ver 1 rev 0
machine                 : TP-LINK TL-WR1043ND v2
processor               : 0
cpu model               : MIPS 74Kc V5.0
BogoMIPS                : 358.80
wait instruction        : yes
microsecond timers      : yes
tlb_entries             : 32
extra interrupt vector  : yes
hardware watchpoint     : yes, count: 4, address/irw mask: [0x0ffc, 0x0ffc, 0x0ffb, 0x0ffb]
isa                     : mips1 mips2 mips32r1 mips32r2
ASEs implemented        : mips16 dsp dsp2
shadow register sets    : 1
kscratch registers      : 0
package                 : 0
core                    : 0
VCED exceptions         : not available
VCEI exceptions         : not available

BusyBox v1.15.3 () built-in shell (ash)
Enter 'help' for a list of built-in commands.
#cat /proc/cpuinfo 
system type             : Broadlight Lilac SOC
processor               : 0
cpu model               : MIPS 74Kc V4.12
BogoMIPS                : 248.21
wait instruction        : yes
microsecond timers      : yes
tlb_entries             : 64
extra interrupt vector  : yes
hardware watchpoint     : yes, count: 4, address/irw mask: [0x0000, 0x0000, 0x0000, 0x0000]
ASEs implemented        : mips16 dsp
shadow register sets    : 1
core                    : 0
VCED exceptions         : not available
VCEI exceptions         : not available

尝试在OpenWrt上编译和运行:

root@OpenWrt:/# cat /hello.c
#include <stdio.h>

int main() {
    printf("Kut met peren!\n");
    return 0;
}

root@OpenWrt:/mnt/sda3# gcc -o hello hello.c 
root@OpenWrt:/mnt/sda3# ./hello
Kut met peren!
root@OpenWrt:/mnt/sda3#

将hello复制到Busybox并执行:

#chmod +x hello
#ls -l hello
-rwxr-xr-x    1 root     root         5284 Feb  8 16:46 hello
#./hello
-sh: ./hello: not found
#

出了什么问题?

**更新:

文件系统似乎不是noexec,无论如何我可以在同一目录中运行可执行文件

#cat /proc/mounts
rootfs / rootfs rw 0 0
ubi0_0 / ubifs rw,relatime 0 0
proc /proc proc rw,relatime 0 0
sysfs /sys sysfs rw,relatime 0 0
devpts /dev/pts devpts rw,relatime,gid=5,mode=620 0 0
tmpfs /dev/shm tmpfs rw,relatime 0 0
/dev/ram1 /tmp tmpfs rw,relatime,size=65536k 0 0
/dev/ubi1_1 /configs ubifs rw,relatime 0 0
/dev/ubi5_0 /logs ubifs rw,relatime 0 0
OpenWrt框中的

filelddstrace而不是请求的第二个系统:

root@OpenWrt:/mnt/sda3# file ./hello
hello: ELF 32-bit MSB executable, MIPS, MIPS32 rel2 version 1, dynamically linked (uses shared libs), not stripped

root@OpenWrt:/mnt/sda3# ldd ./hello
        libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x77f12000)
        libc.so.0 => /lib/libc.so.0 (0x77ea5000)
        ld-uClibc.so.0 => /lib/ld-uClibc.so.0 (0x77f36000)


root@OpenWrt:/mnt/sda3# strace ./hello
execve("./hello", ["./hello"], [/* 13 vars */]) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|0x4000000, -1, 0) = 0x775c2000
stat("/etc/ld.so.cache", {st_mode=S_IFREG|0644, st_size=2683, ...}) = 0
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
mmap(NULL, 2683, PROT_READ, MAP_SHARED, 3, 0) = 0x775be000
close(3)                                = 0
open("/lib/libgcc_s.so.1", O_RDONLY)    = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=78648, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|0x4000000, -1, 0) = 0x775bf000
read(3, "\177ELF\1\2\1\0\0\0\0\0\0\0\0\0\0\3\0\10\0\0\0\1\0\0006\340\0\0\0004"..., 4096) = 4096
mmap(NULL, 147456, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x77586000
mmap(0x77586000, 78268, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED, 3, 0) = 0x77586000
mmap(0x775a9000, 824, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 3, 0x13000) = 0x775a9000
close(3)                                = 0
munmap(0x775bf000, 4096)                = 0
open("/lib/libc.so.0", O_RDONLY)        = 3
fstat(3, {st_mode=S_IFREG|0755, st_size=359596, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|0x4000000, -1, 0) = 0x775bf000
read(3, "\177ELF\1\2\1\0\0\0\0\0\0\0\0\0\0\3\0\10\0\0\0\1\0\0\235\0\0\0\0004"..., 4096) = 4096
mmap(NULL, 446464, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x77519000
mmap(0x77519000, 352496, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED, 3, 0) = 0x77519000
mmap(0x7757f000, 7340, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 3, 0x56000) = 0x7757f000
mmap(0x77581000, 17508, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x77581000
close(3)                                = 0
munmap(0x775bf000, 4096)                = 0
open("/lib/libc.so.0", O_RDONLY)        = 3
fstat(3, {st_mode=S_IFREG|0755, st_size=359596, ...}) = 0
close(3)                                = 0
stat("/lib/ld-uClibc.so.0", {st_mode=S_IFREG|0755, st_size=28972, ...}) = 0
munmap(0x775be000, 2683)                = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|0x4000000, -1, 0) = 0x775bf000
set_thread_area(0x775c6440)             = 0
mprotect(0x7757f000, 4096, PROT_READ)   = 0
mprotect(0x775c0000, 4096, PROT_READ)   = 0
ioctl(0, TIOCNXCL, {B38400 opost isig icanon echo ...}) = 0
ioctl(1, TIOCNXCL, {B38400 opost isig icanon echo ...}) = 0
write(1, "Kut met peren!\n", 15Kut met peren!
)

1 个答案:

答案 0 :(得分:0)

使用file(1)&amp; strace(1)&amp;在你的第二台机器上ldd(1)(如果你没有它们,安装它们,也许是通过在源代码中构建它们,并在笔记本电脑上使用交叉编译器)。

我猜有些共享库缺失,或者动态链接器不同,所以试试吧:

 file ./hello
 ldd ./hello
 strace ./hello

还在第二台计算机上运行cat /proc/cpuinfo

这可以帮助你理解错误。