Android's Linker

"Next task: create a JNI lib that can access Mono... should be fairly easy." Famous last words. I guess I didn't think through the problem of Android using a non-standard linker. Not only is it named and located differently (/system/bin/linker as opposed to ld-linux.so.3), the format of the dynamic libraries it loads is also different as well. So, Android's linker can not load Linux .so files, and vice versa.

This basically means that Mono with its current build configuration can not interact with the Android system at all, other than through RPC. And while it certainly is possible[0] to do that (and Android uses RPC extensively), I feel that would be a clumsy solution, as my goal is to get Mono running side by side with Java/Dalvik, and allow seamless interaction with runtime through usage of Dynamic Language Runtime (I'm not sure if Mono supports the "dynamic" keyword/type yet, but when it does... this will be quite amazing).

There are two possible solutions to this:

  • Recompile Mono and the glibc dependencies using the linker script for Android.
  • Compile Mono within the Android build environment so it uses Bionic instead of libc.

Using Crosstool, I tried to build a new toolchain tailored for Android's linker. I quickly found that whoever set up the toolchain/glibc build process must be a sadist. I wasn't too hesitant to give up on this approach anyway: this would result in two copies of libc being loaded (if that is even possible).

Although getting Mono fully integrated to work with Android's libraries will take considerably longer, I can rest knowing it is the proper solution.

[0] Set up an RPC server for OpenGL ES or skia? Ugh...

7 comments:

Anonymous said...

As a devout linux user for the past 6 or so years who spends 80% of his day doing .net, I am astonished at not only why mono exists but why people would want to port it... Sure, from 2.0 (and VS2005) on it's a great platform to develop for but (1.1/2003 is just plain *expletive*)... it's just not better than Java 5/6 (and Eclipse), on *nix OR Windows. So unless you are working in a MS shop (like I am), why bother with .net? And for Pete's sake, what is the point in developing for mono (which is by definition inferior to .net and java on X)? What possible interest could there be for mono on android?
I really am interested in why someone would bother trying to insert MS stuff where there are clearly better solutions, so if you can be bothered I'm very interested!

Koush said...

1) Java implementations are a complete mess on embedded devices.
2) C# 3.0 is a far better language than Java. Lamdas, true generics (not type erasure, structs, anonymous types, LINQ. Yeah, I went there. :) http://en.wikipedia.org/wiki/Comparison_of_C_Sharp_and_Java
3) Mono performs better than Dalvik/Java on Android. http://www.koushikdutta.com/2009/01/dalvik-vs-mono.html
4) More languages target CIL than Java byte code. Developer freedom.

shamaz said...

Koush : As I've already said on your Dalvik vs Mono post, do you have tried Openjdk6 on ARM ?

Your point about java on embedded device used to be valid... I agree that the different flavors of j2me combined with proprietary and vm were mmm not really optimal ;).
But now, the jdk is GPL and can run on a variety of architectures (in part thanks to the efforts of the icedtea project). So, on this point, *now* there's no real differences between .net (mono) and openjdk.

Next, your 4th point is quite subjective... ever heard about jruby ? groovy ? scala ? etc. ;) (Yes, I know there are also maaany languages for CIL)

Koush said...

I have not tried OpenJDK6 on ARM yet. I only tried Sun's ARM JRE. If someone has a package I can install on ARM, I'd be happy to test it.

shamaz said...

http://gbenson.net/?p=88

hg clone http://icedtea.classpath.org/hg/icedtea6
./configure
make

David said...

35 years ago i wrote my first program (8 bit paper tape). the arguments stay the same. the nouns change. But wake up and smell the coffeee.. My brain hurts like a warehouse, no space in there, for all the android people. Conversion, vested intrest,baclkward compatability and originality will kill us all. take 20mg of headcase, u will be fine/normal/ok/asleep

Anonymous said...

@Koush
1/ Just use : PhoneME, OpenJDK/IcedTea

2/
This is not because something is "better" (I agree for generics) that it will be a market success. Look at VHS vs Betamax for instance or near MS circles HDDVD vs BlueRay ;-)

Same for Java vs MS.net ... beeing an integrated product line (one single editor for every thing) makes it "technically" better & easier. But Java, beeing supported by tons of company makes it "all purpose" and everywhere.

On the long term, .net will vanish when MS will push their "next generation developement paradigm". Look at what as happened to DNA.

Java even if Oracle makes it evil will not vanish, but in worse case will become a "new cobol" (somthing that might not be perfect, but is everywhere and that people can rely on an entire life): this is the power of Libre and GPL.

3/ Possible but Dalvik is a joke from Google, a way not to deal with Sun (oups, Oracle ?) on patents or to pay Jazelle royalties to be able to get silicon acceleration.
On the middle term google will to get back to standard Java.

The only reason google did not wen to OpenJDK+Jazelle is GPL that MS does not want to mess with (because of the impact it will have on handset manufacturers) ;-)

This is like people touting MFC is gold for a decade then bashing it as soon as they discovered .net, while MS was already pushing Java for half a decade ;)

Remeber WFC ? RNI ? JDirect ?

4/ Not sure google vmlanguages list ;-) But, even, how much are used on both sides appart from C# and Java ? Really, language choice is not existing at enterprise side, those languages are language flavors, not complete different solutions that can compete: they offers same paradigms. I miss the functional paradigms that were supposed to be there in original Cool project, but look at C# it is nothing else but a Java made-in MS with some pascalish guys on command. Nice for those who were used of MFC and C++ ... but not a revolution for those used to Java already (JView rulez :P ) : nothing that will make them move to MS tools at least.

.net is doomed, thus Mono is void, the reason : there will never be a full compliance guaranty on any kind of portability outside MS OSes. So please tell me why do I need to run a VM for the same OS & APIs ? Really ... I mean appart from GC obviously.
.net only exists because MS has failed to hook Java (JDirect story) by forgettin to go thru the spec modification process before doing a fork.
If I am wrong and such a kit exist then this would be the end of MS OS division, because there will be no more premium to run MS OSes over alternatives (say Linux for instance).
MS shareholders will never let SteveB kill the OS milking cow, never.
Thus : .net (as a VM at least) will be killed by MS on the long term.

Sad, but quite anticipated.