Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Tango as a dylib - unexpected output

Moderators: kris

Posted: 05/15/09 12:05:19

I tried building tango (the user lib not the runtime) as a dynamic library on Mac OS X 10.5. The size of the resulting lib was 3.6 MB compared to a static lib that was 6.3 MB. I tried building a "Hello World" app and the resulting executable was 16 KB (just as a C "Hello World") compared to 308 KB when linking to a static tango.

OK, now to the unexpected output. When I run the executable the output was:

3 Trace cluster.generic - creating bulletin consumer for 'cluster.server.advertise'
3 Trace cluster.generic - discovering cluster nodes
Hello D dynamic World

What are the cluster things doing there? I only expected "Hello D dynamic World".

D application:

module main;

import tango.io.Stdout;

void main ()
{
    Stdout("Hello D dynamic World").newline;
}
Author Message

Posted: 05/15/09 15:39:11

That does indeed sound very weird.

I tried to see how this could happen, but I'm pretty sure the only possibility is if some of the cluster tests (look for void main inside version/debug blocks) happen to also be executed.

Posted: 05/15/09 17:03:32

That happens to me with the unittests, it seems that the static constructors of one of

./tina/ClusterTask.d ./NetworkRegistry.d ./NetworkClient.d

are executed for some reason... not sure how to avoid it.

Posted: 05/15/09 18:04:43

Forgot to mention, this is with gdc and tango 0.99.8

Posted: 05/15/09 18:34:03

There are some logging going on in tango.net.cluster.tina.Cluster at line 472, 488 and 128 which match the output. I found five "main" functions in tango.net.cluster:

  • tango.net.cluster.QueuedCache:380
  • tango.net.cluster.tina.CacheServer:79
  • tango.net.cluster.tina.QueueFile:346
  • tango.net.cluster.tina.QueueServer:81
  • tango.net.cluster.tina.TaskServer:73.

Let me know if I should file a ticket.

I'm also not sure that I correctly built the dynamic library. I modified the build script to copy every object file to a directory and than compiled with gcc like this:

gcc -dynamiclib -o libgtango.dylib ./objs/*.o libgphobos.a -lz -lbz2

Posted: 05/16/09 08:33:26

The logging itself is ok, and so are the main functions afaics. Fawzi's comment suggests that this is a compiler or linker issue on OSX. This output is not present when running the unittests on linux for instance.

Posted: 05/16/09 09:10:07

fawzi wrote:

That happens to me with the unittests, it seems that the static constructors of one of

./tina/ClusterTask.d ./NetworkRegistry.d ./NetworkClient.d

are executed for some reason... not sure how to avoid it.

Seems like it's the static constructor in ./tina/ClusterTask.d. It calls .tina.Cluster.join which contains

logger.trace ("discovering cluster nodes");

Posted: 05/16/09 09:35:58

Yes, but why would a non-cluster using application make that static constructor run? An explicit import should normally be necessary.

Posted: 05/16/09 17:47:19

larsivi wrote:

Yes, but why would a non-cluster using application make that static constructor run? An explicit import should normally be necessary.

Ok, here's my guess: it runs all the static constructors. I added a Stdout in the static ctor in tango.core.Cpuid, recompiled tango and the application, it printed the string from the static ctor in Cpuid also. I guess that the static ctor in the cluster package was the only one the printed something.

Posted: 05/16/09 19:46:13

Wasn't there a recent 'enhancement' to DMD where it now executes static-ctors in a library, or something related?

Posted: 05/17/09 17:40:55

I don't know. I'm using gdc and it's nothing recent about gdc.