FFM with Fortran

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Wed Jul 17 09:54:37 UTC 2024


Hi Giuseppe

On 17/07/2024 10:11, Giuseppe Barbieri wrote:
> Hello folks,
>
>
> I'd like to call from the Jvm a shared library (.so) compiled from 
> Fortran code, using some Python code.
>
> My first question is, would this work? I assume yes

Interesting question. As long as you have some .so shared library, that 
should work.

Note that Fortran has slightly different rules for passing arguments (as 
it features different types than C). Typically, ABIs deal with Fortran 
by "lowering it" into C. For instance, the SysV ABI (the one used by 
Linux x64) deals with Fortran in section 9.2:

https://refspecs.linuxbase.org/elf/x86_64-abi-0.99.pdf

It might be useful to read that section of the ABI before attempting to 
use the Linker, to understand how Fortran data types are mapped to C types.


>
> Now, since I don't have any classic header (.h) to generate something 
> automatically with jextract, I guess I'm gonna have to do this 
> manually, but is there a way, by any chance, I can inspect the binary 
> library to list the different methods (and their signature)?
On Linux you have `objdump -T <filename>` which lists all the symbols in 
the shared library. For signatures, we're out of luck: unless the 
library contains debugging information, signatures are not preserved in 
the shared library file. This is why jextract works on header files and 
not just shared library files.
>
> Otherwise I have to dig into the Fortran source code..

It seems like this would be the best way to go.

Let us know how you get along.

Maurizio

>
>
> Thanks in advance,
> Giuseppe


More information about the panama-dev mailing list