Based on some limitations with the NDK standalone toolchain and bionic, I have rolled my own toolchain using crosstool-NG with these general settings:
- binutils-2.22
- gcc-4.5.3 with gfortran enabled
- glibc-2.14.1
- kernel-headers-2.35.7
- arch arm4t
Using this I build an executable and upload all dependencies, including libc, ld-linux etc with it onto my Android device. I manually run the executable with ld-linux.so.3 –library-path …
It is a very complex executable, and it all seems to work except, if I do any system() call, even something basic, like system(“pwd”) or system(NULL) I get 127 as the status (not found). If I go further and use popen instead to collect a response, I get:
*glibc detected * double free or corruption
What is going on? Has anyone succeeded at doing similar? Is there a permissions issue? Is there something fundamentally different about Android that makes system() calls not possible? Where can I find out how bionic handles system and popen (source code) in the end, because I think if you use the NDK you can do system() calls.
(1)
SHELLenvironment variable is unlikely to be set on Android. The default shell/bin/shdoesn’t exist (AFAIK); it’s in/system/bin/sh. This is likely what causessystemto fail.(2) You can find the implementations on GitHub: system, popen. Your crash in glibc sounds like a library bug to me (unless you’re using
popenfrom a signal handler or in a multithreaded environment)