Why does Ada DLL get stuck at adainit when called from Rust over FFI interface?

  ada, dll, ffi, rust, windows

Happy case

Using Mingw I have successfully compiled a minimal hello world windows DLL in Ada and used it over the FFI interface:

package body MY_FFI is
    procedure Hello_World is
    begin
        Ada.Text_IO.Put_Line("Hello world!");
    end Send_Request;
end MY_FFI;
#[link(name = "my_ffi")]
extern "C" {
    #[link_name = "hello_world"]
    fn ada_hello_world();
    fn my_ffiinit(); // same as adainit just renamed by gprbuild
    fn my_ffifinal(); // same as adafinal just renamed by gprbuild
}

pub fn initialize_my_ffi() {
    unsafe {
        println!("step 1");
        my_ffiinit();
        println!("step 2");
        ada_hello_world();
        println!("step 3");
    }
}

Which results in:

step 1
step 2
Hello world!
step 3

Real problem

When my Ada library gets more complicated and requires following extra system DLLs:

  • libgnarl-7.dll

  • libgnat-7.dll

  • libgcc_s_seh-1.dll (mingw posix)

  • libwinpthreadthread-1.dll (mingw posix)

I am not able to exactly single out the code, which requires those extra DLLs, but once the code gets complicated enough to require these DLLs, it just stalls in the rust at the my_ffiinit function, outputting only:

step 1
step 2

Same code on x64 Linux just works. Also cross-compilation for other Linux platforms (powerpc, amr64) works.

When I use Library_Auto_Init="true", wine64 outputs:

0009:err:module:LdrInitializeThunk "libmy_ffi.dll" failed to initialize, aborting
0009:err:module:LdrInitializeThunk Initializing dlls for L"Z:test.exe" failed, status 20474343

Source: Windows Questions

LEAVE A COMMENT