Dynamic Shared Library in Android Another Approach - Don't Use android Linker

2,315 views
Skip to first unread message

Susmith M R

unread,
Feb 9, 2008, 8:36:37 AM2/9/08
to Android Internals, susmi...@in.bosch.com
Hai all,
Anroid is using a linker that is different from historical linux
linkers like ld.so,ld-linux.so.2,ld-linux.so.3.
I think ld.so is for a.out ld-linux.so.2 is for elf and ld-linux.so.3
is the new one which is different
from normal elf linker. Correct me if i am wrong.

I actually usded the ld-linux.so.3 instead of /system/bin/linker of
android.

So we will start with a simple program
hello.c
#include<stdio.h>
int main()
{
printf("\n Hello World \n");
return 0;
}

Toolchain is from Code Sourcery (arm gnu/linux)
arm-none-linux-gnueabi-gcc -o hello.out hello.c -Wl,-dynamic-linker=/
system/lib/ld-linux.so.6 (...DO NOT USE -static let it link
dynamically )

Just check the hello.out to findout the dependencies.
I just guessed(because i dont have ldd in my cywin) that it needs
ld-linux.so.6,
libgcc_s.so,
libc.so.6

I took these files from toolchain library (libc/usr/lib) and pushed
into the emulator directory /system/lib

Now push the hello.out to the emulator and give the permission to
execute (chmod) and u can see ur output
without static linking.

So every program whether it is DSO or any thing , if it is created
successfully with the toolchiain in
ur host system it can be executed in the emulator. U have to only push
the needed dynamic shared libraries
into the emulator system library and whenever u r linking dynamically
use the option " -Wl,-dynamic-linker=/system/lib/ld-linux.so.6 "

Good Luck ..
Best Regards
Susmith M R

Detro

unread,
Feb 23, 2008, 6:46:41 AM2/23/08
to Android Internals
Hi.

Just wondering.
I think this "3rd" linking system is based on the "Symbian way".
Because name resolution is expensive, whenever you compile a library,
it has to have a table that associate integers with function names.
Then, at linking time, you call these integers instead of names, so
it's much faster.
(Obviously, this is a raw explaination).

Susmith M R

unread,
Feb 24, 2008, 1:22:11 PM2/24/08
to Android Internals
Hai Detro,
I faced a lot of problem with android linker while i was porting my c+
+ application. I found it is impossible to port it with the libc of
android. So here
i explained the way i ported my application to android and it was
successful. What is not clear for u. Have u tried this way.
> > system/lib/ld-linux.so.3 (...DO NOT USE -static let it link
> > dynamically )
>
> > Just check the hello.out to findout the dependencies.
> > I just guessed(because i dont have ldd in my cywin) that it needs
> > ld-linux.so.3,
> > libgcc_s.so,
> > libc.so.6
>
> > I took these files from toolchain library (libc/usr/lib) and pushed
> > into the emulator directory /system/lib
>
> > Now push the hello.out to the emulator and give the permission to
> > execute (chmod) and u can see ur output
> > without static linking.
>
> > So every program whether it is DSO or any thing , if it is created
> > successfully with the toolchiain in
> > ur host system it can be executed in the emulator. U have to only push
> > the needed dynamic shared libraries
> > into the emulator system library and whenever u r linking dynamically
> > use the option " -Wl,-dynamic-linker=/system/lib/ld-linux.so.3 "
Reply all
Reply to author
Forward
0 new messages