www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - druntime investigation troubles

reply Denis Shelomovskij <verylonglogin.reg gmail.com> writes:
Looks like `_STI_monitor_staticctor` is called by C runtime on Windows. 
And C runtime isn't open-source.

It creates troubles for investigation druntime (for me at least). Why is 
it so? Why not to call everything in C `main`, what's the reason?

If there is no list of stuff done before C `main` druntime isn't 
open-source for me because I can't understand what is taking place just 
with druntime sources.

-- 
Денис В. Шеломовский
Denis V. Shelomovskij
May 20 2012
parent reply =?UTF-8?B?QWxleCBSw7hubmUgUGV0ZXJzZW4=?= <alex lycus.org> writes:
On 20-05-2012 10:41, Denis Shelomovskij wrote:
 Looks like `_STI_monitor_staticctor` is called by C runtime on Windows.
 And C runtime isn't open-source.

 It creates troubles for investigation druntime (for me at least). Why is
 it so? Why not to call everything in C `main`, what's the reason?

 If there is no list of stuff done before C `main` druntime isn't
 open-source for me because I can't understand what is taking place just
 with druntime sources.

Huh? It's perfectly open source. Read src/rt/monitor.c. -- Alex Rønne Petersen alex lycus.org http://lycus.org
May 20 2012
next sibling parent reply =?UTF-8?B?QWxleCBSw7hubmUgUGV0ZXJzZW4=?= <alex lycus.org> writes:
On 20-05-2012 18:20, Alex Rønne Petersen wrote:
 On 20-05-2012 10:41, Denis Shelomovskij wrote:
 Looks like `_STI_monitor_staticctor` is called by C runtime on Windows.
 And C runtime isn't open-source.

 It creates troubles for investigation druntime (for me at least). Why is
 it so? Why not to call everything in C `main`, what's the reason?

 If there is no list of stuff done before C `main` druntime isn't
 open-source for me because I can't understand what is taking place just
 with druntime sources.

Huh? It's perfectly open source. Read src/rt/monitor.c.

Seems like I misunderstood what you were saying. Right, the C runtime on *Windows* is closed source. But, I don't know why you think that function is called by the C runtime; see src/rt/dmain2.d. -- Alex Rønne Petersen alex lycus.org http://lycus.org
May 20 2012
parent reply Jacob Carlborg <doob me.com> writes:
On 2012-05-20 18:25, Alex Rønne Petersen wrote:

 Seems like I misunderstood what you were saying. Right, the C runtime on
 *Windows* is closed source. But, I don't know why you think that
 function is called by the C runtime; see src/rt/dmain2.d.

Have a look again. It's only called on Posix: https://github.com/D-Programming-Language/druntime/blob/7d663821d39cfe8874cb95b0df46b5065a770cef/src/rt/dmain2.d#L364 -- /Jacob Carlborg
May 20 2012
parent reply =?UTF-8?B?QWxleCBSw7hubmUgUGV0ZXJzZW4=?= <alex lycus.org> writes:
On 20-05-2012 22:13, Jacob Carlborg wrote:
 On 2012-05-20 18:25, Alex Rønne Petersen wrote:

 Seems like I misunderstood what you were saying. Right, the C runtime on
 *Windows* is closed source. But, I don't know why you think that
 function is called by the C runtime; see src/rt/dmain2.d.

Have a look again. It's only called on Posix: https://github.com/D-Programming-Language/druntime/blob/7d663821d39cfe8874cb95b0df46b5065a770cef/src/rt/dmain2.d#L364

I stand corrected. I had no idea about the magic involved here! The proprietary Windows tool chain is seriously problematic... -- Alex Rønne Petersen alex lycus.org http://lycus.org
May 20 2012
parent reply Denis Shelomovskij <verylonglogin.reg gmail.com> writes:
21.05.2012 2:13, Alex Rønne Petersen написал:
 On 20-05-2012 22:13, Jacob Carlborg wrote:
 On 2012-05-20 18:25, Alex Rønne Petersen wrote:

 Seems like I misunderstood what you were saying. Right, the C runtime on
 *Windows* is closed source. But, I don't know why you think that
 function is called by the C runtime; see src/rt/dmain2.d.

Have a look again. It's only called on Posix: https://github.com/D-Programming-Language/druntime/blob/7d663821d39cfe8874cb95b0df46b5065a770cef/src/rt/dmain2.d#L364

I stand corrected. I had no idea about the magic involved here! The proprietary Windows tool chain is seriously problematic...

So can anybody do something with it? At least document a bit what does proprietary part do. -- Денис В. Шеломовский Denis V. Shelomovskij
May 22 2012
next sibling parent Jacob Carlborg <doob me.com> writes:
On 2012-05-22 23:01, Steven Schveighoffer wrote:

 It looks like code that is not called on Windows. Which doesn't make
 sense. It would seem that you must initialize a critical section in
 order to use it.

 I can't find any reference to STI_monitor in dmd, dmc, or druntime
 source code, except those calls that are done for Posix only. This isn't
 some closed-source mystery, I think it is just unused code.

 Sean, does this make sense? Are we using uninitialized critical sections?

 -Steve

"_STI_critical_init" is defined both in critical.c and critical_.d, but I can't find a place where it's called on Windows. -- /Jacob Carlborg
May 22 2012
prev sibling parent reply Jacob Carlborg <doob me.com> writes:
On 2012-05-22 23:01, Steven Schveighoffer wrote:

 It looks like code that is not called on Windows. Which doesn't make
 sense. It would seem that you must initialize a critical section in
 order to use it.

 I can't find any reference to STI_monitor in dmd, dmc, or druntime
 source code, except those calls that are done for Posix only. This isn't
 some closed-source mystery, I think it is just unused code.

 Sean, does this make sense? Are we using uninitialized critical sections?

 -Steve

I found a call now, it's in "_d_criticalenter", both in critical.c and critical_.d. -- /Jacob Carlborg
May 22 2012
next sibling parent Jacob Carlborg <doob me.com> writes:
On 2012-05-23 13:31, Steven Schveighoffer wrote:
 On Wed, 23 May 2012 02:21:14 -0400, Jacob Carlborg <doob me.com> wrote:

 On 2012-05-22 23:01, Steven Schveighoffer wrote:

 It looks like code that is not called on Windows. Which doesn't make
 sense. It would seem that you must initialize a critical section in
 order to use it.

 I can't find any reference to STI_monitor in dmd, dmc, or druntime
 source code, except those calls that are done for Posix only. This isn't
 some closed-source mystery, I think it is just unused code.

 Sean, does this make sense? Are we using uninitialized critical
 sections?

 -Steve

I found a call now, it's in "_d_criticalenter", both in critical.c and critical_.d.

OK, so does this mean monitor is only used on Posix, and critical is used only on windows? This seems a little weird. Especially since we are still compiling monitor.c. -Steve

No, there's a "_d_criticalenter" for Posix in critical(_).d/c which calls "_STI_critical_init". It seems there's a duplicate call for "_STI_critical_init" on Posix, in dmain2.d and in critical(_).d/c. Also this actually looks like a big mess: * critical_.d and critical.c contains the same code. critical_.d is used in the posix makefile. critical.c _and_ critical_.d is used in the win32 makefile * "_STI_critical_init" is implemented on both Posix and Windows, but it's only called on Posix * "_STI_critical_init" is called on multiple places on Posix. In dmain2.d and in "_d_criticalenter". -- /Jacob Carlborg
May 23 2012
prev sibling parent reply Denis Shelomovskij <verylonglogin.reg gmail.com> writes:
23.05.2012 10:21, Jacob Carlborg написал:
 On 2012-05-22 23:01, Steven Schveighoffer wrote:

 It looks like code that is not called on Windows. Which doesn't make
 sense. It would seem that you must initialize a critical section in
 order to use it.

 I can't find any reference to STI_monitor in dmd, dmc, or druntime
 source code, except those calls that are done for Posix only. This isn't
 some closed-source mystery, I think it is just unused code.

 Sean, does this make sense? Are we using uninitialized critical sections?

 -Steve

I found a call now, it's in "_d_criticalenter", both in critical.c and critical_.d.

What call have you found in "_d_criticalenter"? By the way, `_STI_critical_init` is called before C main (uncomment printf's and check), so it is definitely called not by druntime. -- Денис В. Шеломовский Denis V. Shelomovskij
May 23 2012
parent reply Jacob Carlborg <doob me.com> writes:
On 2012-05-23 19:32, Denis Shelomovskij wrote:

 What call have you found in "_d_criticalenter"?

 By the way, `_STI_critical_init` is called before C main (uncomment
 printf's and check), so it is definitely called not by druntime.

"_STI_critical_init" is called here: * https://github.com/D-Programming-Language/druntime/blob/master/src/rt/critical_.d#L149 * https://github.com/D-Programming-Language/druntime/blob/master/src/rt/critical.c#L124 * https://github.com/D-Programming-Language/druntime/blob/master/src/rt/dmain2.d#L364 Found another one: * https://github.com/D-Programming-Language/druntime/blob/master/src/rt/dmain2.d#L255 I assume, and hope, that only one of these are actually called. That's why I said all this is a big mess. The last one is only called if the runtime is manually initialized, i.e. via C using the "rt_init" function. Which is stupid, "rt_init" should be called from the C main function as well. There's unnecessary code duplication here. -- /Jacob Carlborg
May 23 2012
next sibling parent Jacob Carlborg <doob me.com> writes:
On 2012-05-23 21:58, Steven Schveighoffer wrote:

 +1

 dmain2 has that "magic runtime" feel where you look at it and are so
 confused that you are afraid to touch anything :P

 -Steve

I previously made a pull request and tried to fix code duplication in dmain2.d. Unfortunately some test case failed, I'm going to look into it again. -- /Jacob Carlborg
May 23 2012
prev sibling parent Jacob Carlborg <doob me.com> writes:
On 2012-05-24 21:49, Sean Kelly wrote:

 There's a difference in how unittest execution is handled.  This could
probably be sorted out though.

Yeah, I've noticed that. Does the unit test really need to run when you call rt_init from C? -- /Jacob Carlborg
May 24 2012
prev sibling next sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Tue, 22 May 2012 15:16:30 -0400, Denis Shelomovskij  =

<verylonglogin.reg gmail.com> wrote:

 21.05.2012 2:13, Alex R=C3=B8nne Petersen =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=

 On 20-05-2012 22:13, Jacob Carlborg wrote:
 On 2012-05-20 18:25, Alex R=C3=B8nne Petersen wrote:

 Seems like I misunderstood what you were saying. Right, the C runti=




 on
 *Windows* is closed source. But, I don't know why you think that
 function is called by the C runtime; see src/rt/dmain2.d.

Have a look again. It's only called on Posix: https://github.com/D-Programming-Language/druntime/blob/7d663821d39c=




I stand corrected. I had no idea about the magic involved here! The proprietary Windows tool chain is seriously problematic...

So can anybody do something with it? At least document a bit what does=

 proprietary part do.

It looks like code that is not called on Windows. Which doesn't make = sense. It would seem that you must initialize a critical section in ord= er = to use it. I can't find any reference to STI_monitor in dmd, dmc, or druntime sourc= e = code, except those calls that are done for Posix only. This isn't some = = closed-source mystery, I think it is just unused code. Sean, does this make sense? Are we using uninitialized critical section= s? -Steve
May 22 2012
prev sibling next sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Wed, 23 May 2012 02:21:14 -0400, Jacob Carlborg <doob me.com> wrote:

 On 2012-05-22 23:01, Steven Schveighoffer wrote:

 It looks like code that is not called on Windows. Which doesn't make
 sense. It would seem that you must initialize a critical section in
 order to use it.

 I can't find any reference to STI_monitor in dmd, dmc, or druntime
 source code, except those calls that are done for Posix only. This isn't
 some closed-source mystery, I think it is just unused code.

 Sean, does this make sense? Are we using uninitialized critical  
 sections?

 -Steve

I found a call now, it's in "_d_criticalenter", both in critical.c and critical_.d.

OK, so does this mean monitor is only used on Posix, and critical is used only on windows? This seems a little weird. Especially since we are still compiling monitor.c. -Steve
May 23 2012
prev sibling next sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Wed, 23 May 2012 15:46:16 -0400, Jacob Carlborg <doob me.com> wrote:

 On 2012-05-23 19:32, Denis Shelomovskij wrote:

 What call have you found in "_d_criticalenter"?

 By the way, `_STI_critical_init` is called before C main (uncomment
 printf's and check), so it is definitely called not by druntime.

"_STI_critical_init" is called here: * https://github.com/D-Programming-Language/druntime/blob/master/src/rt/critical_.d#L149 * https://github.com/D-Programming-Language/druntime/blob/master/src/rt/critical.c#L124 * https://github.com/D-Programming-Language/druntime/blob/master/src/rt/dmain2.d#L364 Found another one: * https://github.com/D-Programming-Language/druntime/blob/master/src/rt/dmain2.d#L255 I assume, and hope, that only one of these are actually called. That's why I said all this is a big mess. The last one is only called if the runtime is manually initialized, i.e. via C using the "rt_init" function. Which is stupid, "rt_init" should be called from the C main function as well. There's unnecessary code duplication here.

+1 dmain2 has that "magic runtime" feel where you look at it and are so confused that you are afraid to touch anything :P -Steve
May 23 2012
prev sibling next sibling parent Sean Kelly <sean invisibleduck.org> writes:
On May 23, 2012, at 7:49 AM, Jacob Carlborg wrote:

 On 2012-05-23 13:31, Steven Schveighoffer wrote:
 On Wed, 23 May 2012 02:21:14 -0400, Jacob Carlborg <doob me.com> =


=20
 On 2012-05-22 23:01, Steven Schveighoffer wrote:
=20
 It looks like code that is not called on Windows. Which doesn't =




 sense. It would seem that you must initialize a critical section in
 order to use it.
=20
 I can't find any reference to STI_monitor in dmd, dmc, or druntime
 source code, except those calls that are done for Posix only. This =




 some closed-source mystery, I think it is just unused code.
=20
 Sean, does this make sense? Are we using uninitialized critical
 sections?
=20
 -Steve

I found a call now, it's in "_d_criticalenter", both in critical.c =



 critical_.d.
=20

OK, so does this mean monitor is only used on Posix, and critical is used only on windows? This seems a little weird. Especially since we =


 still compiling monitor.c.
=20
 -Steve

No, there's a "_d_criticalenter" for Posix in critical(_).d/c which =

"_STI_critical_init" on Posix, in dmain2.d and in critical(_).d/c.
=20
 Also this actually looks like a big mess:
=20
 * critical_.d and critical.c contains the same code. critical_.d is =

win32 makefile
=20
 * "_STI_critical_init" is implemented on both Posix and Windows, but =

=20
 * "_STI_critical_init" is called on multiple places on Posix. In =

If I remember correctly, Brad Roberts tried porting the old C critical = section code to D a while back and something didn't work right. Both = versions of the code still exist, and at some point the D code needs to = be sorted and the C code should be thrown away. I suppose I should make = this my top priority, when I find the time.=
May 24 2012
prev sibling next sibling parent Sean Kelly <sean invisibleduck.org> writes:
On May 22, 2012, at 2:01 PM, Steven Schveighoffer wrote:

 On Tue, 22 May 2012 15:16:30 -0400, Denis Shelomovskij =

=20
 21.05.2012 2:13, Alex R=C3=B8nne Petersen =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=


 On 20-05-2012 22:13, Jacob Carlborg wrote:
 On 2012-05-20 18:25, Alex R=C3=B8nne Petersen wrote:
=20
 Seems like I misunderstood what you were saying. Right, the C =





 *Windows* is closed source. But, I don't know why you think that
 function is called by the C runtime; see src/rt/dmain2.d.

Have a look again. It's only called on Posix: =20 =




cb95b0df46b5065a770cef/src/rt/dmain2.d#L364
=20
=20
=20

I stand corrected. I had no idea about the magic involved here! =20 The proprietary Windows tool chain is seriously problematic... =20

So can anybody do something with it? At least document a bit what =


=20

It looks like code that is not called on Windows. Which doesn't make =

order to use it.
=20
 I can't find any reference to STI_monitor in dmd, dmc, or druntime =

isn't some closed-source mystery, I think it is just unused code.
=20
 Sean, does this make sense?  Are we using uninitialized critical =

This code is before my time, but I believe that DMC implicitly treats = STI functions as module ctors, and DMD inherits this behavior because it = shares a C runtime with DMC. It's been a while since I've looked at all = of this, but the full C runtime source is shipped with DMC--I have a = copy.=
May 24 2012
prev sibling next sibling parent Sean Kelly <sean invisibleduck.org> writes:
On May 23, 2012, at 12:46 PM, Jacob Carlborg wrote:

 On 2012-05-23 19:32, Denis Shelomovskij wrote:
=20
 What call have you found in "_d_criticalenter"?
=20
 By the way, `_STI_critical_init` is called before C main (uncomment
 printf's and check), so it is definitely called not by druntime.
=20

"_STI_critical_init" is called here: =20 * =

ical_.d#L149
=20
 * =

ical.c#L124
=20
 * =

n2.d#L364
=20
 Found another one:
=20
 * =

n2.d#L255
=20
 I assume, and hope, that only one of these are actually called. That's =

=20
 The last one is only called if the runtime is manually initialized, =

should be called from the C main function as well. There's unnecessary = code duplication here. There's a difference in how unittest execution is handled. This could = probably be sorted out though.=
May 24 2012
prev sibling next sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Thu, 24 May 2012 15:44:28 -0400, Sean Kelly <sean invisibleduck.org> =
 =

wrote:

 On May 22, 2012, at 2:01 PM, Steven Schveighoffer wrote:

 On Tue, 22 May 2012 15:16:30 -0400, Denis Shelomovskij  =


 <verylonglogin.reg gmail.com> wrote:

 21.05.2012 2:13, Alex R=C3=B8nne Petersen =D0=BD=D0=B0=D0=BF=D0=B8=D1=



 On 20-05-2012 22:13, Jacob Carlborg wrote:
 On 2012-05-20 18:25, Alex R=C3=B8nne Petersen wrote:

 Seems like I misunderstood what you were saying. Right, the C  =






 runtime on
 *Windows* is closed source. But, I don't know why you think that
 function is called by the C runtime; see src/rt/dmain2.d.

Have a look again. It's only called on Posix: https://github.com/D-Programming-Language/druntime/blob/7d663821d3=






I stand corrected. I had no idea about the magic involved here! The proprietary Windows tool chain is seriously problematic...

So can anybody do something with it? At least document a bit what do=



 proprietary part do.

It looks like code that is not called on Windows. Which doesn't make=


 sense.  It would seem that you must initialize a critical section in =


 order to use it.

 I can't find any reference to STI_monitor in dmd, dmc, or druntime  =


 source code, except those calls that are done for Posix only.  This  =


 isn't some closed-source mystery, I think it is just unused code.

 Sean, does this make sense?  Are we using uninitialized critical  =


 sections?

This code is before my time, but I believe that DMC implicitly treats =

 STI functions as module ctors, and DMD inherits this behavior because =

 shares a C runtime with DMC.  It's been a while since I've looked at a=

 of this, but the full C runtime source is shipped with DMC--I have a  =

 copy.

Yeah, I do too. I did a full text search for STI_monitor and found = nothing. That's why I'm confused... -Steve
May 24 2012
prev sibling next sibling parent Sean Kelly <sean invisibleduck.org> writes:
On May 24, 2012, at 1:27 PM, "Steven Schveighoffer" <schveiguy yahoo.com> wr=
ote:

 On Thu, 24 May 2012 15:44:28 -0400, Sean Kelly <sean invisibleduck.org> wr=

=20
 On May 22, 2012, at 2:01 PM, Steven Schveighoffer wrote:
=20
 On Tue, 22 May 2012 15:16:30 -0400, Denis Shelomovskij <verylonglogin.re=



=20
 21.05.2012 2:13, Alex R=C3=B8nne Petersen =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=




 On 20-05-2012 22:13, Jacob Carlborg wrote:
 On 2012-05-20 18:25, Alex R=C3=B8nne Petersen wrote:
=20
 Seems like I misunderstood what you were saying. Right, the C runtim=







 *Windows* is closed source. But, I don't know why you think that
 function is called by the C runtime; see src/rt/dmain2.d.

Have a look again. It's only called on Posix: =20 https://github.com/D-Programming-Language/druntime/blob/7d663821d39cf=






=20
=20
=20

I stand corrected. I had no idea about the magic involved here! =20 The proprietary Windows tool chain is seriously problematic... =20

So can anybody do something with it? At least document a bit what does p=




=20

It looks like code that is not called on Windows. Which doesn't make se=



se it.
=20
 I can't find any reference to STI_monitor in dmd, dmc, or druntime sourc=



osed-source mystery, I think it is just unused code.
=20
 Sean, does this make sense?  Are we using uninitialized critical section=



=20
 This code is before my time, but I believe that DMC implicitly treats STI=


a C runtime with DMC. It's been a while since I've looked at all of this, b= ut the full C runtime source is shipped with DMC--I have a copy.
=20
 Yeah, I do too.  I did a full text search for STI_monitor and found nothin=

=20
 That's why I'm confused...

It's not STI_monitor specifically. STI_anything is a module ctor and STD_any= thing is a module dtor. Or at least that's my recollection. There are a few p= laces in the DMC runtime that have initializers like this. I think one is so= mewhere in the floating-point support code.=20=
May 24 2012
prev sibling next sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Thu, 24 May 2012 16:40:46 -0400, Sean Kelly <sean invisibleduck.org>  
wrote:

 It's not STI_monitor specifically. STI_anything is a module ctor and  
 STD_anything is a module dtor. Or at least that's my recollection. There  
 are a few places in the DMC runtime that have initializers like this. I  
 think one is somewhere in the floating-point support code.

oh. That's.... horrible. Yeah, we should eliminate this ASAP. Is there any reason it has to be done before C's main? -Steve
May 25 2012
prev sibling next sibling parent Sean Kelly <sean invisibleduck.org> writes:
On May 25, 2012, at 7:31 AM, "Steven Schveighoffer" <schveiguy yahoo.com> wr=
ote:

 On Thu, 24 May 2012 16:40:46 -0400, Sean Kelly <sean invisibleduck.org> wr=

=20
 It's not STI_monitor specifically. STI_anything is a module ctor and STD_=


ew places in the DMC runtime that have initializers like this. I think one i= s somewhere in the floating-point support code.
=20
 oh.  That's.... horrible.
=20
 Yeah, we should eliminate this ASAP.  Is there any reason it has to be don=

None that I can think of. I bet it's just really old code.=20=
May 25 2012
prev sibling parent Sean Kelly <sean invisibleduck.org> writes:
On May 24, 2012, at 11:25 PM, Jacob Carlborg <doob me.com> wrote:

 On 2012-05-24 21:49, Sean Kelly wrote:
=20
 There's a difference in how unittest execution is handled.  This could pr=


=20
 Yeah, I've noticed that. Does the unit test really need to run when you ca=

Not really. I wanted initialization to be the same either way, but unittests= seem optional.=20=
May 25 2012