Recent

Author Topic: [SOLVD] Android executable not starting  (Read 13531 times)

hinst

  • Sr. Member
  • ****
  • Posts: 303
[SOLVD] Android executable not starting
« on: May 02, 2014, 11:04:50 am »
Another Android-related question if u excuse me:
I am currently "hacking" on my old Android tablet. I have root access, also SSH access from PC. I also have busybox and bash shell installed. Everything works so far.
I can launch executables from /system/bin like this:
Code: [Select]
bash-3.2# /system/bin/run-as
Usage: run-as <package-name> <command> [<args>]
Have no idea what it does, but it works.

Then I compiled FPC program like this:
Code: [Select]
program TestMinimalP;
begin
  WriteLN('Hello bucket');
end.
Code: [Select]
D:\Dev\daemonirc\SrcTest>D:\LA\FPC\bin\i386-win32\fpc.exe -Parm -Tandroid -CpARMv3 -CfSOFT -o..\Bin\arm-android\testminimalp -FU..\Units\arm-android\TestMinimalP TestMinimalP.lpr
Free Pascal Compiler version 2.7.1 [2014/05/02] for arm
Copyright (c) 1993-2014 by Florian Klaempfl and others
Target OS: Android for ARMEL
Compiling TestMinimalP.lpr
Assembling testminimalp
Linking ..\Bin\arm-android\testminimalp
6 lines compiled, 2.5 sec
It compiled successfully.
Then I copied it to /system/bin folder of my tablet, then changed permissions, then tried to launch it.
It says: no such file or directory
Code: [Select]
bash-3.2# /system/bin/testminimalp
bash: /system/bin/testminimalp: No such file or directory
But if I examine it with ls command, then it appears to be present:
Code: [Select]
bash-3.2# ls -l /system/bin/testminimalp
-rwxrwxrwx system   root          26423 2014-05-02 12:55 testminimalp
It is present, and all permissions are enabled.
Then why does it not want to launch it?

I tried to find out why on my own, and here is what I found: if I copy some executable from my tablet to my PC, then examine it with file command, I get:
Code: [Select]
hinst@h-home-pc /cygdrive/d/Dev/daemonirc/Bin/arm-android
$ file run-as
run-as: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, stripped
If I examine my executable, I get:
Code: [Select]
hinst@h-home-pc /cygdrive/d/Dev/daemonirc/Bin/arm-android
$ file TestMinimalP
TestMinimalP: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked (uses shared libs), stripped
The only difference I see is: file reports run-as to be statically linked, while my executable is kind of dynamically linked. I have no idea what are those libraries, but I currently believe that this is the reason why my executable does not work on my Android tablet.

So how do I make FPC link those libraries statically?

P.S: but something tells me that this is not the reason. Then why does it not work?

P.P.S: I would really appreciate if someone could help me with this. The funny thing is: that it worked before. I tried launching executables generated by FPC from console emulator on my phone, and it worked. Why it does not work now I have no idea, I am now suspecting that someone broke it (on FPC side)

P.S.#4: I googled some info, some ppl say that this error is related to libld.so library which is not present on Android.
Indeed I opened my executable in text editor and searched for ".so" found libld.so surrounded by garbage not displayable as text obviously. libld.so is not present on Android, instead there's /system/bin/linker file
« Last Edit: May 03, 2014, 09:26:49 am by hinst »
Too late to escape fate

hinst

  • Sr. Member
  • ****
  • Posts: 303
Re: Android executable not starting
« Reply #1 on: May 03, 2014, 09:26:14 am »
 >:D >:D >:D
Okay, I sort of solved it: http://stackoverflow.com/questions/8610103/how-do-you-cross-compile-elf-executables-for-android
Should pass this option to linker to make it work:
--dynamic-linker=/system/bin/linker
For FPC:
-k--dynamic-linker=/system/bin/linker
Did this and it started working, got "Hello bucket" printed lol
Too late to escape fate

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: [SOLVD] Android executable not starting
« Reply #2 on: May 03, 2014, 12:38:34 pm »
Quote
Should pass this option to linker to make it work:
--dynamic-linker=/system/bin/linker
For FPC:
-k--dynamic-linker=/system/bin/linker
Did this and it started working, got "Hello bucket" printed lol
Hmm... I thought Android (from its Android subsystem) can't run pure elf binaries. Nice info *thumbs up emoticon*

 

TinyPortal © 2005-2018