Working Free Pascal android JNI example

classic Classic list List threaded Threaded
43 messages Options
123
Reply | Threaded
Open this post in threaded view
|

Re: Working Free Pascal android JNI example

Michael Van Canneyt


On Tue, 7 Dec 2010, Sven Barth wrote:

> Am 07.12.2010 12:12, schrieb Matt Emson:
>> On 07/12/2010 10:46, Felipe Monteiro de Carvalho wrote:
>>> Still not ideal, however.
>>
>> Well, no. As Android targets any processor - not just ARM. Indeed, there
>> are Intel based versions. Native is bad, and only come in to existence
>> to compete with other platforms with purely native compilation - and
>> then purely to counteract criticisms on the performance of games and
>> multimedia apps. Davlik was created for a reason - compile once, run on
>> multiple targets. Would it not be a better solution to create a Dalvik
>> back-end? As I understand it, Dalvik is very, far from a traditional
>> stack based Java VM and closer to a traditional register based processor
>> in design. I know little about it, but the benefits of Android, as a
>> platform, are completely lost when one focuses on native compilation.
>
> I don't see it that problematic to create a Dalvik code generator (or a
> normal Java or CIL one). The biggest problem is to create a suitable RTL and
> to be able to use the classes that are provided by the VM.

In fact I think this is one of the more easy things.
The main problem seems to me that you need to support things like pointers,
which is something deeply embedded in Pascal.

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Working Free Pascal android JNI example

Marco van de Voort
In our previous episode, Michael Van Canneyt said:
> > normal Java or CIL one). The biggest problem is to create a suitable RTL and
> > to be able to use the classes that are provided by the VM.
>
> In fact I think this is one of the more easy things.
> The main problem seems to me that you need to support things like pointers,
> which is something deeply embedded in Pascal.

I think the "suitable RTL" is a reference to an earlier discussion about
this subject, where this (pointers) was also said, and that maintaining an
native RTL without pointers was not desirable.  (and just after that is in
the air the guaranteed destructors will start to that, and the systems will
divergate more and more )

IOW, only the compiler frontend is shared, nothing else.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Working Free Pascal android JNI example

Michael Van Canneyt


On Tue, 7 Dec 2010, Marco van de Voort wrote:

> In our previous episode, Michael Van Canneyt said:
>>> normal Java or CIL one). The biggest problem is to create a suitable RTL and
>>> to be able to use the classes that are provided by the VM.
>>
>> In fact I think this is one of the more easy things.
>> The main problem seems to me that you need to support things like pointers,
>> which is something deeply embedded in Pascal.
>
> I think the "suitable RTL" is a reference to an earlier discussion about
> this subject, where this (pointers) was also said, and that maintaining an
> native RTL without pointers was not desirable.

I think 'RTl' is way too limited in scope. Pointers are used in
many many pascal sources.

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Working Free Pascal android JNI example

Marco van de Voort
In our previous episode, Michael Van Canneyt said:
> >> In fact I think this is one of the more easy things.
> >> The main problem seems to me that you need to support things like pointers,
> >> which is something deeply embedded in Pascal.
> >
> > I think the "suitable RTL" is a reference to an earlier discussion about
> > this subject, where this (pointers) was also said, and that maintaining an
> > native RTL without pointers was not desirable.
>
> I think 'RTl' is way too limited in scope.

It goes of course even more for libraries above that level. I don't see any
future for code sharing (rtl,libs) between bytecode and native. I've seen
the mess with Delphi.NET on the delphi side, and don't want a slippery slope
in that direction.

The pointers are just the first thing. Object model, RTTI etc are next.

But if the overlap with the bytecode generator is only in the compiler, then
that satisfies me, and is it something for the compiler devels to decide.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Working Free Pascal android JNI example

Jürgen Hestermann
In reply to this post by Matt Emson-2
Matt Emson schrieb:
> Native is bad, and only come in to existence to compete with other
> platforms with purely native compilation -
I disagree. Just the opposite. There were already lots of attempts to
create a processor independend programming layer (i.e. USCD-Pascal with
the p-code in the seventies) but none of them survived very long. They
all had a great disadvantage: Bad performance. And it is quite evident,
that if you would have a "universal API layer" then all processors would
be the same. There would be no need to create new processors because
they all would compute the same commands from the one and only API
layer. I doubt that this idea will survive long.


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Is FPC implementing part or most of Delphi 2010's new RTTI?

tcoq
In reply to this post by Marco van de Voort
Dear all,
I understand Delphi 2010 has changed its RTTI mechanism, and it is said
to be much more usable than the previous one.
(see here for example: http://www.malcolmgroves.com/blog/?p=476)

What are the FPC team's plans about improving the RTTI? Any similar or
as easy to use/powerful?
For example, are there any attributes?

Best regards,
Thierry
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Is FPC implementing part or most of Delphi 2010's new RTTI?

Jonas Maebe-2

On 10 Dec 2010, at 08:09, Thierry Coq wrote:

> What are the FPC team's plans about improving the RTTI? Any similar  
> or as easy to use/powerful?

Anyone needing this is welcome to submit patches. I don't think anyone  
is working on it right now, or planning to in the near future.

> For example, are there any attributes?

Not at this time.


Jonas

PS: please do not reply to existing messages when starting a new  
topic, it messes up threading both in the online archive and in many  
mail clients.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Working Free Pascal android JNI example

Felipe Monteiro de Carvalho
In reply to this post by Benjamin Jan Alexander Rosseaux-2
Hello, I am ressuscitating this ancient thread because I'd like to
continue the talk about it =)

My main doubt here is if androidprt0.as is really required, which
would mean that I can only produce android libraries if I make changes
to the compiler.

Benjamin, couldn't one just declare the missing simbols in code? This
would simplify things a bit.

Original message since most probably won't have it:

On Sun, Jun 27, 2010 at 9:50 AM, Benjamin Jan Alexander Rosseaux
<[hidden email]> wrote:

> I've done a working Free Pascal android JNI example (with working .apk for
> current ARM-based Android device of the second device generation (because
> with VFPv3, so Motorola Droid/Milestone, HTC Desire, Nexus One, Samsung
> Galaxy S, and so on) inside)
>
> http://vserver.rosseaux.net/stuff/FPCAndroidJNINativeTest.zip
>
> It contains androidprt0.as as replacement for the empty arm/linux dllprt0.as
> of the FreePascal RTL from the SVN, because otherwise the Android Dalvik VM
> refuses to load the .so library because of missed/absent
> global/import/export symbols (_haltproc_eabi, __strptr,
> __operatingsystem_parameter_argv and so on).
>
> It contains also a own JNI header port from the Android NDK, and own ARM
> Toolchain hook binaries to inject some command line parameters to the
> original "as" and "ld" binary calls. For "as": "--march=armv7-a
> -mfloat-abi=softfp -mfpu=vfp3" and for "ld": "--fix-cortex-a8"
>
> And important FPC parameters are -CpARMv6 -CfVFPV3
>
> I've done it, because i'm needing my own ECMAScript 5th edition engine
> called BESEN in a Android project of me.
>
> Someone can make maybe a true patch from this for FreePascal for a offical
> android target support in FreePascal. And my OpenGL ES 2.0 headers (what I
> did originally for Nokia N900 for Maemo 5) are already in the FPC
> bugtracker, which should also under Android after a single-line-change of
> the OpenGL ES library path.
>
> Benjamin 'BeRo' Rosseaux
>
>
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>



--
Felipe Monteiro de Carvalho
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Working Free Pascal android JNI example

Thomas Schatzl
 Hi,

 On Wed, 10 Aug 2011 11:09:26 +0200, Felipe Monteiro de Carvalho wrote:
> Hello, I am ressuscitating this ancient thread because I'd like to
> continue the talk about it =)
>
> My main doubt here is if androidprt0.as is really required, which
> would mean that I can only produce android libraries if I make
> changes
> to the compiler.

 Note that there is no dedicated android/arm support (or any arm
 support) for freepascal yet. In some circumstances the arm/linux stuff
 works.

> Benjamin, couldn't one just declare the missing simbols in code? This
> would simplify things a bit.

 An improved dllprt0.as has been created since, which works fine at
 least for arm/linux.

 However, you might want to use the hack from
 http://mantis.freepascal.org/view.php?id=18833 on android for now. If
 you can give me some documentation how/if argc/argv/envp are passed to a
 shared library on android, one could see if support can be added. I
 assume that some sort of new target may need to be added though.

 You might want to check whether proper initialization and finalization
 is performed for those libraries correctly for arm/android. At least
 when using dlopen and friends on arm/linux (and others) this works.

 When linking a FPC library using $LINKLIB, initialization/finalization
 is not called on several linux platforms (ppc/ppc64/arm) or crashes
 badly on unload at least on some linuxes (x86/amd64 on ubuntu).

>> It contains also a own JNI header port from the Android NDK, and own
>> ARM
>> Toolchain hook binaries to inject some command line parameters to
>> the
>> original "as" and "ld" binary calls. For "as": "--march=armv7-a
>> -mfloat-abi=softfp -mfpu=vfp3" and for "ld": "--fix-cortex-a8"
>>
>> And important FPC parameters are -CpARMv6 -CfVFPV3

 Not sure whether the as/ld issues have been fixed in the meantime.

 Hth,
 Thomas

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Working Free Pascal android JNI example

Thomas Schatzl
 Hi,

 On Wed, 10 Aug 2011 11:59:03 +0200, Thomas Schatzl wrote:

> Hi,
>
> On Wed, 10 Aug 2011 11:09:26 +0200, Felipe Monteiro de Carvalho
> wrote:
>> Hello, I am ressuscitating this ancient thread because I'd like to
>> continue the talk about it =)
>>
>> My main doubt here is if androidprt0.as is really required, which
>> would mean that I can only produce android libraries if I make
>> changes
>> to the compiler.
>
> Note that there is no dedicated android/arm support (or any arm
> support) for freepascal yet. In some circumstances the arm/linux
> stuff
> works.

 meant "or any android support" here.

 Hth,
  Thomas

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Working Free Pascal android JNI example

Felipe Monteiro de Carvalho
In reply to this post by Thomas Schatzl
On Wed, Aug 10, 2011 at 11:59 AM, Thomas Schatzl <[hidden email]> wrote:
> However, you might want to use the hack from
> http://mantis.freepascal.org/view.php?id=18833 on android for now.

What do you think about merging this hack to trunk and to 2.6.0? I can
do the commit on trunk.

I think that a hack support is better then no support at all.

> If you can give me some documentation how/if argc/argv/envp are passed to a shared
> library on android

I have no idea.

> When linking a FPC library using $LINKLIB, initialization/finalization is
> not called on several linux platforms (ppc/ppc64/arm) or crashes badly on
> unload at least on some linuxes (x86/amd64 on ubuntu).

=( The LCL contains initialization/finalization sections, so that
could prevent the LCL to work via JNI.

--
Felipe Monteiro de Carvalho
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Working Free Pascal android JNI example

Jonas Maebe-2

On 10 Aug 2011, at 12:10, Felipe Monteiro de Carvalho wrote:

> On Wed, Aug 10, 2011 at 11:59 AM, Thomas Schatzl  
> <[hidden email]> wrote:
>> However, you might want to use the hack from
>> http://mantis.freepascal.org/view.php?id=18833 on android for now.
>
> What do you think about merging this hack to trunk and to 2.6.0? I can
> do the commit on trunk.
>
> I think that a hack support is better then no support at all.

No, hacks like that do not belong in trunk.


Jonas
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

RE : [fpc-pascal] Working Free Pascal android JNI example

Ludo Brands
In reply to this post by Felipe Monteiro de Carvalho
> My main doubt here is if androidprt0.as is really required,
> which would mean that I can only produce android libraries if
> I make changes to the compiler.
>

In NativeTest\jni is a makeandroid.bat that assembles androidprt0 and calls
ppcrossarm with -k"-landroidprt0". No need to change the compiler for that,
unless there are conflicts with existing arm initialisation.

Ludo

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Working Free Pascal android JNI example

Felipe Monteiro de Carvalho
In reply to this post by Jonas Maebe-2
On Wed, Aug 10, 2011 at 12:41 PM, Jonas Maebe <[hidden email]> wrote:
> No, hacks like that do not belong in trunk.

And about release branches then? Are hacks allowed to be merged
directly to release branches?

--
Felipe Monteiro de Carvalho
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Working Free Pascal android JNI example

Jonas Maebe-2

On 11 Aug 2011, at 11:56, Felipe Monteiro de Carvalho wrote:

> On Wed, Aug 10, 2011 at 12:41 PM, Jonas Maebe <[hidden email]
> > wrote:
>> No, hacks like that do not belong in trunk.
>
> And about release branches then? Are hacks allowed to be merged
> directly to release branches?

Is that a joke? No, of course they aren't.


Jonas
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Working Free Pascal android JNI example

Felipe Monteiro de Carvalho
Well, the hack doesn't seam to really work well anyway, because it
crashes executables generated by the compiler =(

So one can either activate the hack and have a compiler only for DLLs
or not have it and have a compiler only for executables...

Where does argv and argc come from? From dllprt0.as ?

--
Felipe Monteiro de Carvalho
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Working Free Pascal android JNI example

Felipe Monteiro de Carvalho
Or more generally: Any ideas of where / what I should look for to fix this?

--
Felipe Monteiro de Carvalho
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: RE : [fpc-pascal] Working Free Pascal android JNI example

Torsten Bonde Christiansen-2
In reply to this post by Ludo Brands
Hi Ludo.

I try to use you androidprt0.so but I keep getting the same error.

I do not have much experience in the lower parts of how the
linking/assembling is done,
so I hope you can help me out here.

I get the following error:

$ ppcrossarm -b -B -XX -Xc -XD -Tlinux -darm -k"-landroidprt0" pascaljni.lpr
Free Pascal Compiler version 2.4.4 [2011/11/18] for arm
Copyright (c) 1993-2010 by Florian Klaempfl
Target OS: Linux for ARMEL
Compiling pascaljni.lpr
Assembling pascaljni
Linking libpascaljni.so
/usr/local/bin/arm-linux-ld: warning: link.res contains output sections;
did you forget -T?
/usr/lib/fpc/2.4.4/units/arm-linux/rtl/dllprt0.o: In function `_haltproc':
androidprt0.as:(.text+0x0): multiple definition of `_haltproc'
./libandroidprt0.so:androidprt0.as:(.text+0x0): first defined here
/usr/lib/fpc/2.4.4/units/arm-linux/rtl/dllprt0.o: In function
`_haltproc_eabi':
androidprt0.as:(.text+0x8): multiple definition of `_haltproc_eabi'
./libandroidprt0.so:androidprt0.as:(.text+0x8): first defined here
/usr/lib/fpc/2.4.4/units/arm-linux/rtl/dllprt0.o:(.data+0x0): multiple
definition of `operatingsystem_parameter_envp'
./libandroidprt0.so:(.data+0x0): first defined here
/usr/lib/fpc/2.4.4/units/arm-linux/rtl/dllprt0.o:(.data+0x4): multiple
definition of `operatingsystem_parameter_argc'
./libandroidprt0.so:(.data+0x4): first defined here
/usr/lib/fpc/2.4.4/units/arm-linux/rtl/dllprt0.o:(.data+0x8): multiple
definition of `operatingsystem_parameter_argv'
./libandroidprt0.so:(.data+0x8): first defined here
pascaljni.lpr(19) Error: Error while linking
pascaljni.lpr(19) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted

As you can se i'm using FPC 2.4.4 (releases2_4_4 of the subversion
repository) and there is clearly a conflict between
two competing unit. But how do I resolve this?

Regards,
Torsten Bonde Christiansen.

On 2011-08-11 11:54, Ludo Brands wrote:
>> My main doubt here is if androidprt0.as is really required,
>> which would mean that I can only produce android libraries if
>> I make changes to the compiler.
>>
>
> In NativeTest\jni is a makeandroid.bat that assembles androidprt0 and calls
> ppcrossarm with -k"-landroidprt0". No need to change the compiler for that,
> unless there are conflicts with existing arm initialisation.


>
>
> Ludo
>
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

RE : RE : [fpc-pascal] Working Free Pascal android JNI example

Ludo Brands
> /usr/lib/fpc/2.4.4/units/arm-linux/rtl/dllprt0.o: In function
> `_haltproc':
> androidprt0.as:(.text+0x0): multiple definition of `_haltproc'
> ./libandroidprt0.so:androidprt0.as:(.text+0x0): first defined here
> /usr/lib/fpc/2.4.4/units/arm-linux/rtl/dllprt0.o: In function
> `_haltproc_eabi':

A long time ago, august ;) , libandroidprt0 was a replacement for linux arm
dllprt0.as that apparently was virtually empty. In the mean time dllprt0
contains all of libandroidprt0 + more. Hence the duplicate definitions. Just
remove the -k"-landroidprt0". You won't miss anything.

A lot has changed since august and I haven't followed the development
closely. I think you better refer to the work Felipe is doing on android.
http://wiki.lazarus.freepascal.org/Android_Interface

Ludo

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: RE : RE : [fpc-pascal] Working Free Pascal android JNI example

Torsten Bonde Christiansen-2
On 2011-11-25 13:38, Ludo Brands wrote:

>> /usr/lib/fpc/2.4.4/units/arm-linux/rtl/dllprt0.o: In function
>> `_haltproc':
>> androidprt0.as:(.text+0x0): multiple definition of `_haltproc'
>> ./libandroidprt0.so:androidprt0.as:(.text+0x0): first defined here
>> /usr/lib/fpc/2.4.4/units/arm-linux/rtl/dllprt0.o: In function
>> `_haltproc_eabi':
> A long time ago, august ;) , libandroidprt0 was a replacement for linux arm
> dllprt0.as that apparently was virtually empty. In the mean time dllprt0
> contains all of libandroidprt0 + more. Hence the duplicate definitions. Just
> remove the -k"-landroidprt0". You won't miss anything.
>
> A lot has changed since august and I haven't followed the development
> closely. I think you better refer to the work Felipe is doing on android.
> http://wiki.lazarus.freepascal.org/Android_Interface
Is it still a problem to use libraries under android? I believe I read
somewhere that the env pointer is not set correctly.

-Torsten.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
123