-1

I have 2 systems; a OpenWrt and a Busybox.

I'm trying to compile a simple gcc executable on the OpenWrt, to copy it and run it on the Busybox machine.

They seem to have very similar CPU so I assume my plan should work.

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

Trying to compile and run on 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#

Copying hello to the Busybox and executing:

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

What went wrong?

**UPDATES:

Filesystem doesn't seem to be noexec, anyway I can run executables in the same directory

#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

file, ldd and strace on the OpenWrt box rather than the requested 2nd system:

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!
)
EDP
  • 309
  • 1
  • 6
  • 18

1 Answers1

0

Use file(1) & strace(1) & ldd(1) on your second machine (if you don't have them, install them, perhaps by building them from source code with a cross-compiler on your laptop).

I guess that some shared library is missing, or the dynamic linker is different, so try on it:

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

Also run cat /proc/cpuinfo on your second machine.

this should help you understanding what is wrong.

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
  • cpuinfo of both machines are in the first codebox above. I'm afraid `file` `ldd` and `strace` are not available on the 2nd machine. – EDP Feb 08 '16 at 12:15
  • Then you should install temporarily these commands on the second machine – Basile Starynkevitch Feb 08 '16 at 12:17
  • It's rather difficult to add these as they require additional libraries. I've added the results of `file`, `ldd` and `strace` from the 1st system if this helps? I've also did attempts with `gcc -static`, `gcc -l` etc but every time I get ldd-errors – EDP Feb 10 '16 at 10:31
  • You really should do whatever it takes to have `file`, `ldd`, `strace` available on the target machine; perhaps by cross-building them and linking them statically – Basile Starynkevitch Feb 11 '16 at 07:49
  • If it's that important I will try to do that. However the first reason that I choose the current setup was to avoid having to setup a cross-compiling system. Lacking a way to statically linking the libraries on the OpenWrt box is probably my problem in the first place. I'm in a vicious circle. – EDP Feb 11 '16 at 10:21
  • You certainly can setup a cross-building toolset with static linking abilities (e.g. install Linux with cross-compilers on your laptop, etc...); I agree it might take some time. – Basile Starynkevitch Feb 11 '16 at 10:22