2019-07-22
Keywords: / system / bin / sh: xxx: No such file or directory
Although Android is based on Linux, but I fear for their compilation chain it is likely not the same, which leads to translation of the program may not be universal, even if they are Linux-based.
And some can not universal fundamental reason is that the program is running relies environment are not met, such as common that some libraries are missing.
I have a demand side needs to be a third party, the original target operating environment is an embedded Linux environment running an executable program on the environment Android4.4.
Upon receipt of this demand just when I was head of a burst, a different compiler chain I think his legs felt weak.
Sure enough, just a want to run this program, it will give a report this error
/system/bin/sh: ./system/home1/ctstor/ctserver: No such file or directory
I do not even think of the band, certainly lead to a different compiler chain does not meet the operating environment so that the program can not run.
But the question had to solve ah, we can not say it directly compile and link different leadership can not do it.
How to do it? Look at it in the end missing something.
This executable program about environmental dependency information with pure Linux environment point of view. I put down here is the program analysis ubuntu, because no procedures on the author's Android4.4.
View this executable program compiled by the command dependency information
readelf -l xxx
The results are shown below
Elf file type is EXEC (Executable file) Entry point 0xe6e0 There are 8 program headers, starting at offset 52 Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align EXIDX 0x00be90 0x00013e90 0x00013e90 0x00008 0x00008 R 0x4 PHDR 0x000034 0x00008034 0x00008034 0x00100 0x00100 R E 0x4 INTERP 0x000134 0x00008134 0x00008134 0x00013 0x00013 R 0x1 [Requesting program interpreter: /lib/ld-linux.so.3] LOAD 0x000000 0x00008000 0x00008000 0x0be9c 0x0be9c R E 0x8000 LOAD 0x00c000 0x0001c000 0x0001c000 0x0067c 0x006cc RW 0x8000 DYNAMIC 0x00c01c 0x0001c01c 0x0001c01c 0x00130 0x00130 RW 0x4 NOTE 0x000148 0x00008148 0x00008148 0x00020 0x00020 R 0x4 GNU_STACK 0x000000 0x00000000 0x00000000 0x00000 0x00000 RW 0x4 Section to Segment mapping: Segment Sections... 00 .ARM.exidx 01 02 .interp 03 .interp .note.ABI-tag .hash .dynsym .dynstr .gnu.version .gnu.version_r .rel.dyn .rel.plt .init .plt .text .fini .rodata .ARM.exidx .eh_frame 04 .init_array .fini_array .jcr .dynamic .got .data .bss 05 .dynamic 06 .note.ABI-tag 07
We can see part of the bold red above show that running the program requires an "interpreter." It means in order to load the program, the operating environment must be part of the library bold yellow above, is /lib/ld-linux.so.3 library.
This is not to say that, as long as I will this library into the specified path, it can be loaded with it? Try to know.
But before that, we have a critical step: the compiler must know this chain executable program uses.
I have here a document, record its compilation chain: arm-none-linux-gnueabi
Directly to the Internet to download the compilation chain, then find ld-linux.so.3 library inside, and then into the Android development board to go just fine.
It is noted here that it is required lib directory under the root directory, Android4.4 system without default / lib directory. To create your own.
First opened at the root of the operation is limited
mount -o remount r,w /
Of course, this step is not necessarily able to execute successfully, if you do not succeed, it would have to go and find your self a reason why.
Then mkdir / lib and ld-linux.so.3 download go to this directory.
There is also a key point: You can not create out of the directory permissions to modify and continue to download files. Otherwise, the time will be reported in running a permission denied error.
Then try this program really is not reported No such file or directory in front of the wrong that. But another error report
error while loading shared libraries: libqte.so.3: cannot open shared object file: No such file or directory
No such file or directory or wrong, just another No such file or directory error. And this mistake is very obvious, is the lack of dynamic run-time library.
This time, in front of ubuntu have to go back in to see what library dependencies need to run the executable program period.
readelf -d xxx
Then you can see the following results
Dynamic section at offset 0xc01c contains 33 entries: Tag Type Name/Value 0x00000001 (NEEDED) Shared library: [libqte.so.3] 0x00000001 (NEEDED) Shared library: [libts-0.0.so.0] 0x00000001 (NEEDED) Shared library: [librt.so.1] 0x00000001 (NEEDED) Shared library: [libpthread.so.0] 0x00000001 (NEEDED) Shared library: [libdl.so.2] 0x00000001 (NEEDED) Shared library: [libstdc++.so.6] 0x00000001 (NEEDED) Shared library: [libm.so.6] 0x00000001 (NEEDED) Shared library: [libgcc_s.so.1] 0x00000001 (NEEDED) Shared library: [libc.so.6] 0x0000000f (RPATH) Library rpath: [/usr/qte338-target2/lib] 0x0000000c (INIT) 0xd778 0x0000000d (FINI) 0x1317c 0x00000019 (INIT_ARRAY) 0x1c000 0x0000001b (INIT_ARRAYSZ) 20 (bytes) 0x0000001a (FINI_ARRAY) 0x1c014 0x0000001c (FINI_ARRAYSZ) 4 (bytes) 0x00000004 (HASH) 0x8168 0x00000005 (STRTAB) 0xa184 0x00000006 (SYMTAB) 0x8b24 0x0000000a (STRSZ) 10293 (bytes) 0x0000000b (SYMENT) 16 (bytes) 0x00000015 (DEBUG) 0x0 0x00000003 (PLTGOT) 0x1c14c 0x00000002 (PLTRELSZ) 2608 (bytes) 0x00000014 (PLTREL) REL 0x00000017 (JMPREL) 0xcd48 0x00000011 (REL) 0xcd08 0x00000012 (RELSZ) 64 (bytes) 0x00000013 (RELENT) 8 (bytes) 0x6ffffffe (VERNEED) 0xcc88 0x6fffffff (VERNEEDNUM) 4 0x6ffffff0 (VERSYM) 0xc9ba 0x00000000 (NULL) 0x0
Then it is clear, the above several library files marked as NEEDED all copied to / lib directory. These libraries can generally be found in the specified compilation chain, if there is some special libraries are not directly included in the compilation chain, it would have to think of other ways to find the. In general, the program slightly negative point of responsibility of these providers will come to the library together.
After somehow library file, go running to find it. Our original target operating environment is an embedded Linux environment executable program up and running in under Android.