comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: How to kill GNAT DLL initialization?
Date: Thu, 11 Aug 2016 09:31:29 +0200
Date: 2016-08-11T09:31:29+02:00	[thread overview]
Message-ID: <noh9m8$hi8$1@gioia.aioe.org> (raw)
In-Reply-To: bdc022a5-c2fa-4110-a997-afd4196a4977@googlegroups.com

On 10/08/2016 22:18, ahlan.marriott@gmail.com wrote:
> On Wednesday, 10 August 2016 14:52:33 UTC+2, Dmitry A. Kazakov  wrote:
>> As it seems GNAT DLL may not have initialization code invoked in
>> DllMain. This inevitable deadlocks RTS. Removing user library-level
>> tasks does not help. The RTS itself contains library-level tasks. E.g.
>> when asynchronous select is used.
>>
>> Now the question is how to kill calls to initialization code from DllMain.
>>
>>     for Library_Auto_Init use "false";
>>
>> Is not enough. Are there other attributes I missed?
>>
>> (Maybe there is a way to remove DllMain from the external symbols list
>> during linking?)
>>
> We produce DLLs written using GNAT that are used by other languages - typically C++
> We don't explicitly run any initialisation code, the main procedure is always empty.
> (although this is probably a left over from our ObjectAda days)
> If something has to be initialised then we put this into a
> procedure,  export it and request that our C++ user calls this before calling any
> other routine.

Yes, that is my plan too. GNAT generates files b__dllname.ads/adb 
containing an initialization procedure dllnameinit. This must be called 
to initialize the RTS. The problem is that it is called automatically 
upon DLL load on the context where it freezes. I must find a way to kill 
that call.

> Here is a typical Gpr file for one of our Dlls.
>
> -------
> project Monitor is
>
>    package Naming is
>       for Casing use "mixedcase";
>    end Naming;
>
>    for Library_Name use "Monitor";
>    for Shared_Library_Prefix use "";
>
>    for Source_Dirs use ("W:\Source\Ada\Interfaces\Monitor",
>                         "W:\Source\Ada\Interfaces",
>                         "W:\Source\Ada\Shared",
>                         "W:\Source\Ada\Open\Shared",
>                         "W:\Source\Ada\Open\Shared\Windows");
>
>    for Library_Interface use ("Monitor_Interface");
>
>    for Object_Dir use "objects";
>
>    for Library_Options use ("-LW:\Product\Windows", "resources.o");
>    for Library_Dir use "W:\Product\Windows";
>    for Library_Ali_Dir use "D:\Binary\Ada\Interfaces\Monitor";
>    for Library_Kind use "dynamic";
>    for Library_Standalone use "encapsulated";
>
>    package Pretty_Printer is
>       for Default_Switches ("ada") use ("-i2", "-M120", "-aL", "-A1", "-A4");
>    end Pretty_Printer;
>
>    package Builder is
>       for Default_Switches ("ada") use ("-s", "-g");
>    end Builder;
>
>    package Compiler is
>       for Default_Switches ("ada") use
>          ("-O1", "-gnatQ", "-gnata", "-gnato", "-g", "-gnat12",
>           "-gnatwcehijkmopruvz.c.n.p.t.w.x", "-gnatykmpM120");
>    end Compiler;
>
>    package Binder is
>       for Default_Switches ("ada") use ("-E");
>    end Binder;
>
> end Monitor;

My gpr project is no different, except that Library_Interface is a 
package with some procedures.

> -------
>
> and the main package.
>
> -------
> with Monitor_Interface; --> UD: Drag in Code
>
> procedure Monitor is
> begin
>   null;
> end Monitor;
> -------
>
> Monitor_Interface ads exports all the procedures that the DLL
> provides  and the Adb implements them.

I found that my version of GNAT puts the DLL initialization program into 
the .ctor section. That causes it called regardless anything.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

  reply	other threads:[~2016-08-11  7:31 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-10 12:51 How to kill GNAT DLL initialization? Dmitry A. Kazakov
2016-08-10 20:18 ` ahlan.marriott
2016-08-11  7:31   ` Dmitry A. Kazakov [this message]
2016-08-12  7:56     ` ahlan.marriott
2016-08-12 10:10       ` Dmitry A. Kazakov
2016-08-13  8:59         ` ahlan.marriott
2016-08-13 19:05           ` Dmitry A. Kazakov
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox