not able to run binary

Post new topic   Reply to topic    DD-WRT Forum Index -> Generic Questions
Author Message
jatinderjit
DD-WRT Novice


Joined: 12 Sep 2008
Posts: 3

PostPosted: Fri Sep 19, 2008 11:31    Post subject: not able to run binary Reply with quote
I have cross-compiled a "Hello World" program on my i386 Linux host and then put it on a WRT54G running dd-wrt (using wget in binary mode) in the /tmp directory (RAMFS)

My problem is when I try to run the binary (./a.out) from the shell it says "Syntax error on line 1".

Is the shell confused and thinks that it is a shell script and not a binary executable.

I have used buildroot to build the gcc compiler and had set the target to MIPS32. The target is a WRT54G version6 running dd-wrt-micro-generic v24.
Sponsor
tosiara
DD-WRT User


Joined: 20 Dec 2011
Posts: 100

PostPosted: Thu Jul 31, 2014 15:45    Post subject: Reply with quote
Sorry to bump such old thread, but I would like to add some useful info about running binaries.

0. Always make sure you did "chmod +x hello"

1. "not found" means the binary was compiled against libc that is not found on the router:
Code:

root@router:~# ./hello
-sh: ./hello: not found


To verify, check the binary on your build machine, example:

Code:
# readelf -a hello1 | grep interpreter
      [Requesting program interpreter: /lib/ld-musl-mips.so.1]
# readelf -a hello2 | grep interpreter
      [Requesting program interpreter: /lib/ld-uClibc.so.0]


2. "permission denied" means wrong architecture, you have compiled using wrong platform, ex, binaries built for Atheros does not run on Broadcom:
Code:

root@router:~# ./hello
-sh: ./hello: Permission denied



3. "file" command can give you some info, just compare with existing executables that run fine and try building again for different arch:

Code:
# file hello1
hello1: ELF 32-bit MSB executable, MIPS, MIPS32 rel2 version 1 (SYSV), dynamically linked (uses shared libs), corrupted section header size
# file hello2
hello2: ELF 32-bit MSB executable, MIPS, MIPS32 rel2 version 1, dynamically linked (uses shared libs), corrupted section header size
# file hello3
hello3: ELF 32-bit LSB executable, MIPS, MIPS32 rel2 version 1, dynamically linked (uses shared libs), corrupted section header size


4. if you get empty output, like this:

Code:
# ./hello
#


then make sure you compile with -DNEED_PRINTF flag

Hope this helps
jnjn
DD-WRT User


Joined: 07 Jun 2006
Posts: 448
Location: PRC

PostPosted: Sat Oct 25, 2014 7:33    Post subject: Reply with quote
tosiara wrote:
Sorry to bump such old thread, but I would like to add some useful info about running binaries.

0. Always make sure you did "chmod +x hello"

1. "not found" means the binary was compiled against libc that is not found on the router:
Code:

root@router:~# ./hello
-sh: ./hello: not found


To verify, check the binary on your build machine, example:

Code:
# readelf -a hello1 | grep interpreter
      [Requesting program interpreter: /lib/ld-musl-mips.so.1]
# readelf -a hello2 | grep interpreter
      [Requesting program interpreter: /lib/ld-uClibc.so.0]


2. "permission denied" means wrong architecture, you have compiled using wrong platform, ex, binaries built for Atheros does not run on Broadcom:
Code:

root@router:~# ./hello
-sh: ./hello: Permission denied



3. "file" command can give you some info, just compare with existing executables that run fine and try building again for different arch:

Code:
# file hello1
hello1: ELF 32-bit MSB executable, MIPS, MIPS32 rel2 version 1 (SYSV), dynamically linked (uses shared libs), corrupted section header size
# file hello2
hello2: ELF 32-bit MSB executable, MIPS, MIPS32 rel2 version 1, dynamically linked (uses shared libs), corrupted section header size
# file hello3
hello3: ELF 32-bit LSB executable, MIPS, MIPS32 rel2 version 1, dynamically linked (uses shared libs), corrupted section header size


4. if you get empty output, like this:

Code:
# ./hello
#


then make sure you compile with -DNEED_PRINTF flag

Hope this helps


It's really useful. Thank you.
BTW: What can I do if i've got some binary compiled for uclibc but the host is with libc and it's not possible to recompile from source code?
Display posts from previous:    Page 1 of 1
Post new topic   Reply to topic    DD-WRT Forum Index -> Generic Questions All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum